summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorVishnu Kaushik <vishnu.kaushik@mongodb.com>2021-02-17 17:54:23 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-02-18 15:30:42 +0000
commitd3410812235c66ebdaf1a4e60073bd1ab9d9f2ee (patch)
tree7ee69541b2693a7c05f773ba99309099b8059998 /src/mongo/db
parentc3bae033840342b65384deb9dba7763f567f3a6c (diff)
downloadmongo-d3410812235c66ebdaf1a4e60073bd1ab9d9f2ee.tar.gz
SERVER-54191 Avoid fasserting in a tenant migration if recipient primary calls startup on oplog buffer after it steps down
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/repl/oplog_buffer_collection.cpp4
-rw-r--r--src/mongo/db/repl/oplog_buffer_collection_test.cpp10
-rw-r--r--src/mongo/db/repl/tenant_migration_recipient_service.cpp16
3 files changed, 21 insertions, 9 deletions
diff --git a/src/mongo/db/repl/oplog_buffer_collection.cpp b/src/mongo/db/repl/oplog_buffer_collection.cpp
index e0343e6b9c1..fed20b125c1 100644
--- a/src/mongo/db/repl/oplog_buffer_collection.cpp
+++ b/src/mongo/db/repl/oplog_buffer_collection.cpp
@@ -419,12 +419,12 @@ void OplogBufferCollection::_createCollection(OperationContext* opCtx) {
auto status = _storageInterface->createCollection(opCtx, _nss, options);
if (status.code() == ErrorCodes::NamespaceExists)
return;
- fassert(40154, status);
+ uassertStatusOK(status);
}
void OplogBufferCollection::_dropCollection(OperationContext* opCtx) {
UninterruptibleLockGuard noInterrupt(opCtx->lockState());
- fassert(40155, _storageInterface->dropCollection(opCtx, _nss));
+ uassertStatusOK(_storageInterface->dropCollection(opCtx, _nss));
}
Timestamp OplogBufferCollection::getLastPushedTimestamp() const {
diff --git a/src/mongo/db/repl/oplog_buffer_collection_test.cpp b/src/mongo/db/repl/oplog_buffer_collection_test.cpp
index 6a5184ca117..35cdb2d89a8 100644
--- a/src/mongo/db/repl/oplog_buffer_collection_test.cpp
+++ b/src/mongo/db/repl/oplog_buffer_collection_test.cpp
@@ -149,11 +149,11 @@ TEST_F(OplogBufferCollectionTest, StartupWithUserProvidedNamespaceCreatesCollect
testStartupCreatesCollection(_opCtx.get(), _storageInterface, makeNamespace(_agent));
}
-DEATH_TEST_REGEX_F(
- OplogBufferCollectionTest,
- StartupWithOplogNamespaceTriggersFatalAssertion,
- "Fatal assertion.*40154.*Location28838: cannot create a non-capped oplog collection") {
- testStartupCreatesCollection(_opCtx.get(), _storageInterface, NamespaceString("local.oplog.Z"));
+TEST_F(OplogBufferCollectionTest, StartupWithOplogNamespaceTriggersUassert) {
+ ASSERT_THROWS_CODE(testStartupCreatesCollection(
+ _opCtx.get(), _storageInterface, NamespaceString("local.oplog.Z")),
+ DBException,
+ 28838);
}
TEST_F(OplogBufferCollectionTest, ShutdownDropsCollection) {
diff --git a/src/mongo/db/repl/tenant_migration_recipient_service.cpp b/src/mongo/db/repl/tenant_migration_recipient_service.cpp
index c8571ed76c8..c40612d3045 100644
--- a/src/mongo/db/repl/tenant_migration_recipient_service.cpp
+++ b/src/mongo/db/repl/tenant_migration_recipient_service.cpp
@@ -771,9 +771,21 @@ void TenantMigrationRecipientService::Instance::_startOplogFetcher() {
options.useTemporaryCollection = false;
stdx::unique_lock lk(_mutex);
invariant(_stateDoc.getStartFetchingDonorOpTime());
+ auto oplogBufferNS = getOplogBufferNs(getMigrationUUID());
_donorOplogBuffer = std::make_unique<OplogBufferCollection>(
- StorageInterface::get(opCtx.get()), getOplogBufferNs(getMigrationUUID()), options);
- _donorOplogBuffer->startup(opCtx.get());
+ StorageInterface::get(opCtx.get()), oplogBufferNS, options);
+
+ {
+ // Ensure we are primary when trying to startup and create the oplog buffer collection.
+ auto coordinator = repl::ReplicationCoordinator::get(opCtx.get());
+ Lock::GlobalLock globalLock(opCtx.get(), MODE_IX);
+ if (!coordinator->canAcceptWritesForDatabase(opCtx.get(), oplogBufferNS.db())) {
+ uassertStatusOK(
+ Status(ErrorCodes::NotWritablePrimary,
+ "Recipient node is not primary, cannot create oplog buffer collection."));
+ }
+ _donorOplogBuffer->startup(opCtx.get());
+ }
pauseAfterCreatingOplogBuffer.pauseWhileSet();