[JAVA-1255] Add DBCursor.tryNext() method for tailable cursors Created: 22/May/14  Updated: 25/Aug/17  Resolved: 15/Sep/14

Status: Closed
Project: Java Driver
Component/s: Query Operations
Affects Version/s: 2.12.0
Fix Version/s: 2.13.0, 3.0.0

Type: New Feature Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Ross Lawley
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to JAVA-1326 Introduce API for tailable cursors th... Closed
is related to JAVA-1091 Always set awaitData along with taila... Closed

 Description   

In 2.12, the Java driver started setting the AwaitData cursor flag any time the Tailable flag was set. As part of this change, the driver stopped violating the Iterator contractor for cursors. Whereas in previous versions of the driver, an Iterator for a cursor with Tailable but not AwaitData could return false from Iterator.hasNext(), and then some time later return true. In 2.12, by contrast, Iterator.hasNext() for a Tailable cursor blocks until there is a result available or until the cursor has been closed.

But this change breaks existing clients that were relying on the driver's breaking of the Iterator contract, so the change should be reverted. The driver should allow Tailable without AwaitData, and Iterator.hasNext() for such a cursor will return false but not close the cursor, allowing hasNext() to be called again at a later time.

Long term, the driver should offer a different API for tailable cursors (perhaps one without a hasNext() method), but this is a short term measure until we get there.

UPDATE::

DBCursor now has a tryNext method which may return null if no documents are available, and then return a document on a subsequent call.



 Comments   
Comment by Githook User [ 30/Jan/15 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Fix DBCursor#tryNext support for curr() and numSeen()

Missed in JAVA-1255
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/6eecaad216b1c32e09b5ccc2d875c0378dc75e76

Comment by Githook User [ 30/Jan/15 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Ensure next() and hasNext() behaviour doesn't change

JAVA-1255
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/e5fedfd8c18267c49ffc868c18604fe1e6812bad

Comment by Githook User [ 30/Jan/15 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Added tryNext() for tailable cursors

JAVA-1255
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/8347cf51d87c8a43945bb596ad9fadb07dc795fa

Comment by Jeffrey Yemin [ 29/Jan/15 ]

2.13.0 has been released. Closing issue.

Comment by Githook User [ 07/Oct/14 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Fix DBCursor#tryNext support for curr() and numSeen()

Missed in JAVA-1255
Branch: 3.0.x
https://github.com/mongodb/mongo-java-driver/commit/6eecaad216b1c32e09b5ccc2d875c0378dc75e76

Comment by Githook User [ 08/Sep/14 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Ensure next() and hasNext() behaviour doesn't change

JAVA-1255
Branch: 3.0.x
https://github.com/mongodb/mongo-java-driver/commit/e5fedfd8c18267c49ffc868c18604fe1e6812bad

Comment by Githook User [ 05/Sep/14 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Ensure next() and hasNext() behaviour doesn't change

JAVA-1255
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/a11aec7cfff3af5a22afa7ebbb9943d50165198d

Comment by Githook User [ 05/Sep/14 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Added tryNext() for tailable cursors

JAVA-1255
Branch: 3.0.x
https://github.com/mongodb/mongo-java-driver/commit/8347cf51d87c8a43945bb596ad9fadb07dc795fa

Comment by Githook User [ 05/Sep/14 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Added tryNext() for tailable cursors

JAVA-1255
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/019af845fca4823fbd3d70905bc97b31070a7ee3

Generated at Thu Feb 08 08:54:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.