diff options
author | Matthew Russotto <matthew.russotto@10gen.com> | 2018-07-03 17:23:47 -0400 |
---|---|---|
committer | Matthew Russotto <matthew.russotto@10gen.com> | 2018-07-03 17:23:47 -0400 |
commit | 7c8d941c7f6904a65476ca91c6013067d2149fe8 (patch) | |
tree | dad323ec1bb1d1de96378dd636dbaeb1a9115189 /src/mongo/db/repl | |
parent | 5b8b8934c0007decb3d62915b1265f2dadfc9f4b (diff) | |
download | mongo-7c8d941c7f6904a65476ca91c6013067d2149fe8.tar.gz |
SERVER-34414 Create system indexes using the normal index creation and replication process.
Do not create them directly on secondaries.
Do create oplog entries for index creation.
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r-- | src/mongo/db/repl/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog.h | 4 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_test.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_external_state_impl.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/repl/sync_tail_test_fixture.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/repl/sync_tail_test_fixture.h | 3 |
7 files changed, 30 insertions, 7 deletions
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript index a1b502e935a..e9a4998db59 100644 --- a/src/mongo/db/repl/SConscript +++ b/src/mongo/db/repl/SConscript @@ -1576,6 +1576,7 @@ env.Library( '$BUILD_DIR/mongo/db/s/sharding_runtime_d', '$BUILD_DIR/mongo/db/service_context', '$BUILD_DIR/mongo/db/stats/counters', + '$BUILD_DIR/mongo/db/system_index', '$BUILD_DIR/mongo/rpc/client_metadata', '$BUILD_DIR/mongo/util/fail_point', 'bgsync', diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index a0d13182694..42f471bedd4 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -434,7 +434,8 @@ OpTime logOp(OperationContext* opCtx, const OperationSessionInfo& sessionInfo, StmtId statementId, const OplogLink& oplogLink, - bool prepare) { + bool prepare, + const OplogSlot& oplogSlot) { auto replCoord = ReplicationCoordinator::get(opCtx); // For commands, the test below is on the command ns and therefore does not check for // specific namespaces such as system.profile. This is the caller's responsibility. @@ -453,7 +454,11 @@ OpTime logOp(OperationContext* opCtx, OplogSlot slot; WriteUnitOfWork wuow(opCtx); - _getNextOpTimes(opCtx, oplog, 1, &slot); + if (oplogSlot.opTime.isNull()) { + _getNextOpTimes(opCtx, oplog, 1, &slot); + } else { + slot = oplogSlot; + } auto writer = _logOpWriter(opCtx, opstr, diff --git a/src/mongo/db/repl/oplog.h b/src/mongo/db/repl/oplog.h index b4d34ca0ef6..ef96a304626 100644 --- a/src/mongo/db/repl/oplog.h +++ b/src/mongo/db/repl/oplog.h @@ -127,6 +127,7 @@ std::vector<OpTime> logInsertOps(OperationContext* opCtx, * linked via prevTs, and the timestamps of the oplog entry that contains the document * before/after update was applied. The timestamps are ignored if isNull() is true. * prepare this specifies if the oplog entry should be put into a 'prepare' state. + * oplogSlot If non-null, use this reserved oplog slot instead of a new one. * * Returns the optime of the oplog entry written to the oplog. * Returns a null optime if oplog was not modified. @@ -142,7 +143,8 @@ OpTime logOp(OperationContext* opCtx, const OperationSessionInfo& sessionInfo, StmtId stmtId, const OplogLink& oplogLink, - bool prepare); + bool prepare, + const OplogSlot& oplogSlot); // Flush out the cached pointer to the oplog. // Used by the closeDatabase command to ensure we don't cache closed things. diff --git a/src/mongo/db/repl/oplog_test.cpp b/src/mongo/db/repl/oplog_test.cpp index 93738bb47ed..4f0de89c5f8 100644 --- a/src/mongo/db/repl/oplog_test.cpp +++ b/src/mongo/db/repl/oplog_test.cpp @@ -111,7 +111,8 @@ TEST_F(OplogTest, LogOpReturnsOpTimeOnSuccessfulInsertIntoOplogCollection) { {}, kUninitializedStmtId, {}, - false /* prepare */); + false /* prepare */, + OplogSlot()); ASSERT_FALSE(opTime.isNull()); wunit.commit(); } @@ -234,7 +235,8 @@ OpTime _logOpNoopWithMsg(OperationContext* opCtx, {}, kUninitializedStmtId, {}, - false /* prepare */); + false /* prepare */, + OplogSlot()); ASSERT_FALSE(opTime.isNull()); ASSERT(opTimeNssMap->find(opTime) == opTimeNssMap->end()) diff --git a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp index 139d23183ab..dfd54fb93f3 100644 --- a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp @@ -79,6 +79,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/session_catalog.h" #include "mongo/db/storage/storage_engine.h" +#include "mongo/db/system_index.h" #include "mongo/executor/network_connection_hook.h" #include "mongo/executor/network_interface.h" #include "mongo/executor/network_interface_factory.h" @@ -519,6 +520,16 @@ OpTime ReplicationCoordinatorExternalStateImpl::onTransitionToPrimary(OperationC _shardingOnTransitionToPrimaryHook(opCtx); _dropAllTempCollections(opCtx); + // It is only necessary to check the system indexes on the first transition to master. + // On subsequent transitions to master the indexes will have already been created. + static std::once_flag verifySystemIndexesOnce; + std::call_once(verifySystemIndexesOnce, [opCtx] { + const auto globalAuthzManager = AuthorizationManager::get(opCtx->getServiceContext()); + if (globalAuthzManager->shouldValidateAuthSchemaOnStartup()) { + fassert(65536, verifySystemIndexes(opCtx)); + } + }); + serverGlobalParams.validateFeaturesAsMaster.store(true); return opTimeToReturn; diff --git a/src/mongo/db/repl/sync_tail_test_fixture.cpp b/src/mongo/db/repl/sync_tail_test_fixture.cpp index dc1ed3dec95..3929aa5239d 100644 --- a/src/mongo/db/repl/sync_tail_test_fixture.cpp +++ b/src/mongo/db/repl/sync_tail_test_fixture.cpp @@ -78,7 +78,8 @@ void SyncTailOpObserver::onCreateCollection(OperationContext* opCtx, Collection* coll, const NamespaceString& collectionName, const CollectionOptions& options, - const BSONObj& idIndex) { + const BSONObj& idIndex, + const OplogSlot& createOpTime) { if (!onCreateCollectionFn) { return; } diff --git a/src/mongo/db/repl/sync_tail_test_fixture.h b/src/mongo/db/repl/sync_tail_test_fixture.h index cbbe56b94b5..4f483d26eb6 100644 --- a/src/mongo/db/repl/sync_tail_test_fixture.h +++ b/src/mongo/db/repl/sync_tail_test_fixture.h @@ -74,7 +74,8 @@ public: Collection* coll, const NamespaceString& collectionName, const CollectionOptions& options, - const BSONObj& idIndex) override; + const BSONObj& idIndex, + const OplogSlot& createOpTime) override; // Hooks for OpObserver functions. Defaults to a no-op function but may be overridden to check // actual documents mutated. |