blob: d246098f8fe222d16d9e33582831fbe8b93562db (
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
|
/**
* Test that initial sync can reconstruct a prepared transaction that includes a write that
* sets the multikey flag.
*
* @tags: [
* # Multiversion testing does not support tests that kill and restart nodes.
* multiversion_incompatible,
* requires_persistence,
* uses_prepare_transaction,
* uses_transactions,
* ]
*/
(function() {
"use strict";
load("jstests/core/txns/libs/prepare_helpers.js");
const rst = new ReplSetTest({nodes: 1});
rst.startSet();
rst.initiate();
let primary = rst.getPrimary();
const primaryDB = primary.getDB("test");
const session = primaryDB.getMongo().startSession();
const sessionDB = session.getDatabase("test");
const sessionColl = sessionDB.getCollection("coll");
// Create an index that will later be made multikey.
sessionColl.createIndex({x: 1});
session.startTransaction();
// Make the index multikey.
jsTestLog("Making the index multikey.");
sessionColl.insert({x: [1, 2, 3]});
let prepareTimestamp = PrepareHelpers.prepareTransaction(session);
jsTestLog("Doing another write outside of transaction.");
assert.commandWorked(primaryDB.runCommand({insert: "coll", documents: [{x: 4}]}));
jsTestLog("Adding a secondary node to do the initial sync.");
rst.add();
jsTestLog("Re-initiating replica set with the new secondary.");
rst.reInitiate();
// Wait until initial sync completes.
jsTestLog("Waiting until initial sync completes.");
rst.awaitSecondaryNodes();
rst.awaitReplication();
jsTestLog("Committing the prepared transaction.");
assert.commandWorked(PrepareHelpers.commitTransaction(session, prepareTimestamp));
rst.stopSet();
}());
|