[SERVER-5844] mongos cursors return the wrong value for startingFrom Created: 15/May/12  Updated: 11/Jul/16  Resolved: 24/May/12

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 2.1.1
Fix Version/s: 2.1.2

Type: Bug Priority: Major - P3
Reporter: Bernie Hackett Assignee: Randolph Tan
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-6236 Provide getter methods for extracting... Closed
is depended on by PYTHON-354 Traceback on query on sharded replica... Closed
Operating System: ALL
Participants:

 Description   

Note: This bug is a regression from 2.0.x behavior in mongos. There are no issues with mongod.

mongos returns the wrong value in the startingFrom field of OP_REPLY. The problem appears to be that mongos sets startingFrom to the same value as numberReturned. This causes PyMongo to assert expecting startingFrom to be 0 on the initial batch:

>>> cur = c.test.test.find()
>>> cur.next()
startingFrom: 100
numberReturned: 100
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pymongo/cursor.py", line 747, in next
    if len(self.__data) or self._refresh():
  File "pymongo/cursor.py", line 698, in _refresh
    self.__uuid_subtype))
  File "pymongo/cursor.py", line 668, in __send_message
    assert response["starting_from"] == self.__retrieved

The output should look like this (and does with mongod in 2.1.1):

>>> cur = c.test.test.find()
>>> cur.next()
startingFrom: 0
numberReturned: 101
{u'i': 0.0, u'_id': ObjectId('4fb1a26cb59381ba9dc941c8')}

The problem appears to be in src/mongo/s/cursors.cpp. At line 136 in ShardedClientCursor::sendNextBatch we have:

_totalSent += docCount;

Then in the calling method ShardedClientCursor::sendNextBatchAndReply we have:

replyToQuery( 0, r.p(), r.m(), buffer.buf(), buffer.len(), docCount,
       _totalSent, hasMore ? getId() : 0 );

At that point docCount and _totalSent are the same.



 Comments   
Comment by auto [ 24/May/12 ]

Author:

{u'login': u'', u'name': u'Randolph Tan', u'email': u'randolph@10gen.com'}

Message: SERVER-5844 mongos cursors return the wrong value for startingFrom
Branch: master
https://github.com/mongodb/mongo/commit/b45a2ff6e0b1d91da406c52a328d9d9aea08be6b

Comment by Kevin J. Rice [ 17/May/12 ]

Encountered same problem. Wondering when fix will be in.

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