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

Able to rename drop-pending collection namespaces using applyOps command

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Replication
    • Labels:
      None
    • Replication
    • ALL
    • Hide
      
      load("jstests/libs/check_log.js");  // For 'checkLog'.
      function pauseOplogApplication(node) {
          assert.commandWorked(node.adminCommand(
              {configureFailPoint: "rsSyncApplyStop", mode: "alwaysOn"}));
          checkLog.contains(node, "rsSyncApplyStop fail point enabled");
      }
      
      function resumeOplogApplication(node) {
          assert.commandWorked(
              node.adminCommand({configureFailPoint: "rsSyncApplyStop", mode: "off"}));
      }
      
      function listAllCollections(adb){
          let res = assert.commandWorked(adb.runCommand("listCollections", {includePendingDrops: true}));
          return tojson(res.cursor.firstBatch);
      }
      
      let replTest = new ReplSetTest({name: "applyOpsTest", nodes: 2});
      
      replTest.startSet();
      replTest.initiate();
      replTest.awaitReplication();
      
      // Pause oplog application so collection drop doesn't commit.
      pauseOplogApplication(replTest.getSecondary());
      
      // Get connections and collection.
      let primary = replTest.getPrimary();
      let pdb = primary.getDB("test");
      let collName = "coll";
      
      // Create collection.
      pdb[collName].insert({x:1});
      
      let uuid = pdb.getCollectionInfos()[0].info.uuid;
      
      // Drop collection.
      jsTestLog("Doing collection drop.");
      assert.commandWorked(pdb.runCommand({drop: collName, writeConcern: {w: 1}}));
      
      // Print collections after drop.
      jsTestLog(listAllCollections(pdb));
      
      let renameOp = [{
          "op": "c",
          "ns": "test.$cmd",
          "ui": uuid,
          "o": {"renameCollection": "", "to": "test.not_drop_pending"}
      }];
      
      jsTestLog("Doing 'applyOps' command.");
      assert.commandWorked(pdb.adminCommand({applyOps: renameOp}));
      
      // Print collections after renameCollection.
      jsTestLog(listAllCollections(pdb));
      
      Show
      load( "jstests/libs/check_log.js" ); // For 'checkLog' . function pauseOplogApplication(node) { assert.commandWorked(node.adminCommand( {configureFailPoint: "rsSyncApplyStop" , mode: "alwaysOn" })); checkLog.contains(node, "rsSyncApplyStop fail point enabled" ); } function resumeOplogApplication(node) { assert.commandWorked( node.adminCommand({configureFailPoint: "rsSyncApplyStop" , mode: "off" })); } function listAllCollections(adb){ let res = assert.commandWorked(adb.runCommand( "listCollections" , {includePendingDrops: true })); return tojson(res.cursor.firstBatch); } let replTest = new ReplSetTest({name: "applyOpsTest" , nodes: 2}); replTest.startSet(); replTest.initiate(); replTest.awaitReplication(); // Pause oplog application so collection drop doesn't commit. pauseOplogApplication(replTest.getSecondary()); // Get connections and collection. let primary = replTest.getPrimary(); let pdb = primary.getDB( "test" ); let collName = "coll" ; // Create collection. pdb[collName].insert({x:1}); let uuid = pdb.getCollectionInfos()[0].info.uuid; // Drop collection. jsTestLog( "Doing collection drop." ); assert.commandWorked(pdb.runCommand({drop: collName, writeConcern: {w: 1}})); // Print collections after drop. jsTestLog(listAllCollections(pdb)); let renameOp = [{ "op" : "c" , "ns" : "test.$cmd" , "ui" : uuid, "o" : { "renameCollection" : "", " to ": " test.not_drop_pending"} }]; jsTestLog( "Doing 'applyOps' command." ); assert.commandWorked(pdb.adminCommand({applyOps: renameOp})); // Print collections after renameCollection. jsTestLog(listAllCollections(pdb));
    • 0

      By executing a renameCollection operation via the applyOps command, and specifying a specific collection UUID for a drop-pending collection, it is possible to rename a drop-pending collection namespace to an arbitrary value. See repro script. I expect this may cause us to never clean up such a drop-pending collection, if it was renamed away from its proper namespace format.

            Assignee:
            backlog-server-repl [DO NOT USE] Backlog - Replication Team
            Reporter:
            william.schultz@mongodb.com William Schultz (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: