diff options
author | Jonathan Abrahams <jonathan@mongodb.com> | 2016-03-09 12:17:50 -0500 |
---|---|---|
committer | Jonathan Abrahams <jonathan@mongodb.com> | 2016-03-09 12:18:14 -0500 |
commit | 4ae691e8edc87d0e3cfb633bb91c328426be007b (patch) | |
tree | 52079a593f54382ca13a2e741633eab1b6271893 /jstests/sharding/cleanup_orphaned_basic.js | |
parent | a025d43f3ce2efc1fb1282a718f5d286fa0a4dc1 (diff) | |
download | mongo-4ae691e8edc87d0e3cfb633bb91c328426be007b.tar.gz |
SERVER-22468 Format JS code with approved style in jstests/
Diffstat (limited to 'jstests/sharding/cleanup_orphaned_basic.js')
-rw-r--r-- | jstests/sharding/cleanup_orphaned_basic.js | 244 |
1 files changed, 107 insertions, 137 deletions
diff --git a/jstests/sharding/cleanup_orphaned_basic.js b/jstests/sharding/cleanup_orphaned_basic.js index 387863ee75d..3ed9015941b 100644 --- a/jstests/sharding/cleanup_orphaned_basic.js +++ b/jstests/sharding/cleanup_orphaned_basic.js @@ -3,142 +3,112 @@ // command fail. // -(function() { -"use strict"; - -/***************************************************************************** - * Unsharded mongod. - ****************************************************************************/ - -// cleanupOrphaned fails against unsharded mongod. -var mongod = MongoRunner.runMongod(); -assert.commandFailed(mongod.getDB('admin').runCommand({cleanupOrphaned: 'foo.bar'})); - -/***************************************************************************** - * Bad invocations of cleanupOrphaned command. - ****************************************************************************/ - -var st = new ShardingTest({ - other: { - rs: true, - rsOptions: {nodes: 2} - } -}); - -var mongos = st.s0; -var shards = mongos.getCollection('config.shards').find().toArray(); -var mongosAdmin = mongos.getDB('admin'); -var dbName = 'foo'; -var collectionName = 'bar'; -var ns = dbName + '.' + collectionName; -var coll = mongos.getCollection(ns); - -// cleanupOrphaned fails against mongos ('no such command'): it must be run -// on mongod. -assert.commandFailed(mongosAdmin.runCommand({cleanupOrphaned: ns})); - -// cleanupOrphaned must be run on admin DB. -var shardFooDB = st.shard0.getDB(dbName); -assert.commandFailed(shardFooDB.runCommand({cleanupOrphaned: ns})); - -// Must be run on primary. -var secondaryAdmin = st.rs0.getSecondary().getDB('admin'); -var response = secondaryAdmin.runCommand({cleanupOrphaned: ns}); -print('cleanupOrphaned on secondary:'); -printjson(response); -assert.commandFailed(response); - -var shardAdmin = st.shard0.getDB('admin'); -var badNS = ' \\/."*<>:|?'; -assert.commandFailed(shardAdmin.runCommand({cleanupOrphaned: badNS})); - -// cleanupOrphaned works on sharded collection. -assert.commandWorked(mongosAdmin.runCommand({ - enableSharding: coll.getDB().getName() -})); - -st.ensurePrimaryShard(coll.getDB().getName(), shards[0]._id); - -assert.commandWorked(mongosAdmin.runCommand({ - shardCollection: ns, - key: {_id: 1} -})); - -assert.commandWorked(shardAdmin.runCommand({cleanupOrphaned: ns})); - -/***************************************************************************** - * Empty shard. - ****************************************************************************/ - -// Ping shard[1] so it will be aware that it is sharded. Otherwise cleanupOrphaned -// may fail. -assert.commandWorked(mongosAdmin.runCommand({ - moveChunk: coll.getFullName(), - find: {_id: 1}, - to: shards[1]._id -})); - -assert.commandWorked(mongosAdmin.runCommand({ - moveChunk: coll.getFullName(), - find: {_id: 1}, - to: shards[0]._id -})); - -// Collection's home is shard0, there are no chunks assigned to shard1. -st.shard1.getCollection(ns).insert({}); -assert.eq(null, st.shard1.getDB(dbName).getLastError()); -assert.eq(1, st.shard1.getCollection(ns).count()); -response = st.shard1.getDB('admin').runCommand({cleanupOrphaned: ns}); -assert.commandWorked(response); -assert.eq({_id: {$maxKey:1}}, response.stoppedAtKey); -assert.eq( - 0, st.shard1.getCollection(ns).count(), - "cleanupOrphaned didn't delete orphan on empty shard."); - -/***************************************************************************** - * Bad startingFromKeys. - ****************************************************************************/ - -// startingFromKey of MaxKey. -response = shardAdmin.runCommand({ - cleanupOrphaned: ns, - startingFromKey: {_id: MaxKey} -}); -assert.commandWorked(response); -assert.eq(null, response.stoppedAtKey); - -// startingFromKey doesn't match number of fields in shard key. -assert.commandFailed(shardAdmin.runCommand({ - cleanupOrphaned: ns, - startingFromKey: {someKey: 'someValue', someOtherKey: 1} -})); - -// startingFromKey matches number of fields in shard key but not field names. -assert.commandFailed(shardAdmin.runCommand({ - cleanupOrphaned: ns, - startingFromKey: {someKey: 'someValue'} -})); - -var coll2 = mongos.getCollection('foo.baz'); - -assert.commandWorked(mongosAdmin.runCommand({ - shardCollection: coll2.getFullName(), - key: {a:1, b:1} -})); - - -// startingFromKey doesn't match number of fields in shard key. -assert.commandFailed(shardAdmin.runCommand({ - cleanupOrphaned: coll2.getFullName(), - startingFromKey: {someKey: 'someValue'} -})); - -// startingFromKey matches number of fields in shard key but not field names. -assert.commandFailed(shardAdmin.runCommand({ - cleanupOrphaned: coll2.getFullName(), - startingFromKey: {a: 'someValue', c: 1} -})); - -st.stop(); +(function() { + "use strict"; + + /***************************************************************************** + * Unsharded mongod. + ****************************************************************************/ + + // cleanupOrphaned fails against unsharded mongod. + var mongod = MongoRunner.runMongod(); + assert.commandFailed(mongod.getDB('admin').runCommand({cleanupOrphaned: 'foo.bar'})); + + /***************************************************************************** + * Bad invocations of cleanupOrphaned command. + ****************************************************************************/ + + var st = new ShardingTest({other: {rs: true, rsOptions: {nodes: 2}}}); + + var mongos = st.s0; + var shards = mongos.getCollection('config.shards').find().toArray(); + var mongosAdmin = mongos.getDB('admin'); + var dbName = 'foo'; + var collectionName = 'bar'; + var ns = dbName + '.' + collectionName; + var coll = mongos.getCollection(ns); + + // cleanupOrphaned fails against mongos ('no such command'): it must be run + // on mongod. + assert.commandFailed(mongosAdmin.runCommand({cleanupOrphaned: ns})); + + // cleanupOrphaned must be run on admin DB. + var shardFooDB = st.shard0.getDB(dbName); + assert.commandFailed(shardFooDB.runCommand({cleanupOrphaned: ns})); + + // Must be run on primary. + var secondaryAdmin = st.rs0.getSecondary().getDB('admin'); + var response = secondaryAdmin.runCommand({cleanupOrphaned: ns}); + print('cleanupOrphaned on secondary:'); + printjson(response); + assert.commandFailed(response); + + var shardAdmin = st.shard0.getDB('admin'); + var badNS = ' \\/."*<>:|?'; + assert.commandFailed(shardAdmin.runCommand({cleanupOrphaned: badNS})); + + // cleanupOrphaned works on sharded collection. + assert.commandWorked(mongosAdmin.runCommand({enableSharding: coll.getDB().getName()})); + + st.ensurePrimaryShard(coll.getDB().getName(), shards[0]._id); + + assert.commandWorked(mongosAdmin.runCommand({shardCollection: ns, key: {_id: 1}})); + + assert.commandWorked(shardAdmin.runCommand({cleanupOrphaned: ns})); + + /***************************************************************************** + * Empty shard. + ****************************************************************************/ + + // Ping shard[1] so it will be aware that it is sharded. Otherwise cleanupOrphaned + // may fail. + assert.commandWorked(mongosAdmin.runCommand( + {moveChunk: coll.getFullName(), find: {_id: 1}, to: shards[1]._id})); + + assert.commandWorked(mongosAdmin.runCommand( + {moveChunk: coll.getFullName(), find: {_id: 1}, to: shards[0]._id})); + + // Collection's home is shard0, there are no chunks assigned to shard1. + st.shard1.getCollection(ns).insert({}); + assert.eq(null, st.shard1.getDB(dbName).getLastError()); + assert.eq(1, st.shard1.getCollection(ns).count()); + response = st.shard1.getDB('admin').runCommand({cleanupOrphaned: ns}); + assert.commandWorked(response); + assert.eq({_id: {$maxKey: 1}}, response.stoppedAtKey); + assert.eq(0, + st.shard1.getCollection(ns).count(), + "cleanupOrphaned didn't delete orphan on empty shard."); + + /***************************************************************************** + * Bad startingFromKeys. + ****************************************************************************/ + + // startingFromKey of MaxKey. + response = shardAdmin.runCommand({cleanupOrphaned: ns, startingFromKey: {_id: MaxKey}}); + assert.commandWorked(response); + assert.eq(null, response.stoppedAtKey); + + // startingFromKey doesn't match number of fields in shard key. + assert.commandFailed(shardAdmin.runCommand( + {cleanupOrphaned: ns, startingFromKey: {someKey: 'someValue', someOtherKey: 1}})); + + // startingFromKey matches number of fields in shard key but not field names. + assert.commandFailed( + shardAdmin.runCommand({cleanupOrphaned: ns, startingFromKey: {someKey: 'someValue'}})); + + var coll2 = mongos.getCollection('foo.baz'); + + assert.commandWorked( + mongosAdmin.runCommand({shardCollection: coll2.getFullName(), key: {a: 1, b: 1}})); + + // startingFromKey doesn't match number of fields in shard key. + assert.commandFailed(shardAdmin.runCommand( + {cleanupOrphaned: coll2.getFullName(), startingFromKey: {someKey: 'someValue'}})); + + // startingFromKey matches number of fields in shard key but not field names. + assert.commandFailed(shardAdmin.runCommand( + {cleanupOrphaned: coll2.getFullName(), startingFromKey: {a: 'someValue', c: 1}})); + + st.stop(); })(); |