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

cleanupOrphaned does nothing on empty shard

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.5.5
    • Affects Version/s: 2.5.2
    • Component/s: Sharding
    • Labels:
    • Fully Compatible
    • ALL
    • Hide
      var st = new ShardingTest({
          other: {
              rs: true,
              rsOptions: {nodes: 2}
          }
      });
      
      st.stopBalancer();
      
      var mongos = st.s0;
      var mongosAdmin = mongos.getDB('admin');
      var dbName = 'foo';
      var collectionName = 'bar';
      var ns = dbName + '.' + collectionName;
      var coll = mongos.getCollection(ns);
      
      assert.commandWorked(mongosAdmin.runCommand({
          enableSharding: coll.getDB().getName()
      }));
      
      assert.commandWorked(mongosAdmin.runCommand({
          shardCollection: ns,
          key: {_id: 1}
      }));
      
      // Collection's home is shard1, there are no chunks assigned to shard0.
      st.printShardingStatus();
      st.shard0.getCollection(ns).insert({});
      assert.eq(null, st.shard0.getDB(dbName).getLastError());
      assert.eq(1, st.shard0.getCollection(ns).count());
      jsTest.log('Running cleanupOrphaned on ' + st.shard0);
      response = st.shard0.getDB('admin').runCommand({cleanupOrphaned: ns});
      assert.commandWorked(response);
      assert.eq(null, response.stoppedAtKey);
      assert.eq(
          0, st.shard0.getCollection(ns).count(),
          "cleanupOrphaned didn't delete orphan on empty shard.");
      
      Show
      var st = new ShardingTest({ other: { rs: true , rsOptions: {nodes: 2} } }); st.stopBalancer(); var mongos = st.s0; var mongosAdmin = mongos.getDB( 'admin' ); var dbName = 'foo' ; var collectionName = 'bar' ; var ns = dbName + '.' + collectionName; var coll = mongos.getCollection(ns); assert .commandWorked(mongosAdmin.runCommand({ enableSharding: coll.getDB().getName() })); assert .commandWorked(mongosAdmin.runCommand({ shardCollection: ns, key: {_id: 1} })); // Collection's home is shard1, there are no chunks assigned to shard0. st.printShardingStatus(); st.shard0.getCollection(ns).insert({}); assert .eq( null , st.shard0.getDB(dbName).getLastError()); assert .eq(1, st.shard0.getCollection(ns).count()); jsTest.log( 'Running cleanupOrphaned on ' + st.shard0); response = st.shard0.getDB( 'admin' ).runCommand({cleanupOrphaned: ns}); assert .commandWorked(response); assert .eq( null , response.stoppedAtKey); assert .eq( 0, st.shard0.getCollection(ns).count(), "cleanupOrphaned didn't delete orphan on empty shard." );

      On a shard with no chunks assigned to it for a sharded collection, I expect cleanupOrphaned to remove any document in that collection. But in fact cleanupOrphaned returns without removing anything.

            Assignee:
            randolph@mongodb.com Randolph Tan
            Reporter:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: