0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/jstests/replsets/recover_prepared_txn_with_multikey_write.js
William Schultz 7d687264de SERVER-42251 Timestamp multikey writes with the prepare timestamp during replication recovery
Now that we execute multikey catalog updates in a side transaction, we need to give them some suitable timestamp. In normal replication, we can grab the latest value of the LogicalClock. In startup recovery, though, we may replay a prepared transaction that does a multikey write, but the LogicalClock may not have been initialized yet. Thus, we use the prepare timestamp of the transaction for the multikey write, since that timestamp is guaranteed to be less than or equal to the commit timestamp of the transaction.
2019-07-23 17:06:54 -04:00

44 lines
1.2 KiB
JavaScript

/**
* Test that replication recovery can reconstruct a prepared transaction that includes a write that
* sets the multikey flag.
*
* @tags: [uses_transactions, uses_prepare_transaction]
*/
(function() {
const rst = new ReplSetTest({
nodes: [
{},
{
// Disallow elections on secondary.
rsConfig: {
priority: 0,
votes: 0,
}
}
]
});
rst.startSet();
rst.initiate();
const primary = rst.getPrimary();
const session = primary.getDB("test").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.
sessionColl.insert({x: [1, 2, 3]});
assert.commandWorked(sessionDB.adminCommand({prepareTransaction: 1}));
// Do an unclean shutdown so we don't force a checkpoint, and then restart.
rst.stop(0, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
rst.restart(0);
rst.stopSet();
}());