[SERVER-9738] mongos should set the CursorNotFound bit when the cursor is not found Created: 21/May/13  Updated: 11/Jul/16  Resolved: 08/Jul/13

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: None
Fix Version/s: 2.4.7, 2.5.1

Type: Bug Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Randolph Tan
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Operating System: ALL
Participants:

 Description   
MongoDB Status as of October 9th, 2013

ISSUE SUMMARY
mongos does not set the CursorNotFound bit in the response when the cursor is not found for unsharded collections. Instead it sets the QueryFailure bit. See the response definition here.

USER IMPACT
The wrong message will be returned to the user through their client driver. It is present in versions of MongoDB prior to and including v2.4.6.

SOLUTION
The issue has been solved by bringing the behavior of mongos into accordance with mongod and mongos with sharded collections.

WORKAROUNDS
None

PATCHES
Production release v2.4.7 contains the fix for this issue, and production release v2.6.0 will contain the fix as well.

Original Description

Instead, it sets the QueryFailure bit.

See http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/#op-reply.

Drivers typically have different exception types for these two bits, so end up throwing a different exception when running against a shard cluster.



 Comments   
Comment by auto [ 02/Oct/13 ]

Author:

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

Message: SERVER-9738 mongos should set the CursorNotFound bit when the cursor is not found

Lower invalid cursor log level from 6 to 3.
Branch: v2.4
https://github.com/mongodb/mongo/commit/3803f6424a32433401b55126bbe7cad76c56d723

Comment by auto [ 02/Oct/13 ]

Author:

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

Message: SERVER-9738 mongos should set the CursorNotFound bit when the cursor is not found
Branch: v2.4
https://github.com/mongodb/mongo/commit/80adf5e6901e016ff2df21f85b3efa93b701b3b9

Comment by Randolph Tan [ 08/Jul/13 ]

Note to drivers:

Mongos now doesn't reply with a BSON document with the $err field if cursor is not found for unsharded collections. It is now consistent with the behavior with sharded collections and stand alone mongod - the cursor not found flag is set with no document in the response.

Comment by auto [ 08/Jul/13 ]

Author:

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

Message: SERVER-9738 mongos should set the CursorNotFound bit when the cursor is not found

Lower invalid cursor log level from 6 to 3.
Branch: master
https://github.com/mongodb/mongo/commit/82f2196f64e9883e4e35ac9f07a4e1ecd195b682

Comment by auto [ 08/Jul/13 ]

Author:

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

Message: SERVER-9738 mongos should set the CursorNotFound bit when the cursor is not found
Branch: master
https://github.com/mongodb/mongo/commit/8cf1cd27240ef6e7127b7f86eca22da298b213ee

Comment by Randolph Tan [ 27/Jun/13 ]

The docs for CursorNotFound says:

Set when getMore is called but the cursor id is not valid at the server. Returned with zero results.

So I think the mongod works as designed (no $err document).

Comment by Derick Rethans [ 22/May/13 ]

I'm actually seeing another difference between talking to MongoS and MongoD. With MongoD, if we try to read from a killed/closed cursor, I am seeing this:

127.0.0.1:40927  -->> 127.0.0.1:30000 test.php755  44 bytes  id:d5	213
	getMore nToReturn: 0 cursorId: 28495533495443627
127.0.0.1:30000  <<--  127.0.0.1:40927   36 bytes  id:36bf	14015 - 213
	reply n:0 cursorId: 0

With MongoS, I see:

127.0.0.1:40696  -->> 127.0.0.1:30999 test.php755  44 bytes  id:d5	213
	getMore nToReturn: 0 cursorId: 28494939114340187
127.0.1.1:30999  <<--  127.0.1.1:40696   145 bytes  id:a002	40962 - 213
	reply n:1 cursorId: 0
	{ $err: "could not find cursor in cache for id 28494939114340187 over collection test.php755", code: 16336 }

mongosniff however doesn't show the flags, but from checking in the code:

  • MongoS sets "QueryFailure" (bad) and adds an $err document (good)
  • MongoD sets "CursorNotFound" (good) but doesn't add an $err document (bad)

It'd be helpful of MongoD also added the $err document just like MongoS now does (but with the wrong flag).

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