Skip to content

Commit b1bd366

Browse files
haleyConnellyevergreen
authored andcommitted
SERVER-43752 Fix prepare_conflict.js log check
1 parent 95b038c commit b1bd366

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

jstests/core/txns/prepare_conflict.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ const dbName = "test";
1212
const collName = "prepare_conflict";
1313
const testDB = db.getSiblingDB(dbName);
1414
const testColl = testDB.getCollection(collName);
15-
16-
// Logs must be cleared each run.
17-
assert.commandWorked(testDB.adminCommand({clearLog: "global"}));
15+
const prepareConflictDurationLogMsg = "prepareConflictDuration";
1816

1917
testColl.drop({writeConcern: {w: "majority"}});
2018
assert.commandWorked(testDB.runCommand({create: collName, writeConcern: {w: "majority"}}));
2119

22-
function assertPrepareConflict(filter, clusterTime, count) {
20+
/**
21+
* Asserts that a prepare read conflict occurs, and is recorded through the profiler and logs
22+
* accordingly, by running a find command that uses the provided filter and clusterTime.
23+
*/
24+
const assertPrepareConflict = function assertPrepareReadConflict(filter, clusterTime) {
25+
assert.commandWorked(testDB.adminCommand({clearLog: "global"}));
26+
2327
// Uses a 5 second timeout so that there is enough time for the prepared transaction to
2428
// release its locks and for the command to obtain those locks.
2529
assert.commandFailedWithCode(
@@ -32,8 +36,7 @@ function assertPrepareConflict(filter, clusterTime, count) {
3236
}),
3337
ErrorCodes.MaxTimeMSExpired);
3438

35-
// Ensures prepareConflictDuration is logged each time a prepare conflict is encountered.
36-
checkLog.containsWithCount(testDB, "prepareConflictDuration", count);
39+
checkLog.contains(testDB, prepareConflictDurationLogMsg);
3740

3841
let prepareConflicted = false;
3942
const cur =
@@ -46,15 +49,15 @@ function assertPrepareConflict(filter, clusterTime, count) {
4649
}
4750
}
4851
assert(prepareConflicted);
49-
}
52+
};
5053

51-
// Inserts a document modified by the transaction.
54+
// Insert a document modified by the transaction.
5255
const txnDoc = {
5356
_id: 1,
5457
x: 1
5558
};
5659
assert.commandWorked(testColl.insert(txnDoc));
57-
// Inserts a document unmodified by the transaction.
60+
// Insert a document unmodified by the transaction.
5861
const otherDoc = {
5962
_id: 2,
6063
y: 2
@@ -77,24 +80,21 @@ assert.commandWorked(sessionDB.runCommand({
7780
}));
7881
const prepareTimestamp = PrepareHelpers.prepareTransaction(session);
7982

80-
// Stores the number of times prepareConflictDuration should appear in the log.
81-
let conflictCount = 1;
82-
8383
// Conflict on _id of prepared document.
84-
assertPrepareConflict({_id: txnDoc._id}, prepareTimestamp, conflictCount);
84+
assertPrepareConflict({_id: txnDoc._id}, prepareTimestamp);
8585

8686
// Conflict on field that could be added to a prepared document.
87-
assertPrepareConflict({randomField: "random"}, prepareTimestamp, ++conflictCount);
87+
assertPrepareConflict({randomField: "random"}, prepareTimestamp);
8888

8989
// No conflict on _id of a non-prepared document.
90+
assert.commandWorked(testDB.adminCommand({clearLog: "global"}));
9091
assert.commandWorked(testDB.runCommand({find: collName, filter: {_id: otherDoc._id}}));
92+
assert.eq(false, checkLog.checkContainsOnce(testDB, prepareConflictDurationLogMsg));
9193

9294
// No conflict on indexed field of a non-prepared document.
95+
assert.commandWorked(testDB.adminCommand({clearLog: "global"}));
9396
assert.commandWorked(testDB.runCommand({find: collName, filter: {y: otherDoc.y}}));
94-
95-
// Ensures that prepareConflictDuration is only logged when a prepare conflict is encountered. We
96-
// expect conflictCount to be 2.
97-
checkLog.containsWithCount(testDB, "prepareConflictDuration", conflictCount);
97+
assert.eq(false, checkLog.checkContainsOnce(testDB, prepareConflictDurationLogMsg));
9898

9999
// At this point, we can guarantee all subsequent reads will conflict. Do a read in a parallel
100100
// shell, abort the transaction, then ensure the read succeeded with the old document.
@@ -105,7 +105,6 @@ const findAwait = startParallelShell(function() {
105105
const it = db.getSiblingDB(TestData.dbName)
106106
.runCommand({find: TestData.collName, filter: {_id: TestData.txnDoc._id}});
107107
}, db.getMongo().port);
108-
109108
assert.commandWorked(session.abortTransaction_forTesting());
110109

111110
// The find command should be successful.

0 commit comments

Comments
 (0)