2011-03-06 08:51:59 +01:00
|
|
|
// Tests splitting a chunk twice
|
2015-10-22 17:18:50 +02:00
|
|
|
(function() {
|
2016-04-14 21:41:16 +02:00
|
|
|
'use strict';
|
2011-03-06 08:51:59 +01:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
var s = new ShardingTest({name: "shard_keycount", shards: 2, mongos: 1, other: {chunkSize: 1}});
|
2012-06-24 02:37:33 +02:00
|
|
|
|
2016-04-14 21:41:16 +02:00
|
|
|
var dbName = "test";
|
|
|
|
var collName = "foo";
|
|
|
|
var ns = dbName + "." + collName;
|
2011-03-06 08:51:59 +01:00
|
|
|
|
2016-04-14 21:41:16 +02:00
|
|
|
var db = s.getDB(dbName);
|
2011-03-06 08:51:59 +01:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
for (var i = 0; i < 10; i++) {
|
|
|
|
db.foo.insert({_id: i});
|
|
|
|
}
|
2011-03-06 08:51:59 +01:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
// Enable sharding on DB
|
2016-04-14 21:41:16 +02:00
|
|
|
assert.commandWorked(s.s0.adminCommand({enablesharding: dbName}));
|
2018-02-07 23:38:49 +01:00
|
|
|
s.ensurePrimaryShard(dbName, s.shard1.shardName);
|
2011-03-06 08:51:59 +01:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
// Enable sharding on collection
|
2016-04-14 21:41:16 +02:00
|
|
|
assert.commandWorked(s.s0.adminCommand({shardcollection: ns, key: {_id: 1}}));
|
2011-03-06 08:51:59 +01:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
// Split into two chunks
|
2016-04-14 21:41:16 +02:00
|
|
|
assert.commandWorked(s.s0.adminCommand({split: ns, find: {_id: 3}}));
|
2011-03-06 08:51:59 +01:00
|
|
|
|
2016-04-14 21:41:16 +02:00
|
|
|
var coll = db.getCollection(collName);
|
2011-03-06 08:51:59 +01:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
// Split chunk again
|
2016-04-14 21:41:16 +02:00
|
|
|
assert.commandWorked(s.s0.adminCommand({split: ns, find: {_id: 3}}));
|
2011-03-06 08:51:59 +01:00
|
|
|
|
2016-04-14 21:41:16 +02:00
|
|
|
assert.writeOK(coll.update({_id: 3}, {_id: 3}));
|
2011-03-06 08:51:59 +01:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
// Split chunk again
|
2016-04-14 21:41:16 +02:00
|
|
|
assert.commandWorked(s.s0.adminCommand({split: ns, find: {_id: 3}}));
|
2011-03-06 08:51:59 +01:00
|
|
|
|
2016-04-14 21:41:16 +02:00
|
|
|
assert.writeOK(coll.update({_id: 3}, {_id: 3}));
|
2011-03-06 08:51:59 +01:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
// Split chunk again
|
2016-04-14 21:41:16 +02:00
|
|
|
assert.commandWorked(s.s0.adminCommand({split: ns, find: {_id: 3}}));
|
2011-03-06 08:51:59 +01:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
s.stop();
|
2016-04-14 21:41:16 +02:00
|
|
|
})();
|