File: drop_sharded_db.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (63 lines) | stat: -rw-r--r-- 2,039 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Tests the dropping of a sharded database SERVER-3471 SERVER-1726

var st = new ShardingTest({ name : jsTestName() })
st.stopBalancer()

var mongos = st.s0
var config = mongos.getDB( "config" )

var dbName = "buy"
var dbA = mongos.getDB( dbName )
var dbB = mongos.getDB( dbName + "_201107" )
var dbC = mongos.getDB( dbName + "_201108" )

print( "1: insert some data and colls into all dbs" )

var numDocs = 3000;
var numColls = 10;
for( var i = 0; i < numDocs; i++ ){
    dbA.getCollection( "data" + (i % numColls) ).insert({ _id : i })
    dbB.getCollection( "data" + (i % numColls) ).insert({ _id : i })
    dbC.getCollection( "data" + (i % numColls) ).insert({ _id : i })
}

print( "2: shard the colls ")

for( var i = 0; i < numColls; i++ ){
    
    var key = { _id : 1 }
    st.shardColl( dbA.getCollection( "data" + i ), key )
    st.shardColl( dbB.getCollection( "data" + i ), key )
    st.shardColl( dbC.getCollection( "data" + i ), key )

}

print( "3: drop the non-suffixed db ")

dbA.dropDatabase()


print( "3: ensure only the non-suffixed db was dropped ")

var dbs = mongos.getDBNames()
for( var i = 0; i < dbs.length; i++ ){
    assert.neq( dbs, "" + dbA )
}

assert.eq( 0, config.databases.find({ _id : "" + dbA }).toArray().length )
assert.eq( 1, config.databases.find({ _id : "" + dbB }).toArray().length )
assert.eq( 1, config.databases.find({ _id : "" + dbC }).toArray().length )

assert.eq( numColls, config.collections.find({ _id : RegExp( "^" + dbA + "\\..*" ), dropped : true }).toArray().length )
assert.eq( numColls, config.collections.find({ _id : RegExp( "^" + dbB + "\\..*" ), dropped : false }).toArray().length )
assert.eq( numColls, config.collections.find({ _id : RegExp( "^" + dbC + "\\..*" ), dropped : false }).toArray().length )

for( var i = 0; i < numColls; i++ ){
    
    assert.eq( numDocs / numColls, dbB.getCollection( "data" + (i % numColls) ).find().itcount() )
    assert.eq( numDocs / numColls, dbC.getCollection( "data" + (i % numColls) ).find().itcount() ) 
    
}

// Finish
st.stop()