-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "SERVER-18124 Move tags loading to the catalog manager""
This reverts commit b59643c.
- Loading branch information
Showing
23 changed files
with
836 additions
and
824 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Test balancing all chunks off of one shard | ||
var s = new ShardingTest("balance_tags1", 3, 1, 1, { sync:true, chunksize : 1, nopreallocj : true }); | ||
s.config.settings.update({ _id: "balancer" }, { $set: { stopped: false }}, true); | ||
|
||
s.adminCommand({ enablesharding: "test" }); | ||
s.ensurePrimaryShard('test', 'shard0001'); | ||
|
||
var db = s.getDB("test"); | ||
|
||
var bulk = db.foo.initializeUnorderedBulkOp(); | ||
for (i = 0; i < 21; i++) { | ||
bulk.insert({ _id: i, x: i }); | ||
} | ||
assert.writeOK(bulk.execute()); | ||
|
||
sh.shardCollection("test.foo", { _id : 1 }); | ||
|
||
sh.stopBalancer(); | ||
|
||
for (i = 0; i < 20; i++) { | ||
s.adminCommand({ split : "test.foo", middle : { _id : i } }); | ||
} | ||
|
||
sh.startBalancer(); | ||
|
||
sh.status(true); | ||
|
||
// Wait for the initial balance to happen | ||
assert.soon(function() { | ||
var counts = s.chunkCounts("foo"); | ||
printjson(counts); | ||
return counts["shard0000"] == 7 && | ||
counts["shard0001"] == 7 && | ||
counts["shard0002"] == 7; | ||
}, | ||
"balance 1 didn't happen", | ||
1000 * 60 * 10, | ||
1000); | ||
|
||
// Quick test of some shell helpers and setting up state | ||
sh.addShardTag("shard0000", "a"); | ||
assert.eq([ "a" ] , s.config.shards.findOne({ _id : "shard0000" }).tags); | ||
|
||
sh.addShardTag("shard0000", "b"); | ||
assert.eq([ "a" , "b" ], s.config.shards.findOne({ _id : "shard0000" }).tags); | ||
|
||
sh.removeShardTag("shard0000", "b"); | ||
assert.eq([ "a" ], s.config.shards.findOne( { _id : "shard0000" } ).tags); | ||
|
||
sh.addShardTag("shard0001" , "a"); | ||
sh.addTagRange("test.foo" , { _id : -1 } , { _id : 1000 } , "a"); | ||
|
||
sh.status( true ); | ||
|
||
// At this point, everything should drain off shard 2, which does not have the tag | ||
assert.soon(function() { | ||
var counts = s.chunkCounts("foo"); | ||
printjson(counts); | ||
return counts["shard0002"] == 0; | ||
}, | ||
"balance 2 didn't happen", | ||
1000 * 60 * 10 , 1000); | ||
|
||
printjson(sh.status()); | ||
|
||
s.stop(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Test balancing all chunks to one shard by tagging the full shard-key range on that collection | ||
var s = new ShardingTest("balance_tags2", 3, 1, 1, { sync:true, chunksize : 1, nopreallocj : true }); | ||
s.config.settings.update({ _id: "balancer" }, { $set: { stopped: false }}, true); | ||
|
||
s.adminCommand({ enablesharding: "test" }); | ||
s.ensurePrimaryShard('test', 'shard0001'); | ||
|
||
var db = s.getDB("test"); | ||
|
||
var bulk = db.foo.initializeUnorderedBulkOp(); | ||
for (i = 0; i < 21; i++) { | ||
bulk.insert({ _id: i, x: i }); | ||
} | ||
assert.writeOK(bulk.execute()); | ||
|
||
sh.shardCollection("test.foo", { _id : 1 }); | ||
|
||
sh.stopBalancer(); | ||
|
||
for (i = 0; i < 20; i++) { | ||
sh.splitAt("test.foo", {_id : i}); | ||
} | ||
|
||
sh.startBalancer(); | ||
|
||
sh.status(true); | ||
|
||
// Wait for the initial balance to happen | ||
assert.soon(function() { | ||
var counts = s.chunkCounts("foo"); | ||
printjson(counts); | ||
return counts["shard0000"] == 7 && | ||
counts["shard0001"] == 7 && | ||
counts["shard0002"] == 7; | ||
}, | ||
"balance 1 didn't happen", | ||
1000 * 60 * 10, | ||
1000); | ||
|
||
// Tag one shard | ||
sh.addShardTag("shard0000" , "a"); | ||
assert.eq([ "a" ] , s.config.shards.findOne({ _id : "shard0000" }).tags); | ||
|
||
// Tag the whole collection (ns) to one shard | ||
sh.addTagRange("test.foo", { _id : MinKey }, { _id : MaxKey }, "a"); | ||
|
||
// Wait for things to move to that one shard | ||
sh.status(true); | ||
|
||
assert.soon(function() { | ||
var counts = s.chunkCounts("foo"); | ||
printjson(counts); | ||
return counts["shard0001"] == 0 && | ||
counts["shard0002"] == 0; | ||
}, | ||
"balance 2 didn't happen", | ||
1000 * 60 * 10, | ||
1000); | ||
|
||
printjson(sh.status()); | ||
|
||
s.stop(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.