Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-90040

Dropping collection via direct connection can cause uuid inconsistencies

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 5.0.0, 6.0.0, 7.0.0, 8.0.0-rc0, 7.3.0
    • Component/s: None
    • None
    • Catalog and Routing
    • ALL
    • Hide

      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();

      Show
      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();

      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

            Assignee:
            Unassigned Unassigned
            Reporter:
            enrico.golfieri@mongodb.com Enrico Golfieri
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: