BugZero found this defect 18 days ago.
Data sources
All data on this page is proprietary to BugZero® or gathered from public sources
5/1/2024
MongoDB Server
8.0.0-rc0
8.1.0-rc0
No fixed releases provided.
Given a replica set with a direct connection on it, once the replica-set is added to the cluster the collections in it will be registered to the CSRS. However, if the direct connection is not dropped, dropping the collection via direct connection and re-creating it via mongos will cause a uuid inconsistency The createCollectionCoordinator relies that the collection is always present both on the local catalog of the primary and on the sharding catalog. In this case, the coordinator believes the collection does not exists because it's not present locally. It will proceed to create locally a new collection with a different uuid. During the commit phase, it will fail to upsert the previous collection as the new uuid is used to find the existing document
const st = new ShardingTest({shards: 0}); const replShard = new ReplSetTest({name: "shard1", nodes: 3}); const dbName = "test" replShard.startSet({verbose: 1}); replShard.initiate(); jsTestLog("Creating a collection via direct connection."); replShard.getPrimary().getDB(dbName).createCollection("x"); jsTestLog("Adding replica set as shard."); // Restarting secondaries with --shardsvr const secondaries = replShard.getSecondaries(); secondaries.forEach(secondary => { replShard.restart(secondary, \{shardsvr: ''} ); }); // Restarting primary with --shardsvr and waiting for new primary let primary = replShard.getPrimary(); replShard.restart(primary, {shardsvr: ''}); replShard.awaitNodesAgreeOnPrimary(); assert.commandWorked(st.s.adminCommand({addShard: replShard.getURL()})); jsTestLog("Dropping the collection via direct connection.") replShard.getPrimary().getDB(dbName).x.drop() jsTestLog("Re-creating the collection via mongos will now cause an inconsistency.") st.s.getDB(dbName).createCollection("x") jsTestLog("Run rename via mongos which provides some consistency checks.") assert.commandWorked(st.s.getDB(dbName).x.renameCollection({to: "y", dropTarget: false})) st.stop(); replShard.stopSet();