blob: 858f268a76b96a60e6927404bf032676e8f4fde5 (
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
|
/**
* Test to ensure that index creation fails on a drop-pending collection.
*/
(function() {
"use strict";
load("jstests/libs/fail_point_util.js"); // For kDefaultWaitForFailPointTimeout.
load("jstests/noPassthrough/libs/index_build.js"); // For IndexBuildTest.
load("jstests/replsets/libs/two_phase_drops.js"); // For TwoPhaseDropCollectionTest.
// Set up a two phase drop test.
let testName = "drop_collection_two_phase";
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;
}
const primary = replTest.getPrimary();
const testDB = primary.getDB(dbName);
const coll = testDB.getCollection(collName);
// Create the collection that will be dropped.
twoPhaseDropTest.createCollection(collName);
// Avoid empty collection optimization for index builds.
assert.commandWorked(coll.insert({a: 1}));
// We do not expect index builds to be able to add entries to the catalog for a drop-pending
// collection. Therefore, this should have no effect unless the index build somehow gets past the
// drop-pending namespace check.
IndexBuildTest.pauseIndexBuilds(primary);
// Pause createIndexes command before it adds the index to the catalog.
const createIndexesFailPoint =
configureFailPoint(primary, 'hangCreateIndexesBeforeStartingIndexBuild');
const createIdx = IndexBuildTest.startIndexBuild(primary, coll.getFullName(), {a: 1});
try {
createIndexesFailPoint.wait(30 * 1000);
// PREPARE collection drop.
twoPhaseDropTest.prepareDropCollection(collName);
// The IndexBuildsCoordinator will not proceed with the index build on the drop-pending
// collection and fail with a NamespaceNotFound error. The createIndexes command will ignore
// this error and return success to the caller. This is consistent with the current treatment
// for index builds on dropped collections.
createIndexesFailPoint.off();
createIdx();
// COMMIT collection drop.
twoPhaseDropTest.commitDropCollection(collName);
} finally {
createIndexesFailPoint.off();
IndexBuildTest.resumeIndexBuilds(primary);
}
twoPhaseDropTest.stop();
}());
|