[SERVER-8059] After movePrimary, db.getCollectionNames() excludes previously existing one-chunk collections Created: 02/Jan/13  Updated: 31/Oct/19  Resolved: 31/Oct/19

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

Type: Bug Priority: Major - P3
Reporter: Stephen Lee Assignee: Esha Maharishi (Inactive)
Resolution: Duplicate Votes: 7
Labels: ShardingRoughEdges, pm-1051-legacy-tickets
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File move_primary.js    
Issue Links:
Depends
Duplicate
duplicates SERVER-32643 ensure 'clone' command can be used to... Closed
is duplicated by SERVER-8870 mongos unaware of database move after... Closed
is duplicated by SERVER-12688 After a shard is removed, db.collecti... Closed
Related
is related to SERVER-11509 movePrimary should error when databas... Closed
is related to SERVER-22905 mongos are having different data in s... Closed
Operating System: ALL
Steps To Reproduce:

1. Create a sharded cluster (eg. two shards: A and B).
2. Create a shardable database (eg. test).
3. Create a sharded one-chunk, collection (eg. test.counter).
4. Change the primary shard for the database (eg. A => B).
5. db.getCollectionNames() should not include "test.counter".

Participants:
Case:

 Description   

db.getCollectionNames() on mongos essentially reflects db.getCollectionNames() output from the mongod of the database's primary shard. If small, one-chunk collections are created prior to a movePrimary, db.getCollectionNames() query the newly changed primary shard which doesn't report the existence of those small, one-chunk collections.

mongos> sh.status()
--- Sharding Status --- 
  sharding version: { "_id" : 1, "version" : 3 }
  shards:
	{  "_id" : "s1",  "host" : "s1/localhost:10000,localhost:10001,localhost:10002",  "tags" : [ 	"a" ] }
	{  "_id" : "s2",  "host" : "s2/localhost:20000,localhost:20001,localhost:20002",  "tags" : [ 	"b" ] }
  databases:
	{  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
	{  "_id" : "test",  "partitioned" : true,  "primary" : "s2" }
 
mongos> db.counter.insert({a:1})
mongos> db.counter.ensureIndex({a:1})
mongos> sh.shardCollection("test.counter",{a:1})
{ "collectionsharded" : "test.counter", "ok" : 1 }
mongos> sh.status()
--- Sharding Status --- 
  sharding version: { "_id" : 1, "version" : 3 }
  shards:
	{  "_id" : "s1",  "host" : "s1/localhost:10000,localhost:10001,localhost:10002",  "tags" : [ 	"a" ] }
	{  "_id" : "s2",  "host" : "s2/localhost:20000,localhost:20001,localhost:20002",  "tags" : [ 	"b" ] }
  databases:
	{  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
	{  "_id" : "test",  "partitioned" : true,  "primary" : "s2" }
		test.counter chunks:
				s2	1
			{ "a" : { $minKey : 1 } } -->> { "a" : { $maxKey : 1 } } on : s2 Timestamp(1000, 0) 
 
mongos> db.getCollectionNames()
[ "counter", "system.indexes" ]
mongos> db.adminCommand({movePrimary:"test",to:"s1"})
{
	"primary " : "s1:s1/localhost:10000,localhost:10001,localhost:10002",
	"ok" : 1
}
mongos> db.getCollectionNames()
[ "system.indexes" ]
mongos> db.adminCommand({movePrimary:"test",to:"s2"})
{
	"primary " : "s2:s2/localhost:20000,localhost:20001,localhost:20002",
	"ok" : 1
}
mongos> db.getCollectionNames()
[ "counter", "system.indexes" ]



 Comments   
Comment by Sheeri Cabral (Inactive) [ 31/Oct/19 ]

please close and link appropriately. done in 4.0!!!

Comment by James Blackburn [ 14/Oct/16 ]

It would be great to have the movePrimary and dropDatabase followed by re-create issues fixed.

The fact the cluster enters a split brain scenario is confusing and invariably leads to dataloss.

Comment by Remon van Vliet [ 13/Aug/13 ]

There should be a dedicated ticket for the root cause of this and similar issues so it can be tracked more easily as this ticket does not describe or cover the root cause.

Comment by James Wahlin [ 01/Apr/13 ]

Attaching reproduction script for SERVER-8870, which is believed to have the same root cause as this ticket. The script (move_primary.js) performs the following:

  1. Sets up a non-sharded database on a sharded cluster (with 2 mongos instances)
  2. Inserts a record to collection in the db
  3. Performs a movePrimary to move the database from one shard to another
  4. Inserts an additional record
  5. Confirms whether a count() on both mongos instances returns the same #.
Generated at Thu Feb 08 03:16:26 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.