diff options
author | Benety Goh <benety@mongodb.com> | 2018-02-08 15:54:59 -0500 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2018-02-08 15:57:27 -0500 |
commit | 99ec7ccdb0196b3826abfa5d987835b349f32e0d (patch) | |
tree | 10e02db0a2a22966d890625a2fd41adba60e7e7c /src/mongo/db | |
parent | b77e46685dc7ae8b9893ef019a1cbc67798bb749 (diff) | |
download | mongo-99ec7ccdb0196b3826abfa5d987835b349f32e0d.tar.gz |
SERVER-33160 syncApply() treats delete ops on non-existent namespaces as no-ops for idempotency reasons
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/repl/sync_tail.cpp | 33 | ||||
-rw-r--r-- | src/mongo/db/repl/sync_tail_test.cpp | 8 |
2 files changed, 23 insertions, 18 deletions
diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp index 1f71d8b5b15..1600b99d224 100644 --- a/src/mongo/db/repl/sync_tail.cpp +++ b/src/mongo/db/repl/sync_tail.cpp @@ -360,24 +360,33 @@ Status SyncTail::syncApply(OperationContext* opCtx, // it must have been in the same database or it would have gotten a new UUID. // Need to throw instead of returning a status for it to be properly ignored. actualNss = UUIDCatalog::get(opCtx).lookupNSSByUUID(statusWithUUID.getValue()); - uassert(ErrorCodes::NamespaceNotFound, - str::stream() << "Failed to apply operation due to missing collection (" - << statusWithUUID.getValue() - << "): " - << redact(op.toString()), - !actualNss.isEmpty()); + if (actualNss.isEmpty()) { + if (opType[0] == 'd') { + return Status::OK(); + } + uasserted(ErrorCodes::NamespaceNotFound, + str::stream() + << "Failed to apply operation due to missing collection (" + << statusWithUUID.getValue() + << "): " + << redact(op.toString())); + } dassert(actualNss.db() == nss.db()); } Lock::CollectionLock collLock(opCtx->lockState(), actualNss.ns(), MODE_IX); // Need to throw instead of returning a status for it to be properly ignored. Database* db = dbHolder().get(opCtx, actualNss.db()); - uassert(ErrorCodes::NamespaceNotFound, - str::stream() << "Failed to apply operation due to missing database (" - << actualNss.db() - << "): " - << redact(op.toString()), - db); + if (!db) { + if (opType[0] == 'd') { + return Status::OK(); + } + uasserted(ErrorCodes::NamespaceNotFound, + str::stream() << "Failed to apply operation due to missing database (" + << actualNss.db() + << "): " + << redact(op.toString())); + } OldClientContext ctx(opCtx, actualNss.ns(), db, /*justCreated*/ false); return applyOp(ctx.db()); diff --git a/src/mongo/db/repl/sync_tail_test.cpp b/src/mongo/db/repl/sync_tail_test.cpp index c58f88b36cd..cea4e8652c9 100644 --- a/src/mongo/db/repl/sync_tail_test.cpp +++ b/src/mongo/db/repl/sync_tail_test.cpp @@ -306,9 +306,7 @@ TEST_F(SyncTailTest, SyncApplyDeleteDocumentDatabaseMissing) { << "d" << "ns" << "test.othername"); - ASSERT_THROWS_CODE(_testSyncApplyCrudOperation(ErrorCodes::OK, op, false), - AssertionException, - ErrorCodes::NamespaceNotFound); + _testSyncApplyCrudOperation(ErrorCodes::OK, op, false); } TEST_F(SyncTailTest, SyncApplyInsertDocumentCollectionLookupByUUIDFails) { @@ -334,9 +332,7 @@ TEST_F(SyncTailTest, SyncApplyDeleteDocumentCollectionLookupByUUIDFails) { << nss.getSisterNS("othername") << "ui" << UUID::gen()); - ASSERT_THROWS_CODE(_testSyncApplyCrudOperation(ErrorCodes::OK, op, false), - AssertionException, - ErrorCodes::NamespaceNotFound); + _testSyncApplyCrudOperation(ErrorCodes::OK, op, false); } TEST_F(SyncTailTest, SyncApplyInsertDocumentCollectionMissing) { |