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
|
/**
* Tests that the collMod command converting an index to unique fails if the index is modified
* between the lock acquisitions.
*
* @tags: [
* # TODO(SERVER-61181): Fix validation errors under ephemeralForTest.
* incompatible_with_eft,
* # TODO(SERVER-61182): Fix WiredTigerKVEngine::alterIdentMetadata() under inMemory.
* requires_fcv_60,
* requires_persistence,
* # Replication requires journaling support so this tag also implies exclusion from
* # --nojournal test configurations.
* requires_replication,
* ]
*/
(function() {
'use strict';
load('jstests/libs/fail_point_util.js');
load('jstests/libs/parallel_shell_helpers.js');
const rst = new ReplSetTest({nodes: 1});
rst.startSet();
rst.initiate();
const primary = rst.getPrimary();
const collModIndexUniqueEnabled =
assert.commandWorked(primary.adminCommand({getParameter: 1, featureFlagCollModIndexUnique: 1}))
.featureFlagCollModIndexUnique.value;
if (!collModIndexUniqueEnabled) {
jsTestLog('Skipping test because the collMod unique index feature flag is disabled');
rst.stopSet();
return;
}
const testDB = primary.getDB('test');
const collName = "collmod_convert_to_unique_locking";
const coll = testDB.getCollection(collName);
assert.commandWorked(coll.createIndex({a: 1}));
assert.commandWorked(coll.insert({a: 1}));
// Disallows new duplicate keys on the index.
assert.commandWorked(
testDB.runCommand({collMod: collName, index: {keyPattern: {a: 1}, prepareUnique: true}}));
let awaitCollMod = () => {};
const failPoint = configureFailPoint(
primary, 'hangAfterCollModIndexUniqueReleaseIXLock', {nss: coll.getFullName()});
// Attempts to run collMod to convert the index to unique during which the index is modified.
awaitCollMod = assertCommandFailedWithCodeInParallelShell(
primary,
testDB,
{collMod: collName, index: {keyPattern: {a: 1}, unique: true}},
ErrorCodes.CommandFailed);
failPoint.wait();
// Invalidates the index being converted to unique to fail the command.
assert.commandWorked(
testDB.runCommand({collMod: collName, index: {keyPattern: {a: 1}, hidden: true}}));
failPoint.off();
awaitCollMod();
// Reruns the collmod without the index being modified and succeeds.
assert.commandWorked(
testDB.runCommand({collMod: collName, index: {keyPattern: {a: 1}, unique: true}}));
rst.stopSet();
})();
|