diff options
author | Judah Schvimer <judah@mongodb.com> | 2020-07-15 17:23:47 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-07-15 20:25:45 +0000 |
commit | e0cde43310e5dab3fcf6e93bb115259e70a165e8 (patch) | |
tree | cf7ed72405549221e1d05dcf041722f784a30b9b | |
parent | 7f699ffd1710c027d3bade0257a7cd2821e9db28 (diff) | |
download | mongo-e0cde43310e5dab3fcf6e93bb115259e70a165e8.tar.gz |
SERVER-49527 recoverFromOplogAsStandalone does not relax index constraints
-rw-r--r-- | jstests/replsets/standalone_replication_recovery_relaxes_index_constaints.js | 61 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl.cpp | 3 |
2 files changed, 64 insertions, 0 deletions
diff --git a/jstests/replsets/standalone_replication_recovery_relaxes_index_constaints.js b/jstests/replsets/standalone_replication_recovery_relaxes_index_constaints.js new file mode 100644 index 00000000000..050a16ee9d0 --- /dev/null +++ b/jstests/replsets/standalone_replication_recovery_relaxes_index_constaints.js @@ -0,0 +1,61 @@ +/* + * Tests that 'recoverFromOplogAsStandalone' relaxes index constraints. This test is + * non-deterministic. If there were a bug, it would still succeed with low probability, but should + * never fail without a bug. + * + * This test only makes sense for storage engines that support recover to stable timestamp. + * @tags: [requires_wiredtiger, requires_persistence, requires_journaling, requires_replication, + * requires_majority_read_concern] + */ + +(function() { + "use strict"; + load("jstests/replsets/rslib.js"); + load("jstests/libs/write_concern_util.js"); + + const name = jsTestName(); + const dbName = name; + const collName = 'coll'; + const logLevel = tojson({storage: {recovery: 2}, replication: 3}); + + const rst = new ReplSetTest({ + nodes: 1, + }); + + function getColl(conn) { + return conn.getDB(dbName)[collName]; + } + + jsTestLog("Initiating as a replica set."); + rst.startSet(); + rst.initiate(); + let node = rst.getPrimary(); + + assert.commandWorked(getColl(node).insert({_id: 1}, {writeConcern: {w: 1, j: 1}})); + assert.commandWorked(getColl(node).createIndex({x: 1}, {unique: true})); + + jsTestLog("Running inserts and removes"); + const start = (new Date()).getTime(); + const waitTimeMillis = 5 * 1000; + const baseNum = 10; + let iter = 2; + Random.setRandomSeed(); + while (((new Date()).getTime() - start) < waitTimeMillis) { + iter++; + const uniqueKey = Math.floor(Random.rand() * baseNum); + assert.commandWorked(getColl(node).insert({_id: iter, x: uniqueKey})); + assert.commandWorked(getColl(node).remove({_id: iter})); + } + + jsTestLog("Kill the node"); + rst.stop(node, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL}); + + jsTestLog("Restart the node with 'recoverFromOplogAsStandalone'"); + node = rst.restart(node, { + noReplSet: true, + setParameter: {recoverFromOplogAsStandalone: true, logComponentVerbosity: logLevel} + }); + reconnect(node); + + rst.stopSet(); +})(); diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index 4fef050eb52..600a67934a6 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -2084,6 +2084,9 @@ bool ReplicationCoordinatorImpl::isInPrimaryOrSecondaryState() const { bool ReplicationCoordinatorImpl::shouldRelaxIndexConstraints(OperationContext* opCtx, const NamespaceString& ns) { + if (ReplSettings::shouldRecoverFromOplogAsStandalone()) { + return true; + } return !canAcceptWritesFor(opCtx, ns); } |