summaryrefslogtreecommitdiff
path: root/jstests/replsets/temp_namespace.js
blob: d2cbe59a95f579b4ca650016cbc95d4fe851e198 (plain)
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
64
65
66
67
68
69
// SERVER-10927
// This is to make sure that temp collections get cleaned up on promotion to primary

var replTest = new ReplSetTest({ name: 'testSet', nodes: 2 });
var nodes = replTest.startSet();
replTest.initiate();
var master = replTest.getMaster();
var second = replTest.getSecondary();

var masterId = replTest.getNodeId(master);
var secondId = replTest.getNodeId(second);

var masterDB = master.getDB('test');
var secondDB = second.getDB('test');

// set up collections
masterDB.runCommand({create: 'temp1', temp: true});
masterDB.temp1.ensureIndex({x:1});
masterDB.runCommand({create: 'temp2', temp: 1});
masterDB.temp2.ensureIndex({x:1});
masterDB.runCommand({create: 'keep1', temp: false});
masterDB.runCommand({create: 'keep2', temp: 0});
masterDB.runCommand({create: 'keep3'});
masterDB.keep4.insert({});
masterDB.getLastError(2);

// make sure they exist on primary and secondary
assert.eq(masterDB.system.namespaces.count({name: /temp\d$/}) , 2); // collections
assert.eq(masterDB.system.namespaces.count({name: /temp\d\.\$.*$/}) , 4); // indexes (2 _id + 2 x)
assert.eq(masterDB.system.namespaces.count({name: /keep\d$/}) , 4);

assert.eq(secondDB.system.namespaces.count({name: /temp\d$/}) , 2); // collections
assert.eq(secondDB.system.namespaces.count({name: /temp\d\.\$.*$/}) , 4); // indexes (2 _id + 2 x)
assert.eq(secondDB.system.namespaces.count({name: /keep\d$/}) , 4);

// make sure restarting secondary doesn't drop collections
replTest.restart(secondId, {},  /*wait=*/true);
second = replTest.getSecondary();
secondDB = second.getDB('test');
assert.eq(secondDB.system.namespaces.count({name: /temp\d$/}) , 2); // collections
assert.eq(secondDB.system.namespaces.count({name: /temp\d\.\$.*$/}) , 4); // indexes (2 _id + 2 x)
assert.eq(secondDB.system.namespaces.count({name: /keep\d$/}) , 4);

// step down primary and make sure former secondary (now primary) drops collections
var threw = false;
try {
    master.adminCommand({replSetStepDown: 50, force : true});
} catch (e) {
    threw = true;
}
assert(threw);

assert.soon(function() {
    printjson(secondDB.adminCommand("replSetGetStatus"));
    printjson(secondDB.getSisterDB('local').system.replset.findOne());
    return secondDB.isMaster().ismaster;
}, '',  75*1000); // must wait for secondary to be willing to promote self

assert.eq(secondDB.system.namespaces.count({name: /temp\d$/}) , 0); // collections
assert.eq(secondDB.system.namespaces.count({name: /temp\d\.\$.*$/}) , 0); //indexes
assert.eq(secondDB.system.namespaces.count({name: /keep\d$/}) , 4);

// check that former primary dropped collections
replTest.awaitReplication()
assert.eq(masterDB.system.namespaces.count({name: /temp\d$/}) , 0); // collections
assert.eq(masterDB.system.namespaces.count({name: /temp\d\.\$.*$/}) , 0); //indexes
assert.eq(masterDB.system.namespaces.count({name: /keep\d$/}) , 4);

replTest.stopSet();