-
Type: Task
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Fully Compatible
One of the Mongoid query cache tests broke when the cursor implementation was changed to allow iterating the cursor one time only. We need to restore the old behavior where the cursor could be iterated more than once.
The old behavior was buggy when a getMore was issued, because the following would happen:
1. The driver would return documents from the initial result.
2. The driver would issue another getMore to advance the cursor forward and return those documents.
Any documents in the batches that had been iterated via prior getMore calls would be lost on subsequent restarted iterations.
The change in this ticket is to reinstate repeated iteration as long as only the first batch is iterated. Trying to restart iteration after a get_more was invoked on a cursor object would now raise a NotImplementedError.
In a future version of the driver we may restore the "early 2.10" behavior of always iterating forward from cursor position. The alternative is to support always restarting iteration from the beginning, but this requires issuing initial query again which is more complicated and perhaps outside the scope of the cursor.
To further clarify, the case in question is as follows:
cursor = ... cursor.each do |doc| # retrieve one document and stop break end cursor.to_a
In pre-2.10 drivers, to_a would return the document already retrieved by #each. In "early 2.10" drivers, to_a would skip that document. After this ticket is done, the final 2.10 driver would return these documents again.
The second case:
cursor = ... # batch size = 2 cursor.each do |doc| # retrieve three documents and stop if ... break end end cursor.to_a
In pre-2.10 drivers, this would drop the second batch of results (documents #3 and #4). In 2.10 final, this would raise NotImplementedError.
- is caused by
-
RUBY-1708 Support postBatchResumeToken in change streams
- Closed
- is related to
-
MONGOID-4756 Query cache tests do not test that QC is used
- Closed
- related to
-
RUBY-1849 Implement caching cursor in driver
- Closed
- links to