diff options
author | Benety Goh <benety@mongodb.com> | 2017-09-06 13:16:29 -0400 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2017-09-06 13:17:49 -0400 |
commit | 456ba544978a0d41a2261bf65da686874fb631a2 (patch) | |
tree | 40e06df83c3ceefb96912f889cc94c915ac1c9b9 | |
parent | e3f3b1357bb2838140f6e9a42ff704237d68afbe (diff) | |
download | mongo-456ba544978a0d41a2261bf65da686874fb631a2.tar.gz |
SERVER-30381 Remove handing for rolling back dropSource collections
-rw-r--r-- | src/mongo/db/repl/rs_rollback.cpp | 44 | ||||
-rw-r--r-- | src/mongo/db/repl/rs_rollback.h | 14 | ||||
-rw-r--r-- | src/mongo/db/repl/rs_rollback_test.cpp | 169 |
3 files changed, 1 insertions, 226 deletions
diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp index 7f7eb82bb06..8795ec17db5 100644 --- a/src/mongo/db/repl/rs_rollback.cpp +++ b/src/mongo/db/repl/rs_rollback.cpp @@ -185,35 +185,6 @@ Status FixUpInfo::recordDropTargetInfo(const BSONElement& dropTarget, return Status::OK(); } -Status FixUpInfo::recordCrossDatabaseRenameRollbackInfo(const BSONElement& dropSource, - const BSONObj& obj, - const NamespaceString& nss, - UUID uuid, - OpTime opTime) { - - StatusWith<UUID> uuidWithStatus = UUID::parse(dropSource); - if (!uuidWithStatus.isOK()) { - std::string message = str::stream() - << "Unable to roll back cross database renameCollection. Cannot parse " - << "dropSource UUID. Returned status: " << redact(uuidWithStatus.getStatus()) - << ", oplog entry: " << redact(obj); - error() << message; - return uuidWithStatus.getStatus(); - } - UUID dropSourceUUID = uuidWithStatus.getValue(); - - // If a cross-database rename has occurred, we record it as separate - // createCollection and dropCollection commands. First, we record the - // necessary information for the source collection to be un-dropped. - recordRollingBackDrop(nss, opTime, dropSourceUUID); - - // Next, we need to drop the new collection that was created due to the rename. - // Dropping this collection will effectively drop all the documents inserted into - // the collection, rolling back the copy portion of the renameCollection command. - collectionsToDrop.insert(uuid); - return Status::OK(); -} - Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(FixUpInfo& fixUpInfo, const BSONObj& ourObj) { @@ -399,13 +370,10 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(FixUpInfo& fixUpInf // to: "foo.y", // stayTemp: false, // dropTarget: BinData(...), - // dropSource: BinData(...), // } // dropTarget will be false if no collection is dropped during the rename. - // dropSource is only present during a cross-database rename, and contains - // the UUID of the collection that is being renamed over. The ui field will - // contain the UUID of the new collection that is created. + // The ui field will contain the UUID of the new collection that is created. BSONObj cmd = obj; @@ -429,16 +397,6 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(FixUpInfo& fixUpInf } } - // Checks if the renameCollection is a cross-database rename. If the dropSource - // field is present in the oplog entry then the renameCollection must be a - // cross-database rename. The field will be absent in renames in the same - // database. - auto dropSource = obj.getField("dropSource"); - if (!dropSource.eoo()) { - return fixUpInfo.recordCrossDatabaseRenameRollbackInfo( - dropSource, obj, NamespaceString(ns), *uuid, oplogEntry.getOpTime()); - } - RenameCollectionInfo info; info.renameTo = NamespaceString(ns); info.renameFrom = NamespaceString(obj.getStringField("to")); diff --git a/src/mongo/db/repl/rs_rollback.h b/src/mongo/db/repl/rs_rollback.h index d4e4015f279..d3722c39ed9 100644 --- a/src/mongo/db/repl/rs_rollback.h +++ b/src/mongo/db/repl/rs_rollback.h @@ -335,20 +335,6 @@ struct FixUpInfo { * and collectionsToRename by calling recordRollingBackDrop(). */ Status recordDropTargetInfo(const BSONElement& dropTarget, const BSONObj& obj, OpTime opTime); - - /** - * This function handles adding the necessary information into the fixUpInfo struct to - * roll back cross database renames. We handle cross database renames differently from - * within database renames. We add the collection that was created during the renameCollection - * to collectionsToDrop, and add the source collection that was dropped into - * collectionsToRemoveFromDropPendingCollections and collectionsToRename by calling - * recordRollingBackDrop(). We handle the dropTarget in the rename in a separate step. - */ - Status recordCrossDatabaseRenameRollbackInfo(const BSONElement& dropSource, - const BSONObj& obj, - const NamespaceString& nss, - UUID uuid, - OpTime opTime); }; // Indicates that rollback cannot complete and the server must abort. diff --git a/src/mongo/db/repl/rs_rollback_test.cpp b/src/mongo/db/repl/rs_rollback_test.cpp index 62fbecbf7f5..acddacb2ca6 100644 --- a/src/mongo/db/repl/rs_rollback_test.cpp +++ b/src/mongo/db/repl/rs_rollback_test.cpp @@ -208,7 +208,6 @@ OplogInterfaceMock::Operation makeRenameCollectionOplogEntry(const NamespaceStri const NamespaceString& renameTo, const UUID collectionUUID, OptionalCollectionUUID dropTarget, - OptionalCollectionUUID dropSource, const bool stayTemp, OpTime opTime) { BSONObjBuilder cmd; @@ -223,10 +222,6 @@ OplogInterfaceMock::Operation makeRenameCollectionOplogEntry(const NamespaceStri } else { obj = obj.addField(BSON("dropTarget" << false).firstElement()); } - if (dropSource) { - obj = obj.addField(BSON("dropSource" << *dropSource).firstElement()); - } - return std::make_pair( BSON("ts" << opTime.getTimestamp() << "t" << opTime.getTerm() << "h" << 1LL << "op" << "c" @@ -946,7 +941,6 @@ TEST_F(RSRollbackTest, RollbackRenameCollectionInSameDatabaseCommand) { NamespaceString("test.y"), collectionUUID, boost::none, - boost::none, false, renameTime); @@ -1011,7 +1005,6 @@ TEST_F(RSRollbackTest, NamespaceString(renameToNss), collectionUUID, boost::none, - boost::none, stayTemp, OpTime(Timestamp(2, 0), 5)); @@ -1057,7 +1050,6 @@ TEST_F(RSRollbackTest, RollbackRenameCollectionInDatabaseWithDropTargetTrueComma NamespaceString("test.y"), renamedCollectionUUID, droppedCollectionUUID, - boost::none, false, dropTime); @@ -1114,7 +1106,6 @@ TEST_F(RSRollbackTest, RollbackRenamingCollectionsToEachOther) { NamespaceString("test.z"), collection1UUID, boost::none, - boost::none, false, OpTime(Timestamp(2, 0), 5)); @@ -1122,7 +1113,6 @@ TEST_F(RSRollbackTest, RollbackRenamingCollectionsToEachOther) { NamespaceString("test.x"), collection2UUID, boost::none, - boost::none, false, OpTime(Timestamp(3, 0), 5)); @@ -1130,7 +1120,6 @@ TEST_F(RSRollbackTest, RollbackRenamingCollectionsToEachOther) { NamespaceString("test.y"), collection1UUID, boost::none, - boost::none, false, OpTime(Timestamp(4, 0), 5)); @@ -1196,7 +1185,6 @@ TEST_F(RSRollbackTest, RollbackDropCollectionThenRenameCollectionToDroppedCollec NamespaceString("test.x"), renamedCollectionUUID, boost::none, - boost::none, false, OpTime(Timestamp(3, 0), 5)); @@ -1254,7 +1242,6 @@ TEST_F(RSRollbackTest, RollbackRenameCollectionThenCreateNewCollectionWithOldNam NamespaceString("test.y"), renamedCollectionUUID, boost::none, - boost::none, false, OpTime(Timestamp(2, 0), 5)); @@ -1300,162 +1287,6 @@ TEST_F(RSRollbackTest, RollbackRenameCollectionThenCreateNewCollectionWithOldNam } } -TEST_F(RSRollbackTest, RollbackRenameCollectionAcrossDatabases) { - createOplog(_opCtx.get()); - CollectionOptions options; - options.uuid = UUID::gen(); - auto collection = _createCollection(_opCtx.get(), "foo.t", options); - auto renamedCollectionUUID = collection->uuid().get(); - - OpTime dropTime = OpTime(Timestamp(2, 0), 5); - auto dpSourceNs = NamespaceString("test.t").makeDropPendingNamespace(dropTime); - CollectionOptions dpSourceOptions; - dpSourceOptions.uuid = UUID::gen(); - auto droppedSource = _createCollection(_opCtx.get(), dpSourceNs, dpSourceOptions); - _dropPendingCollectionReaper->addDropPendingNamespace(dropTime, dpSourceNs); - auto droppedSourceUUID = droppedSource->uuid().get(); - - auto dpTargetNs = NamespaceString("foo.t").makeDropPendingNamespace(dropTime); - CollectionOptions dpTargetOptions; - dpTargetOptions.uuid = UUID::gen(); - auto droppedTarget = _createCollection(_opCtx.get(), dpTargetNs, dpTargetOptions); - _dropPendingCollectionReaper->addDropPendingNamespace(dropTime, dpTargetNs); - auto droppedTargetUUID = droppedTarget->uuid().get(); - - auto commonOperation = - std::make_pair(BSON("ts" << Timestamp(Seconds(1), 0) << "h" << 1LL), RecordId(1)); - - auto renameCollectionOperation = makeRenameCollectionOplogEntry(NamespaceString("test.t"), - NamespaceString("foo.t"), - renamedCollectionUUID, - droppedTargetUUID, - droppedSourceUUID, - false, - dropTime); - RollbackSourceMock rollbackSource(std::unique_ptr<OplogInterface>(new OplogInterfaceMock({ - commonOperation, - }))); - - { - AutoGetCollectionForReadCommand autoDropSource(_opCtx.get(), dpSourceNs); - ASSERT_TRUE(autoDropSource.getCollection()); - AutoGetCollectionForReadCommand autoDropTarget(_opCtx.get(), dpTargetNs); - ASSERT_TRUE(autoDropTarget.getCollection()); - AutoGetCollectionForReadCommand renamedColl(_opCtx.get(), NamespaceString("foo.t")); - ASSERT_TRUE(renamedColl.getCollection()); - AutoGetCollectionForReadCommand droppedColl(_opCtx.get(), NamespaceString("test.t")); - ASSERT_FALSE(droppedColl.getCollection()); - } - ASSERT_OK(syncRollback(_opCtx.get(), - OplogInterfaceMock({renameCollectionOperation, commonOperation}), - rollbackSource, - {}, - _coordinator, - _replicationProcess.get())); - - { - AutoGetCollectionForReadCommand autoDropSource(_opCtx.get(), dpSourceNs); - ASSERT_FALSE(autoDropSource.getCollection()); - - AutoGetCollectionForReadCommand autoDropTarget(_opCtx.get(), dpTargetNs); - ASSERT_FALSE(autoDropTarget.getCollection()); - - AutoGetCollectionForReadCommand renamedColl(_opCtx.get(), NamespaceString("test.t")); - ASSERT_TRUE(renamedColl.getCollection()); - ASSERT_EQUALS(renamedColl.getCollection()->uuid().get(), droppedSourceUUID); - - AutoGetCollectionForReadCommand droppedColl(_opCtx.get(), NamespaceString("foo.t")); - ASSERT_TRUE(droppedColl.getCollection()); - ASSERT_EQUALS(droppedColl.getCollection()->uuid().get(), droppedTargetUUID); - } -} - -TEST_F(RSRollbackTest, NewDocumentsInsertedAfterRenamingCollectionAcrossDatabasesShouldBeDropped) { - createOplog(_opCtx.get()); - Collection* collection = nullptr; - { - AutoGetOrCreateDb autoDb(_opCtx.get(), "foo", MODE_X); - mongo::WriteUnitOfWork wuow(_opCtx.get()); - collection = autoDb.getDb()->getCollection(_opCtx.get(), "foo.t"); - if (!collection) { - CollectionOptions options; - options.uuid = UUID::gen(); - collection = _createCollection(_opCtx.get(), "foo.t", options); - } - ASSERT(collection); - OpDebug* const nullOpDebug = nullptr; - ASSERT_OK(collection->insertDocument( - _opCtx.get(), InsertStatement(BSON("_id" << 1 << "a" << 1)), nullOpDebug, false)); - wuow.commit(); - } - - auto renamedCollectionUUID = collection->uuid().get(); - ASSERT(collection->numRecords(_opCtx.get()) == 1); - - OpTime dropTime = OpTime(Timestamp(2, 0), 5); - auto dpns = NamespaceString("test.t").makeDropPendingNamespace(dropTime); - - CollectionOptions droppedCollOptions; - droppedCollOptions.uuid = UUID::gen(); - auto droppedColl = _createCollection(_opCtx.get(), dpns, droppedCollOptions); - _dropPendingCollectionReaper->addDropPendingNamespace(dropTime, dpns); - auto droppedCollectionUUID = droppedColl->uuid().get(); - - auto commonOperation = - std::make_pair(BSON("ts" << Timestamp(Seconds(1), 0) << "h" << 1LL), RecordId(1)); - - auto renameCollectionOperation = makeRenameCollectionOplogEntry(NamespaceString("test.t"), - NamespaceString("foo.t"), - renamedCollectionUUID, - boost::none, - droppedCollectionUUID, - false, - OpTime(Timestamp(2, 0), 5)); - - auto insertDocumentOperation = - std::make_pair(BSON("ts" << Timestamp(Seconds(3), 0) << "h" << 1LL << "op" - << "i" - << "ui" - << renamedCollectionUUID - << "ns" - << "foo.t" - << "o" - << BSON("_id" << 1 << "a" << 1)), - RecordId(3)); - - RollbackSourceMock rollbackSource(std::unique_ptr<OplogInterface>(new OplogInterfaceMock({ - commonOperation, - }))); - - { - AutoGetCollectionForReadCommand autoCollDropPending(_opCtx.get(), dpns); - ASSERT_TRUE(autoCollDropPending.getCollection()); - AutoGetCollectionForReadCommand renamedColl(_opCtx.get(), NamespaceString("foo.t")); - ASSERT_TRUE(renamedColl.getCollection()); - AutoGetCollectionForReadCommand droppedColl(_opCtx.get(), NamespaceString("test.t")); - ASSERT_FALSE(droppedColl.getCollection()); - } - ASSERT_OK(syncRollback( - _opCtx.get(), - OplogInterfaceMock({insertDocumentOperation, renameCollectionOperation, commonOperation}), - rollbackSource, - {}, - _coordinator, - _replicationProcess.get())); - - { - AutoGetCollectionForReadCommand autoCollDropPending(_opCtx.get(), dpns); - ASSERT_FALSE(autoCollDropPending.getCollection()); - AutoGetCollectionForReadCommand renamedColl(_opCtx.get(), NamespaceString("test.t")); - ASSERT_TRUE(renamedColl.getCollection()); - ASSERT_EQUALS(renamedColl.getCollection()->uuid().get(), droppedCollectionUUID); - ASSERT(renamedColl.getCollection()->numRecords(_opCtx.get()) == 0); - AutoGetCollectionForReadCommand droppedColl(_opCtx.get(), NamespaceString("foo.t")); - ASSERT_FALSE(droppedColl.getCollection()); - } -} - - TEST_F(RSRollbackTest, RollbackCollModCommandFailsIfRBIDChangesWhileSyncingCollectionMetadata) { createOplog(_opCtx.get()); CollectionOptions options; |