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
|
/**
* This tests that writes with majority write concern will wait for at least the all durable
* timestamp to reach the timestamp of the write. This guarantees that once a write is majority
* committed, reading at the all durable timestamp will read that write.
*/
(function() {
"use strict";
load("jstests/libs/fail_point_util.js");
function assertWriteConcernTimeout(result) {
assert.writeErrorWithCode(result, ErrorCodes.WriteConcernFailed);
assert(result.hasWriteConcernError(), tojson(result));
assert(result.getWriteConcernError().errInfo.wtimeout, tojson(result));
}
const rst = new ReplSetTest({name: "writes_wait_for_all_durable", nodes: 1});
rst.startSet();
rst.initiate();
const primary = rst.getPrimary();
const dbName = "test";
const collName = "majority_writes_wait_for_all_durable";
const testDB = primary.getDB(dbName);
const testColl = testDB[collName];
TestData.dbName = dbName;
TestData.collName = collName;
testDB.runCommand({drop: collName, writeConcern: {w: "majority"}});
assert.commandWorked(testDB.createCollection(collName, {writeConcern: {w: "majority"}}));
const failPoint = configureFailPoint(
testDB, "hangAfterCollectionInserts", {collectionNS: testColl.getFullName(), first_id: "b"});
jsTestLog(
"Insert a document to hang before the insert completes to hold back the all durable timestamp.");
const joinHungWrite = startParallelShell(() => {
assert.commandWorked(db.getSiblingDB(TestData.dbName)[TestData.collName].insert({_id: "b"}));
}, primary.port);
jsTestLog("Checking that the log contains fail point enabled.");
failPoint.wait();
try {
jsTest.log("Do a write with majority write concern that should time out.");
// Note: we must use {j: false} otherwise the command can hang where writeConcern waits for no
// oplog holes, which currently does not obey wtimeout (SERVER-46191), before persistence on
// single voter replica set primaries.
assertWriteConcernTimeout(
testColl.insert({_id: 0}, {writeConcern: {w: "majority", j: false, wtimeout: 2 * 1000}}));
} finally {
failPoint.off();
}
joinHungWrite();
rst.stopSet();
})();
|