1
1
/**
2
2
* Tests that a collection with zone definitions has its zones dropped when it is unsharded.
3
- * @tags : [assumes_balancer_off]
3
+ * @tags : [
4
+ * assumes_balancer_off,
5
+ * does_not_support_stepdowns
6
+ * ]
4
7
*/
5
8
6
9
import { Thread } from "jstests/libs/parallelTester.js" ;
@@ -13,53 +16,57 @@ if (shards.length < 2) {
13
16
}
14
17
15
18
Random . setRandomSeed ( ) ;
16
- const dbName = db . getName ( ) ;
19
+
20
+ const testDb = db . getSiblingDB ( jsTestName ( ) ) ;
21
+ testDb . dropDatabase ( ) ;
22
+
23
+ const dbName = testDb . getName ( ) ;
17
24
18
25
let shard0 = shards [ 0 ] ;
19
26
let shard1 = shards [ 1 ] ;
20
27
21
- assert . commandWorked ( db . adminCommand ( { enableSharding : dbName , primaryShard : shard0 . _id } ) ) ;
28
+ assert . commandWorked ( testDb . adminCommand ( { enableSharding : dbName , primaryShard : shard0 . _id } ) ) ;
22
29
23
- assert . commandWorked ( db . adminCommand ( { addShardToZone : shard0 . _id , zone : "zone1" } ) ) ;
24
- assert . commandWorked ( db . adminCommand ( { addShardToZone : shard1 . _id , zone : "zone2" } ) ) ;
30
+ assert . commandWorked ( testDb . adminCommand ( { addShardToZone : shard0 . _id , zone : "zone1" } ) ) ;
31
+ assert . commandWorked ( testDb . adminCommand ( { addShardToZone : shard1 . _id , zone : "zone2" } ) ) ;
25
32
26
33
const collName = jsTestName ( ) ;
27
34
const ns = dbName + '.' + collName ;
28
35
29
- assert . commandWorked ( db . createCollection ( collName ) ) ;
30
- assert . commandWorked ( db . adminCommand ( { shardCollection : ns , key : { x : 1 } } ) ) ;
31
- assert . commandWorked ( db . adminCommand ( { split : ns , middle : { x : 0 } } ) ) ;
36
+ assert . commandWorked ( testDb . createCollection ( collName ) ) ;
37
+ assert . commandWorked ( testDb . adminCommand ( { shardCollection : ns , key : { x : 1 } } ) ) ;
38
+ assert . commandWorked ( testDb . adminCommand ( { split : ns , middle : { x : 0 } } ) ) ;
32
39
33
- assert . commandWorked ( db . adminCommand ( { moveChunk : ns , find : { x : 0 } , to : shard1 . _id } ) ) ;
40
+ assert . commandWorked ( testDb . adminCommand ( { moveChunk : ns , find : { x : 0 } , to : shard1 . _id } ) ) ;
34
41
35
42
// Define zones for test collection.
36
43
assert . commandWorked (
37
- db . adminCommand ( { updateZoneKeyRange : ns , min : { x : MinKey } , max : { x : 0 } , zone : "zone1" } ) ) ;
44
+ testDb . adminCommand ( { updateZoneKeyRange : ns , min : { x : MinKey } , max : { x : 0 } , zone : "zone1" } ) ) ;
38
45
assert . commandWorked (
39
- db . adminCommand ( { updateZoneKeyRange : ns , min : { x : 0 } , max : { x : MaxKey } , zone : "zone2" } ) ) ;
46
+ testDb . adminCommand ( { updateZoneKeyRange : ns , min : { x : 0 } , max : { x : MaxKey } , zone : "zone2" } ) ) ;
40
47
41
48
for ( let i = 0 ; i < 5000 ; i ++ ) {
42
- db . getCollection ( ns ) . insert ( { x : i } ) ;
49
+ testDb . getCollection ( ns ) . insert ( { x : i } ) ;
43
50
}
44
51
45
52
const unshardCollectionThread = function ( host , ns ) {
46
53
const mongos = new Mongo ( host ) ;
47
54
mongos . adminCommand ( { unshardCollection : ns } ) ;
48
55
} ;
49
56
50
- let threadForTest = new Thread ( unshardCollectionThread , db . getMongo ( ) . host , ns ) ;
57
+ let threadForTest = new Thread ( unshardCollectionThread , testDb . getMongo ( ) . host , ns ) ;
51
58
threadForTest . start ( ) ;
52
59
53
60
// Since we sleep for a random interval, there is a chance the unsharding will succeed
54
61
// before the abort can happen.
55
62
sleep ( Random . randInt ( 10 * 1000 ) ) ;
56
63
57
- db . adminCommand ( { abortUnshardCollection : ns } ) ;
64
+ testDb . adminCommand ( { abortUnshardCollection : ns } ) ;
58
65
59
66
threadForTest . join ( ) ;
60
67
61
- let configCollectionDoc = db . getSiblingDB ( 'config' ) . collections . findOne ( { _id : ns } ) . key ;
62
- const tags = db . getSiblingDB ( 'config' ) . tags . find ( { ns : ns } ) . toArray ( ) ;
68
+ let configCollectionDoc = testDb . getSiblingDB ( 'config' ) . collections . findOne ( { _id : ns } ) . key ;
69
+ const tags = testDb . getSiblingDB ( 'config' ) . tags . find ( { ns : ns } ) . toArray ( ) ;
63
70
64
71
// If we successfully unsharded our collection, we should have 0 zones in config.tags.
65
72
// If unsharding was unsuccessful, we should retain 2 tags since we specified 2 zones for
0 commit comments