diff options
author | Judah Schvimer <judah@mongodb.com> | 2017-09-13 11:36:22 -0400 |
---|---|---|
committer | Judah Schvimer <judah@mongodb.com> | 2017-10-05 10:21:29 -0400 |
commit | 76695d7e64934b8d26948c701c77658818200a5e (patch) | |
tree | 4086b705c26bd5313bdbd33b13ca3453fa9aab2a /src | |
parent | ecf73def6797d9d61472a5c800b41e98803023f5 (diff) | |
download | mongo-76695d7e64934b8d26948c701c77658818200a5e.tar.gz |
SERVER-29772 Add allowUnsafeRenamesDuringInitialSync server parameter
(cherry picked from commit 76da39708f4d07ed0cf56d986d1c6f3d4353e670)
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/repl/oplog.cpp | 16 | ||||
-rw-r--r-- | src/mongo/db/repl/rs_initialsync.cpp | 15 |
2 files changed, 28 insertions, 3 deletions
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 2c764baf9e3..e642142d195 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -114,6 +114,11 @@ namespace { Database* _localDB = nullptr; Collection* _localOplogCollection = nullptr; +// Specifies whether we abort initial sync when attempting to apply a renameCollection operation. +// If set to true, users risk corrupting their data. This should only be enabled by expert users +// of the server who understand the risks this poses. +MONGO_EXPORT_SERVER_PARAMETER(allowUnsafeRenamesDuringInitialSync, bool, false); + PseudoRandom hashGenerator(std::unique_ptr<SecureRandom>(SecureRandom::create())->nextInt64()); // Synchronizes the section where a new Timestamp is generated and when it actually @@ -975,9 +980,14 @@ Status applyCommand_inlock(OperationContext* txn, // Applying renameCollection during initial sync might lead to data corruption, so we restart // the initial sync. if (!inSteadyStateReplication && o.firstElementFieldName() == std::string("renameCollection")) { - return Status(ErrorCodes::OplogOperationUnsupported, - str::stream() - << "Applying renameCollection not supported in initial sync: " << op); + if (!allowUnsafeRenamesDuringInitialSync.load()) { + return Status(ErrorCodes::OplogOperationUnsupported, + str::stream() + << "Applying renameCollection not supported in initial sync: " << op); + } + warning() << "allowUnsafeRenamesDuringInitialSync set to true. Applying renameCollection " + "operation during initial sync even though it may lead to data corruption: " + << op; } // Applying commands in repl is done under Global W-lock, so it is safe to not diff --git a/src/mongo/db/repl/rs_initialsync.cpp b/src/mongo/db/repl/rs_initialsync.cpp index d475d53d644..ecaea8fcbc4 100644 --- a/src/mongo/db/repl/rs_initialsync.cpp +++ b/src/mongo/db/repl/rs_initialsync.cpp @@ -69,6 +69,10 @@ using std::string; // Failpoint which fails initial sync and leaves on oplog entry in the buffer. MONGO_FP_DECLARE(failInitSyncWithBufferedEntriesLeft); +// Failpoint which causes the initial sync function to hang before copying databases. +MONGO_FP_DECLARE(initialSyncHangBeforeCopyingDatabases); + + /** * Truncates the oplog (removes any documents) and resets internal variables that were * originally initialized or affected by using values from the oplog at startup time. These @@ -346,6 +350,15 @@ Status _initialSync() { log() << "initial sync clone all databases"; + if (MONGO_FAIL_POINT(initialSyncHangBeforeCopyingDatabases)) { + // This log output is used in js tests so please leave it. + log() << "initial sync - initialSyncHangBeforeCopyingDatabases fail point " + "enabled. Blocking until fail point is disabled."; + while (MONGO_FAIL_POINT(initialSyncHangBeforeCopyingDatabases) && !inShutdown()) { + mongo::sleepsecs(1); + } + } + list<string> dbs = r.conn()->getDatabaseNames(); { // Clone admin database first, to catch schema errors. @@ -511,6 +524,8 @@ void syncDoInitialSync() { severe() << "The maximum number of retries have been exhausted for initial sync."; fassertFailedNoTrace(16233); } + + log() << "initial sync succeeded after " << (failedAttempts + 1) << " attempt(s)."; } } // namespace repl |