blob: 44f58126ea914c1688edfa738fc5c1633c263389 (
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
|
/**
* Tests that duplicate keys can still be inserted during the index build with the 'prepareUnique'
* option.
*
* @tags: [
* requires_replication,
* ]
*/
(function() {
"use strict";
load('jstests/libs/fail_point_util.js');
load("jstests/noPassthrough/libs/index_build.js");
const rst = new ReplSetTest({nodes: 1});
rst.startSet();
rst.initiate();
const dbName = "test";
const collName = "index_build_prepareUnique";
const primary = rst.getPrimary();
const db = primary.getDB(dbName);
assert.commandWorked(db.createCollection(collName));
const coll = db.getCollection(collName);
assert.commandWorked(coll.insert({a: 123}));
// Waits after the side write tracker is installed.
const fp = configureFailPoint(primary, "hangAfterSettingUpIndexBuild");
const awaitIndexBuild =
IndexBuildTest.startIndexBuild(primary, coll.getFullName(), {a: 1}, {prepareUnique: true});
fp.wait();
// Inserts the document with the duplicate key.
assert.commandWorked(coll.insert({a: 123}));
fp.off();
awaitIndexBuild();
// Confirms the index has duplicate keys and cannot be converted to unique.
assert.commandFailedWithCode(
db.runCommand({collMod: collName, index: {keyPattern: {a: 1}, unique: true}}),
ErrorCodes.CannotConvertIndexToUnique);
rst.stopSet();
}());
|