0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

SERVER-33343 move test functions from transaction_table_oplog_reply.js to retryable_writes_util.js for reuse

This commit is contained in:
Benety Goh 2018-04-04 13:47:34 -04:00
parent 4c42865f84
commit c04aa22602
2 changed files with 41 additions and 33 deletions

View File

@ -30,5 +30,37 @@ var RetryableWritesUtil = (function() {
return !kStorageEnginesWithoutDocumentLocking.has(storageEngineName);
}
return {isRetryableCode, isRetryableWriteCmdName, storageEngineSupportsRetryableWrites};
/**
* Asserts the connection has a document in its transaction collection that has the given
* sessionId, txnNumber, and lastWriteOptimeTs.
*/
function checkTransactionTable(conn, lsid, txnNumber, ts) {
let table = conn.getDB("config").transactions;
let res = table.findOne({"_id.id": lsid.id});
assert.eq(res.txnNum, txnNumber);
assert.eq(res.lastWriteOpTime.ts, ts);
}
/**
* Asserts the transaction collection document for the given session id is the same on both
* connections.
*/
function assertSameRecordOnBothConnections(primary, secondary, lsid) {
let primaryRecord = primary.getDB("config").transactions.findOne({"_id.id": lsid.id});
let secondaryRecord = secondary.getDB("config").transactions.findOne({"_id.id": lsid.id});
assert.eq(bsonWoCompare(primaryRecord, secondaryRecord),
0,
"expected transaction records: " + tojson(primaryRecord) + " and " +
tojson(secondaryRecord) + " to be the same for lsid: " + tojson(lsid));
}
return {
isRetryableCode,
isRetryableWriteCmdName,
storageEngineSupportsRetryableWrites,
checkTransactionTable,
assertSameRecordOnBothConnections,
};
})();

View File

@ -11,32 +11,6 @@
return;
}
/**
* Asserts the connection has a document in its transaction collection that has the given
* sessionId, txnNumber, and lastWriteOptimeTs.
*/
function checkTransactionTable(conn, lsid, txnNumber, ts) {
let table = conn.getDB("config").transactions;
let res = table.findOne({"_id.id": lsid.id});
assert.eq(res.txnNum, txnNumber);
assert.eq(res.lastWriteOpTime.ts, ts);
}
/**
* Asserts the transaction collection document for the given session id is the same on both
* connections.
*/
function assertSameRecordOnBothConnections(primary, secondary, lsid) {
let primaryRecord = primary.getDB("config").transactions.findOne({"_id.id": lsid.id});
let secondaryRecord = secondary.getDB("config").transactions.findOne({"_id.id": lsid.id});
assert.eq(bsonWoCompare(primaryRecord, secondaryRecord),
0,
"expected transaction records: " + tojson(primaryRecord) + " and " +
tojson(secondaryRecord) + " to be the same for lsid: " + tojson(lsid));
}
/**
* Runs each command on the primary, awaits replication then asserts the secondary's transaction
* collection has been updated to store the latest txnNumber and lastWriteOpTimeTs for each
@ -51,7 +25,7 @@
let res = assert.commandWorked(primary.getDB("test").runCommand(cmd));
let opTime = (res.opTime.ts ? res.opTime.ts : res.opTime);
checkTransactionTable(primary, cmd.lsid, cmd.txnNumber, opTime);
RetryableWritesUtil.checkTransactionTable(primary, cmd.lsid, cmd.txnNumber, opTime);
responseTimestamps.push(opTime);
});
@ -59,12 +33,13 @@
secondary.adminCommand({configureFailPoint: "rsSyncApplyStop", mode: "off"});
replTest.awaitReplication();
cmds.forEach(function(cmd, i) {
checkTransactionTable(secondary, cmd.lsid, cmd.txnNumber, responseTimestamps[i]);
RetryableWritesUtil.checkTransactionTable(
secondary, cmd.lsid, cmd.txnNumber, responseTimestamps[i]);
});
// Both nodes should have the same transaction collection record for each sessionId.
cmds.forEach(function(cmd) {
assertSameRecordOnBothConnections(primary, secondary, cmd.lsid);
RetryableWritesUtil.assertSameRecordOnBothConnections(primary, secondary, cmd.lsid);
});
}
@ -83,7 +58,7 @@
let res = assert.commandWorked(primary.getDB("test").runCommand(cmd));
let opTime = (res.opTime.ts ? res.opTime.ts : res.opTime);
checkTransactionTable(primary, cmd.lsid, cmd.txnNumber, opTime);
RetryableWritesUtil.checkTransactionTable(primary, cmd.lsid, cmd.txnNumber, opTime);
latestOpTimeTs = opTime;
highestTxnNumber =
(cmd.txnNumber > highestTxnNumber ? cmd.txnNumber : highestTxnNumber);
@ -93,10 +68,11 @@
// highest transaction number and the latest write optime.
secondary.adminCommand({configureFailPoint: "rsSyncApplyStop", mode: "off"});
replTest.awaitReplication();
checkTransactionTable(secondary, cmds[0].lsid, highestTxnNumber, latestOpTimeTs);
RetryableWritesUtil.checkTransactionTable(
secondary, cmds[0].lsid, highestTxnNumber, latestOpTimeTs);
// Both nodes should have the same transaction collection record for the sessionId.
assertSameRecordOnBothConnections(primary, secondary, cmds[0].lsid);
RetryableWritesUtil.assertSameRecordOnBothConnections(primary, secondary, cmds[0].lsid);
}
const replTest = new ReplSetTest({nodes: 2});