Skip to content

Commit fbefd67

Browse files
comerfordbenety
authored andcommitted
SERVER-6352 Add sh.removeTagRange
Adding the removeTagRange helper to match addTagRange with some informational warnings that do not stop the operation from happening. Note: does not address the fact that no feedback is given to indicate work done, or lack of work done (must check config.tags manually for results). This is also the case for addTagRange. Closes mongodb#709 Signed-off-by: Benety Goh <[email protected]>
1 parent 98fb05b commit fbefd67

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

jstests/sharding/tag_range.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// tests to make sure that tag ranges are added/removed/updated successfully
2+
3+
s = new ShardingTest( "tag_range" , 2 , 0 , 1 , { nopreallocj : true } );
4+
5+
// this set up is not required but prevents warnings in the remove
6+
db = s.getDB( "tag_range" );
7+
8+
s.adminCommand( { enableSharding : "test" } )
9+
s.adminCommand( { shardCollection : "test.tag_range" , key : { _id : 1 } } );
10+
11+
assert.eq( 1 , s.config.chunks.count() );
12+
13+
sh.addShardTag( "shard0000" , "a" )
14+
15+
// add two ranges, verify the additions
16+
17+
sh.addTagRange( "test.tag_range" , { _id : 5 } , { _id : 10 } , "a" );
18+
sh.addTagRange( "test.tag_range" , { _id : 10 } , { _id : 15 } , "b" );
19+
20+
assert.eq( 2 , s.config.tags.count() , "tag ranges were not successfully added" );
21+
22+
// remove the second range, should be left with one
23+
24+
sh.removeTagRange( "test.tag_range" , { _id : 10 } , { _id : 15 } , "b" );
25+
26+
assert.eq( 1 , s.config.tags.count() , "tag range not removed successfully" );
27+
28+
// the additions are actually updates, so you can alter a range's max
29+
sh.addTagRange( "test.tag_range" , { _id : 5 } , { _id : 11 } , "a" );
30+
31+
assert.eq( 11 , s.config.tags.findOne().max._id , "tag range not updated successfully" );
32+
33+
s.stop();
34+

src/mongo/shell/utils_sh.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ sh.help = function() {
4747
print( "\tsh.addShardTag(shard,tag) adds the tag to the shard" );
4848
print( "\tsh.removeShardTag(shard,tag) removes the tag from the shard" );
4949
print( "\tsh.addTagRange(fullName,min,max,tag) tags the specified range of the given collection" );
50+
print( "\tsh.removeTagRange(fullName,min,max,tag) removes the tagged range of the given collection" );
5051

5152
print( "\tsh.status() prints a general overview of the cluster" )
5253
}
@@ -351,3 +352,19 @@ sh.addTagRange = function( ns, min, max, tag ) {
351352
true );
352353
sh._checkLastError( config );
353354
}
355+
356+
sh.removeTagRange = function( ns, min, max, tag ) {
357+
var config = db.getSisterDB( "config" );
358+
// warn if the namespace does not exist, even dropped
359+
if ( config.collections.findOne( { _id : ns } ) == null ) {
360+
print( "Warning: can't find the namespace: " + ns + " - collection likely never sharded" );
361+
}
362+
// warn if the tag being removed is still in use
363+
if ( config.shards.findOne( { tags : tag } ) ) {
364+
print( "Warning: tag still in use by at least one shard" );
365+
}
366+
// max and tag criteria not really needed, but including them avoids potentially unexpected
367+
// behavior.
368+
config.tags.remove( { _id : { ns : ns , min : min } , max : max , tag : tag } );
369+
sh._checkLastError( config );
370+
}

0 commit comments

Comments
 (0)