summaryrefslogtreecommitdiff
path: root/jstests/replsets/dbhash_read_at_cluster_time.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/replsets/dbhash_read_at_cluster_time.js')
-rw-r--r--jstests/replsets/dbhash_read_at_cluster_time.js92
1 files changed, 75 insertions, 17 deletions
diff --git a/jstests/replsets/dbhash_read_at_cluster_time.js b/jstests/replsets/dbhash_read_at_cluster_time.js
index e8c42b4e57f..99a4517f926 100644
--- a/jstests/replsets/dbhash_read_at_cluster_time.js
+++ b/jstests/replsets/dbhash_read_at_cluster_time.js
@@ -1,7 +1,8 @@
/**
- * Tests that "$_internalReadAtClusterTime" is supported by the "dbHash" command.
+ * Tests that "$_internalReadAtClusterTime" and "snapshot" level
+ * read concern are supported by the "dbHash" command.
*
- * @tags: [uses_transactions]
+ * @tags: [uses_transactions, requires_fcv_46, requires_majority_read_concern]
*/
(function() {
"use strict";
@@ -18,7 +19,6 @@ const secondary = rst.getSecondary();
const session = primary.startSession({causalConsistency: false});
const db = session.getDatabase("test");
-let txnNumber = 0;
// We prevent the replica set from advancing oldest_timestamp. This ensures that the snapshot
// associated with 'clusterTime' is retained for the duration of this test.
@@ -38,7 +38,17 @@ let res = assert.commandWorked(db.runCommand({
$_internalReadAtClusterTime: clusterTime,
}));
-const hash1 = {
+const internalAtClusterTimeHashBefore = {
+ collections: res.collections,
+ md5: res.md5
+};
+
+res = assert.commandWorked(db.runCommand({
+ dbHash: 1,
+ readConcern: {level: "snapshot", atClusterTime: clusterTime},
+}));
+
+const atClusterTimeHashBefore = {
collections: res.collections,
md5: res.md5
};
@@ -50,32 +60,65 @@ const hash1 = {
// on the secondary.
assert.commandWorked(db.mycoll.insert({_id: 2}, {writeConcern: {w: "majority"}}));
-// However, using $_internalReadAtClusterTime to read at the opTime of the first insert should
-// return the same md5sum as it did originally.
+// However, using $_internalReadAtClusterTime or snapshot read concern to read at the opTime of the
+// first insert should return the same md5sum as it did originally.
res = assert.commandWorked(db.runCommand({
dbHash: 1,
$_internalReadAtClusterTime: clusterTime,
}));
-const hash2 = {
+const internalAtClusterTimeHashAfter = {
collections: res.collections,
md5: res.md5
};
-assert.eq(hash1, hash2, "primary returned different dbhash after second insert");
+
+res = assert.commandWorked(db.runCommand({
+ dbHash: 1,
+ readConcern: {level: "snapshot", atClusterTime: clusterTime},
+}));
+
+const atClusterTimeHashAfter = {
+ collections: res.collections,
+ md5: res.md5
+};
+
+assert.eq(internalAtClusterTimeHashBefore,
+ internalAtClusterTimeHashAfter,
+ "primary returned different dbhash after " +
+ "second insert while using $_internalReadAtClusterTime");
+assert.eq(atClusterTimeHashBefore,
+ atClusterTimeHashAfter,
+ "primary returned different dbhash after " +
+ "second insert while using \"snapshot\" level read concern");
{
const secondarySession = secondary.startSession({causalConsistency: false});
const secondaryDB = secondarySession.getDatabase("test");
- // Using $_internalReadAtClusterTime to read at the opTime of the first insert should return
- // the same md5sum on the secondary as it did on the primary.
+ // Using $_internalReadAtClusterTime or snapshot read concern to read at the opTime
+ // of the first insert should return the same md5sum on the secondary as it did on the primary.
res = assert.commandWorked(secondaryDB.runCommand({
dbHash: 1,
$_internalReadAtClusterTime: clusterTime,
}));
- const secondaryHash = {collections: res.collections, md5: res.md5};
- assert.eq(hash1, secondaryHash, "primary and secondary have different dbhash");
+ const internalAtClusterTimeSecondaryHash = {collections: res.collections, md5: res.md5};
+
+ res = assert.commandWorked(secondaryDB.runCommand({
+ dbHash: 1,
+ readConcern: {level: "snapshot", atClusterTime: clusterTime},
+ }));
+
+ const atClusterTimeSecondaryHash = {collections: res.collections, md5: res.md5};
+
+ assert.eq(internalAtClusterTimeHashBefore,
+ internalAtClusterTimeSecondaryHash,
+ "primary and secondary have different dbhash " +
+ "while using $_internalReadAtClusterTime.");
+ assert.eq(atClusterTimeHashBefore,
+ atClusterTimeSecondaryHash,
+ "primary returned different dbhash " +
+ "while using \"snapshot\" level read concern");
}
{
@@ -88,19 +131,34 @@ assert.eq(hash1, hash2, "primary returned different dbhash after second insert")
assert.commandWorked(otherDB.mycoll.insert({_id: 3}));
// It should be possible to run the "dbHash" command with "$_internalReadAtClusterTime"
- // concurrently.
+ // or snapshot read concern concurrently.
res = assert.commandWorked(db.runCommand({
dbHash: 1,
$_internalReadAtClusterTime: clusterTime,
}));
- const hash3 = {collections: res.collections, md5: res.md5};
- assert.eq(hash1, hash3, "primary returned different dbhash after third insert");
+ const concurrentInternalAtClusterTimeHash = {collections: res.collections, md5: res.md5};
+
+ res = assert.commandWorked(db.runCommand({
+ dbHash: 1,
+ readConcern: {level: "snapshot", atClusterTime: clusterTime},
+ }));
+
+ const concurrentAtClusterTimeHash = {collections: res.collections, md5: res.md5};
+
+ assert.eq(internalAtClusterTimeHashBefore,
+ concurrentInternalAtClusterTimeHash,
+ "primary returned different dbhash after " +
+ "third insert while using $_internalReadAtClusterTime.");
+ assert.eq(atClusterTimeHashBefore,
+ concurrentAtClusterTimeHash,
+ "primary returned different dbhash after " +
+ "third insert while using \"snapshot\" level read concern");
// However, the "dbHash" command should block behind the transaction if
// "$_internalReadAtClusterTime" wasn't specified.
- res = assert.commandFailedWithCode(db.runCommand({dbHash: 1, maxTimeMS: 1000}),
- ErrorCodes.MaxTimeMSExpired);
+ assert.commandFailedWithCode(db.runCommand({dbHash: 1, maxTimeMS: 1000}),
+ ErrorCodes.MaxTimeMSExpired);
assert.commandWorked(otherSession.abortTransaction_forTesting());
otherSession.endSession();