[SERVER-11277] cleanupOrphaned does nothing on empty shard Created: 18/Oct/13  Updated: 11/Jul/16  Resolved: 16/Dec/13

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 2.5.2
Fix Version/s: 2.5.5

Type: Bug Priority: Minor - P4
Reporter: A. Jesse Jiryu Davis Assignee: Randolph Tan
Resolution: Done Votes: 0
Labels: 26qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
related to SERVER-12178 cleanupOrphan can fail if shard is mo... Closed
is related to SERVER-8598 Add command to cleanup orphaned data ... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

 
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.");

Participants:

 Description   

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.



 Comments   
Comment by Githook User [ 16/Dec/13 ]

Author:

{u'username': u'renctan', u'name': u'Randolph Tan', u'email': u'randolph@10gen.com'}

Message: SERVER-11277 cleanupOrphaned does nothing on empty shard
Branch: master
https://github.com/mongodb/mongo/commit/99dff054c8b83caf43c42d01b0497dcb0e1ee5bf

Comment by Randolph Tan [ 25/Oct/13 ]

Note:

This is only the case when the shard is totally unaware of the sharded collection (ie., the shard does not have any version information for this namespace). In fact, we have a test for sharded collections with empty chunks:

https://github.com/mongodb/mongo/blob/2a584994ee747b46ada6c6383c7e983dcdf861a6/src/mongo/s/collection_metadata_test.cpp#L407-420

If we add a moveChunk from shard1 to shard0 and shard0 to shard1 again (this only to make setShardVersion get called on shard0) right before running the cleanup command, it will actually delete the orphaned document.

As for the case when the shard doesn't know about the sharded collection, it will complain that the namespace is not sharded and abort early.

Generated at Thu Feb 08 03:25:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.