[SERVER-12082] count() on a sharded cluster includes orphan documents Created: 13/Dec/13  Updated: 13/Dec/13  Resolved: 13/Dec/13

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 2.4.6
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Henrik Ingo (Inactive) Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu 12.04


Issue Links:
Duplicate
duplicates SERVER-3645 Sharded collection counts (on primary... Closed
Operating System: ALL
Participants:

 Description   

mongos> sh.status()
--- Sharding Status --- 
  sharding version: {
	"_id" : 1,
	"version" : 3,
	"minCompatibleVersion" : 3,
	"currentVersion" : 4,
	"clusterId" : ObjectId("52aaf42ca34a2646b68b9333")
}
  shards:
	{  "_id" : "shard0000",  "host" : "localhost:27001" }
	{  "_id" : "shard0001",  "host" : "localhost:27002" }
	{  "_id" : "shard0002",  "host" : "localhost:27003" }
  databases:
	{  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
	{  "_id" : "test",  "partitioned" : true,  "primary" : "shard0000" }
		test.somecollection
			shard key: { "_id" : 1 }
			chunks:
				shard0001	1
				shard0002	1
				shard0000	1
			{ "_id" : { "$minKey" : 1 } } -->> { "_id" : 3 } on : shard0001 Timestamp(2, 0) 
			{ "_id" : 3 } -->> { "_id" : 6 } on : shard0002 Timestamp(3, 0) 
			{ "_id" : 6 } -->> { "_id" : { "$maxKey" : 1 } } on : shard0000 Timestamp(3, 1) 
 
mongos> db.somecollection.find()
{ "_id" : 1, "data" : "one" }
{ "_id" : 3, "data" : "three" }
{ "_id" : 6, "data" : "six" }
{ "_id" : 2, "data" : "two" }
{ "_id" : 4, "data" : "four" }
{ "_id" : 7, "data" : "seven" }
{ "_id" : 5, "data" : "five" }
{ "_id" : 8, "data" : "eight" }
{ "_id" : 9, "data" : "nine" }
{ "_id" : 10, "data" : "ten" }
mongos> db.somecollection.find().count()
10
 
// Connect directly to a shard and insert a document that shouldn't be on that shard (an orphan document)
$ mongo --port 27001
MongoDB shell version: 2.4.8
connecting to: 127.0.0.1:27001/test
> db.somecollection.find()
{ "_id" : 6, "data" : "six" }
{ "_id" : 7, "data" : "seven" }
{ "_id" : 8, "data" : "eight" }
{ "_id" : 9, "data" : "nine" }
{ "_id" : 10, "data" : "ten" }
> db.somecollection.insert( { _id : 1, data : "one (orphan document)" } )
> db.somecollection.find()
{ "_id" : 6, "data" : "six" }
{ "_id" : 7, "data" : "seven" }
{ "_id" : 8, "data" : "eight" }
{ "_id" : 9, "data" : "nine" }
{ "_id" : 10, "data" : "ten" }
{ "_id" : 1, "data" : "one (orphan document)" }
 
// Back on mongos, the orphan document is not visible. This is correct.
mongos> db.somecollection.find()
{ "_id" : 1, "data" : "one" }
{ "_id" : 3, "data" : "three" }
{ "_id" : 6, "data" : "six" }
{ "_id" : 2, "data" : "two" }
{ "_id" : 4, "data" : "four" }
{ "_id" : 7, "data" : "seven" }
{ "_id" : 5, "data" : "five" }
{ "_id" : 8, "data" : "eight" }
{ "_id" : 9, "data" : "nine" }
{ "_id" : 10, "data" : "ten" }
 
// But count() includes it. This is wrong.
mongos> db.somecollection.find().count()
11
 



 Comments   
Comment by Scott Hernandez (Inactive) [ 13/Dec/13 ]

dup of SERVER-3645

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