blob: 7a957df026952fe4bc2242fd687ab5749a2207a1 (
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
70
71
72
73
74
75
76
77
78
79
80
|
/**
* Test to ensure that using applyOps to rename a drop-pending collection is a no-op. The collection
* remains in a drop-pending state. This is the same behavior as renaming a non-existent collection.
*/
(function() {
"use strict";
load("jstests/replsets/libs/two_phase_drops.js"); // For TwoPhaseDropCollectionTest.
// Set up a two phase drop test.
let testName = "drop_collection_two_phase_apply_ops_rename";
let dbName = testName;
let collName = "collToDrop";
let twoPhaseDropTest = new TwoPhaseDropCollectionTest(testName, dbName);
// Initialize replica set.
let replTest = twoPhaseDropTest.initReplSet();
// Check for 'system.drop' two phase drop support.
if (!twoPhaseDropTest.supportsDropPendingNamespaces()) {
jsTestLog('Drop pending namespaces not supported by storage engine. Skipping test.');
twoPhaseDropTest.stop();
return;
}
// Create the collection that will be dropped.
twoPhaseDropTest.createCollection(collName);
// PREPARE collection drop.
twoPhaseDropTest.prepareDropCollection(collName);
try {
// Rename drop-pending collection using applyOps with system.drop namespace.
const dropPendingColl = twoPhaseDropTest.collectionIsPendingDrop(collName);
const dropPendingCollName = dropPendingColl.name;
const primary = replTest.getPrimary();
const cmdNs = dbName + '.$cmd';
const sourceNs = dbName + '.' + dropPendingCollName;
const destNs = dbName + '.bar';
const applyOpsCmdWithName = {
applyOps: [{op: 'c', ns: cmdNs, o: {renameCollection: sourceNs, to: destNs}}]
};
TwoPhaseDropCollectionTest._testLog(
'Attempting to rename collection using applyOps with system.drop namespace: ' +
tojson(applyOpsCmdWithName));
assert.commandWorked(primary.adminCommand(applyOpsCmdWithName));
assert(twoPhaseDropTest.collectionIsPendingDrop(collName),
'applyOps using collection name ' + dropPendingCollName +
' renamed drop-pending collection unexpectedly');
assert(!twoPhaseDropTest.collectionExists(collName));
// Rename drop-pending collection using applyOps with UUID.
const dropPendingCollUuid = dropPendingColl.info.uuid;
const applyOpsCmdWithUuid = {
applyOps: [{
op: 'c',
ns: cmdNs,
ui: dropPendingCollUuid,
o: {renameCollection: dbName + '.ignored_collection_name', to: destNs}
}]
};
TwoPhaseDropCollectionTest._testLog(
'Attempting to rename collection using applyOps with UUID: ' + tojson(applyOpsCmdWithUuid));
assert.commandWorked(primary.adminCommand(applyOpsCmdWithUuid));
const dropPendingCollInfo = twoPhaseDropTest.collectionIsPendingDrop(collName);
assert(dropPendingCollInfo,
'applyOps using UUID ' + dropPendingCollUuid +
' renamed drop-pending collection unexpectedly');
assert.eq(dropPendingCollUuid.hex(),
dropPendingCollInfo.info.uuid.hex(),
'drop pending collection UUID does not match UUID of original collection: ' +
tojson(dropPendingCollInfo));
// COMMIT collection drop.
twoPhaseDropTest.commitDropCollection(collName);
} finally {
twoPhaseDropTest.stop();
}
}());
|