[SERVER-16110] MongoS doesn't update the shard description in the explain() output Created: 12/Nov/14  Updated: 27/Jun/19  Resolved: 27/Jun/19

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 2.4.9, 2.6.5
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Alexander Komyagin Assignee: Kaloian Manassiev
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Sprint: Sharding 2019-07-01
Participants:

 Description   

After removing one RS member in a shard, MongoS updates config.shards but keeps the stale shard string in the explain() output.

Create a new sharded collection with a single record:

mongos> sh.enableSharding("beep")
{ "ok" : 1 }
mongos> sh.shardCollection("beep.beeps",{_id:1})
{ "collectionsharded" : "beep.beeps", "ok" : 1 }
mongos> use beep
switched to db beep
mongos> db.beeps.insert({x:1})
WriteResult({ "nInserted" : 1 })
mongos> db.beeps.find()
{ "_id" : ObjectId("5463ac6986131a1d5750adcd"), "x" : 1 }
mongos> db.beeps.find({ "_id" : ObjectId("5463ac6986131a1d5750adcd")}).explain()
{
	"clusteredType" : "ParallelSort",
	"shards" : {
		"db_0/AlexMMSADemo-0.mralex.9768.mongodbdns.com:27000,AlexMMSADemo-1.mralex.9768.mongodbdns.com:27000,AlexMMSADemo-2.mralex.9768.mongodbdns.com:27000" : [
			{
				"cursor" : "IDCursor",
				"n" : 1,
				"nscannedObjects" : 1,
				"nscanned" : 1,
				"indexOnly" : false,
				"millis" : 0,
				"indexBounds" : {
					"_id" : [
						[
							ObjectId("5463ac6986131a1d5750adcd"),
							ObjectId("5463ac6986131a1d5750adcd")
						]
					]
				},
				"server" : "AlexMMSADemo-0.mralex.9768:27000"
			}
		]
	},
	"cursor" : "IDCursor",
	"n" : 1,
	"nscanned" : 1,
	"nscannedObjects" : 1,
	"millisShardTotal" : 0,
	"millisShardAvg" : 0,
	"numQueries" : 1,
	"numShards" : 1,
	"indexBounds" : {
		"_id" : [
			[
				ObjectId("5463ac6986131a1d5750adcd"),
				ObjectId("5463ac6986131a1d5750adcd")
			]
		]
	},
	"millis" : 0
}
mongos> sh.status()
--- Sharding Status ---
  sharding version: {
	"_id" : 1,
	"version" : 4,
	"minCompatibleVersion" : 4,
	"currentVersion" : 5,
	"clusterId" : ObjectId("5463abcdd77c8abb282138a4")
}
  shards:
	{  "_id" : "db_0",  "host" : "db_0/AlexMMSADemo-0.mralex.9768.mongodbdns.com:27000,AlexMMSADemo-1.mralex.9768.mongodbdns.com:27000,AlexMMSADemo-2.mralex.9768.mongodbdns.com:27000" }
	{  "_id" : "db_1",  "host" : "db_1/AlexMMSADemo-0.mralex.9768.mongodbdns.com:27001,AlexMMSADemo-0.mralex.9768.mongodbdns.com:27002,AlexMMSADemo-1.mralex.9768.mongodbdns.com:27001" }
  databases:
	{  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
	{  "_id" : "beep",  "partitioned" : true,  "primary" : "db_0" }
		beep.beeps
			shard key: { "_id" : 1 }
			chunks:
				db_0	1
			{ "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : db_0 Timestamp(1, 0)

Remove one replica set node and see that the shard description in the explain() output still has the old node in it:

mongos> sh.status()
--- Sharding Status ---
  sharding version: {
	"_id" : 1,
	"version" : 4,
	"minCompatibleVersion" : 4,
	"currentVersion" : 5,
	"clusterId" : ObjectId("5463abcdd77c8abb282138a4")
}
  shards:
	{  "_id" : "db_0",  "host" : "db_0/AlexMMSADemo-0.mralex.9768.mongodbdns.com:27000,AlexMMSADemo-1.mralex.9768.mongodbdns.com:27000" }
	{  "_id" : "db_1",  "host" : "db_1/AlexMMSADemo-0.mralex.9768.mongodbdns.com:27001,AlexMMSADemo-0.mralex.9768.mongodbdns.com:27002,AlexMMSADemo-1.mralex.9768.mongodbdns.com:27001" }
  databases:
	{  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
	{  "_id" : "beep",  "partitioned" : true,  "primary" : "db_0" }
		beep.beeps
			shard key: { "_id" : 1 }
			chunks:
				db_0	1
			{ "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : db_0 Timestamp(1, 0)
 
mongos> db.beeps.find({ "_id" : ObjectId("5463ac6986131a1d5750adcd")}).explain()
{
	"clusteredType" : "ParallelSort",
	"shards" : {
		"db_0/AlexMMSADemo-0.mralex.9768.mongodbdns.com:27000,AlexMMSADemo-1.mralex.9768.mongodbdns.com:27000,AlexMMSADemo-2.mralex.9768.mongodbdns.com:27000" : [
			{
				"cursor" : "IDCursor",
				"n" : 1,
				"nscannedObjects" : 1,
				"nscanned" : 1,
				"indexOnly" : false,
				"millis" : 0,
				"indexBounds" : {
					"_id" : [
						[
							ObjectId("5463ac6986131a1d5750adcd"),
							ObjectId("5463ac6986131a1d5750adcd")
						]
					]
				},
				"server" : "AlexMMSADemo-0.mralex.9768:27000"
			}
		]
	},
	"cursor" : "IDCursor",
	"n" : 1,
	"nscanned" : 1,
	"nscannedObjects" : 1,
	"millisShardTotal" : 0,
	"millisShardAvg" : 0,
	"numQueries" : 1,
	"numShards" : 1,
	"indexBounds" : {
		"_id" : [
			[
				ObjectId("5463ac6986131a1d5750adcd"),
				ObjectId("5463ac6986131a1d5750adcd")
			]
		]
	},
	"millis" : 0
}

Wait some time to be sure:

mongos> new Date()
ISODate("2014-11-12T18:57:44.499Z")
mongos> new Date()
ISODate("2014-11-12T18:59:23.038Z")
mongos> db.beeps.find({ "_id" : ObjectId("5463ac6986131a1d5750adcd")}).explain()
{
	"clusteredType" : "ParallelSort",
	"shards" : {
		"db_0/AlexMMSADemo-0.mralex.9768.mongodbdns.com:27000,AlexMMSADemo-1.mralex.9768.mongodbdns.com:27000,AlexMMSADemo-2.mralex.9768.mongodbdns.com:27000" : [
			{
				"cursor" : "IDCursor",
				"n" : 1,
				"nscannedObjects" : 1,
				"nscanned" : 1,
				"indexOnly" : false,
				"millis" : 0,
				"indexBounds" : {
					"_id" : [
						[
							ObjectId("5463ac6986131a1d5750adcd"),
							ObjectId("5463ac6986131a1d5750adcd")
						]
					]
				},
				"server" : "AlexMMSADemo-0.mralex.9768:27000"
			}
		]
	},
	"cursor" : "IDCursor",
	"n" : 1,
	"nscanned" : 1,
	"nscannedObjects" : 1,
	"millisShardTotal" : 0,
	"millisShardAvg" : 0,
	"numQueries" : 1,
	"numShards" : 1,
	"indexBounds" : {
		"_id" : [
			[
				ObjectId("5463ac6986131a1d5750adcd"),
				ObjectId("5463ac6986131a1d5750adcd")
			]
		]
	},
	"millis" : 0
}
mongos>



 Comments   
Comment by Kaloian Manassiev [ 27/Jun/19 ]

This is not reproducible in 4.2.0-rc0 and was probably fixed starting in 3.4 with the various caching improvements, which were done in that release.

Comment by Greg Studer [ 12/Nov/14 ]

Pretty sure this is a side-effect of the ChunkManager caching copies of Shard information rather than just shard names - flushRouterConfig should be a workaround.

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