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
70
71
72
73
74
75
76
77
78
79
|
/**
* Basic test from the drop collection command on a sharded cluster that verifies collections are
* cleaned up properly.
*
* @tags: [requires_fcv_47]
*/
(function() {
"use strict";
var st = new ShardingTest({shards: 2});
var testDB = st.s.getDB('test');
// Test dropping an unsharded collection.
assert.commandWorked(testDB.bar.insert({x: 1}));
assert.neq(null, testDB.bar.findOne({x: 1}));
assert.commandWorked(testDB.runCommand({drop: 'bar'}));
assert.eq(null, testDB.bar.findOne({x: 1}));
assert.commandFailedWithCode(st.s.getDB('admin').runCommand({drop: 'secrets'}),
ErrorCodes.IllegalOperation);
assert.commandFailedWithCode(st.s.getDB('config').runCommand({drop: 'settings'}),
ErrorCodes.IllegalOperation);
// Test dropping a sharded collection.
assert.commandWorked(st.s.adminCommand({enableSharding: 'test'}));
st.ensurePrimaryShard('test', st.shard0.shardName);
st.s.adminCommand({shardCollection: 'test.user', key: {_id: 1}});
st.s.adminCommand({split: 'test.user', middle: {_id: 0}});
assert.commandWorked(
st.s.adminCommand({moveChunk: 'test.user', find: {_id: 0}, to: st.shard1.shardName}));
assert.commandWorked(st.s.adminCommand({addShardToZone: st.shard1.shardName, zone: 'foo'}));
assert.commandWorked(st.s.adminCommand(
{updateZoneKeyRange: 'test.user', min: {_id: 0}, max: {_id: 10}, zone: 'foo'}));
assert.commandWorked(testDB.user.insert({_id: 10}));
assert.commandWorked(testDB.user.insert({_id: -10}));
assert.neq(null, st.shard0.getDB('test').user.findOne({_id: -10}));
assert.neq(null, st.shard1.getDB('test').user.findOne({_id: 10}));
var configDB = st.s.getDB('config');
var collDoc = configDB.collections.findOne({_id: 'test.user'});
assert.eq(2, configDB.chunks.count({ns: 'test.user'}));
assert.eq(1, configDB.tags.count({ns: 'test.user'}));
assert.commandWorked(testDB.runCommand({drop: 'user'}));
assert.eq(null, st.shard0.getDB('test').user.findOne());
assert.eq(null, st.shard1.getDB('test').user.findOne());
// Call drop again to verify that the command is idempotent.
assert.commandWorked(testDB.runCommand({drop: 'user'}));
// Check for the collection with majority RC to verify that the write to remove the collection
// document from the catalog has propagated to the majority snapshot. Note that here we explicitly
// use a command instead of going through the driver's 'find' helper, in order to be able to specify
// a 'majority' read concern.
//
// TODO (SERVER-51881): Remove this check after 5.0 is released
var collEntry =
assert
.commandWorked(configDB.runCommand(
{find: 'collections', filter: {_id: 'test.user'}, readConcern: {'level': 'majority'}}))
.cursor.firstBatch;
if (collEntry.length > 0) {
assert.eq(1, collEntry.length);
assert.eq(true, collEntry[0].dropped);
}
assert.eq(0, configDB.chunks.count({ns: 'test.user'}));
assert.eq(0, configDB.tags.count({ns: 'test.user'}));
st.stop();
})();
|