summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChibuikem Amaechi <cramaechi@me.com>2018-01-19 14:52:47 -0600
committerSiyuan Zhou <visualzhou@gmail.com>2018-08-13 18:13:22 -0400
commit4db65855dbdc64cd4ca97146c1b5b812e502c8e4 (patch)
tree2b0198060539ba2a072875e81b381d61fa52d96d
parent15d2af439e6426c7232a75403739250b1537c54a (diff)
downloadmongo-4db65855dbdc64cd4ca97146c1b5b812e502c8e4.tar.gz
SERVER-32148 Make NamespaceNotFound an acceptable error for emptyCapped and convertToCapped
Closes #1206 Signed-off-by: Siyuan Zhou <siyuan.zhou@mongodb.com> (cherry picked from commit 35757e8ef3134fad1a09cb09a69882929d9ebb76)
-rw-r--r--jstests/replsets/drop_collections_two_phase_apply_ops_convert_to_capped.js8
-rw-r--r--jstests/replsets/emptycapped.js6
-rw-r--r--src/mongo/db/catalog/capped_utils.cpp4
-rw-r--r--src/mongo/db/repl/oplog.cpp10
-rw-r--r--src/mongo/db/repl/sync_tail_test.cpp34
5 files changed, 50 insertions, 12 deletions
diff --git a/jstests/replsets/drop_collections_two_phase_apply_ops_convert_to_capped.js b/jstests/replsets/drop_collections_two_phase_apply_ops_convert_to_capped.js
index 63746fc4109..013f58afe0b 100644
--- a/jstests/replsets/drop_collections_two_phase_apply_ops_convert_to_capped.js
+++ b/jstests/replsets/drop_collections_two_phase_apply_ops_convert_to_capped.js
@@ -53,8 +53,8 @@
TwoPhaseDropCollectionTest._testLog(
'Attempting to convert collection using applyOps with system.drop namespace: ' +
tojson(applyOpsCmdWithName));
- assert.commandFailedWithCode(primary.adminCommand(applyOpsCmdWithName),
- ErrorCodes.NamespaceNotFound);
+ // NamespaceNotFound is ignored, but the drop-pending collection shouldn't be affected.
+ assert.commandWorked(primary.adminCommand(applyOpsCmdWithName));
assert(twoPhaseDropTest.collectionIsPendingDrop(collName),
'applyOps using collection name ' + dropPendingCollName +
' affected drop-pending collection state unexpectedly');
@@ -72,8 +72,8 @@
TwoPhaseDropCollectionTest._testLog(
'Attempting to convert collection using applyOps with UUID: ' +
tojson(applyOpsCmdWithUuid));
- assert.commandFailedWithCode(primary.adminCommand(applyOpsCmdWithUuid),
- ErrorCodes.NamespaceNotFound);
+ // NamespaceNotFound is ignored, but the drop-pending collection shouldn't be affected.
+ assert.commandWorked(primary.adminCommand(applyOpsCmdWithName));
dropPendingCollInfo = twoPhaseDropTest.collectionIsPendingDrop(collName);
assert(dropPendingCollInfo,
'applyOps using UUID ' + dropPendingCollUuid +
diff --git a/jstests/replsets/emptycapped.js b/jstests/replsets/emptycapped.js
index c6b08fff9dc..b3aa6093be2 100644
--- a/jstests/replsets/emptycapped.js
+++ b/jstests/replsets/emptycapped.js
@@ -21,11 +21,13 @@
// Truncate a non-existent collection on a non-existent database.
assert.commandWorked(rst.getPrimary().getDB('nonexistent').dropDatabase());
assert.commandFailedWithCode(
- rst.getPrimary().getDB('nonexistent').runCommand({emptycapped: 'nonexistent'}), 13429);
+ rst.getPrimary().getDB('nonexistent').runCommand({emptycapped: 'nonexistent'}),
+ ErrorCodes.NamespaceNotFound);
// Truncate a non-existent collection.
primaryTestDB.nonexistent.drop();
- assert.commandFailedWithCode(primaryTestDB.runCommand({emptycapped: 'nonexistent'}), 28584);
+ assert.commandFailedWithCode(primaryTestDB.runCommand({emptycapped: 'nonexistent'}),
+ ErrorCodes.NamespaceNotFound);
// Truncate a capped collection.
assert.commandWorked(primaryTestDB.createCollection("capped", {capped: true, size: 4096}));
diff --git a/src/mongo/db/catalog/capped_utils.cpp b/src/mongo/db/catalog/capped_utils.cpp
index f1dfaf0369d..67f2957a881 100644
--- a/src/mongo/db/catalog/capped_utils.cpp
+++ b/src/mongo/db/catalog/capped_utils.cpp
@@ -64,13 +64,13 @@ mongo::Status mongo::emptyCapped(OperationContext* opCtx, const NamespaceString&
}
Database* db = autoDb.getDb();
- massert(13429, "no such database", db);
+ uassert(ErrorCodes::NamespaceNotFound, "no such database", db);
Collection* collection = db->getCollection(opCtx, collectionName);
uassert(ErrorCodes::CommandNotSupportedOnView,
str::stream() << "emptycapped not supported on view: " << collectionName.ns(),
collection || !db->getViewCatalog()->lookup(opCtx, collectionName.ns()));
- massert(28584, "no such collection", collection);
+ uassert(ErrorCodes::NamespaceNotFound, "no such collection", collection);
if (collectionName.isSystem() && !collectionName.isSystemDotProfile()) {
return Status(ErrorCodes::IllegalOperation,
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index 5f49dace9d8..db55e1560e4 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -923,8 +923,9 @@ std::map<std::string, ApplyOpMetadata> opsMap = {
BSONObj& cmd,
const OpTime& opTime,
OplogApplication::Mode mode) -> Status {
- return convertToCapped(opCtx, parseUUIDorNs(opCtx, ns, ui, cmd), cmd["size"].number());
- }}},
+ return convertToCapped(opCtx, parseUUIDorNs(opCtx, ns, ui, cmd), cmd["size"].number());
+ },
+ {ErrorCodes::NamespaceNotFound}}},
{"emptycapped",
{[](OperationContext* opCtx,
const char* ns,
@@ -932,8 +933,9 @@ std::map<std::string, ApplyOpMetadata> opsMap = {
BSONObj& cmd,
const OpTime& opTime,
OplogApplication::Mode mode) -> Status {
- return emptyCapped(opCtx, parseUUIDorNs(opCtx, ns, ui, cmd));
- }}},
+ return emptyCapped(opCtx, parseUUIDorNs(opCtx, ns, ui, cmd));
+ },
+ {ErrorCodes::NamespaceNotFound}}},
};
} // namespace
diff --git a/src/mongo/db/repl/sync_tail_test.cpp b/src/mongo/db/repl/sync_tail_test.cpp
index 4eae5589e83..97738fe14f2 100644
--- a/src/mongo/db/repl/sync_tail_test.cpp
+++ b/src/mongo/db/repl/sync_tail_test.cpp
@@ -2087,6 +2087,40 @@ TEST_F(SyncTailTxnTableTest, MultiApplyUpdatesTheTransactionTable) {
ASSERT_TRUE(resultNoTxn.isEmpty());
}
+TEST_F(IdempotencyTest, EmptyCappedNamespaceNotFound) {
+ // Create a BSON "emptycapped" command.
+ auto emptyCappedCmd = BSON("emptycapped" << nss.coll());
+
+ // Create an "emptycapped" oplog entry.
+ auto emptyCappedOp = makeCommandOplogEntry(nextOpTime(), nss, emptyCappedCmd);
+
+ // Ensure that NamespaceNotFound is acceptable.
+ ASSERT_OK(runOpInitialSync(emptyCappedOp));
+
+ AutoGetCollectionForReadCommand autoColl(_opCtx.get(), nss);
+
+ // Ensure that autoColl.getCollection() and autoColl.getDb() are both null.
+ ASSERT_FALSE(autoColl.getCollection());
+ ASSERT_FALSE(autoColl.getDb());
+}
+
+TEST_F(IdempotencyTest, ConvertToCappedNamespaceNotFound) {
+ // Create a BSON "convertToCapped" command.
+ auto convertToCappedCmd = BSON("convertToCapped" << nss.coll());
+
+ // Create a "convertToCapped" oplog entry.
+ auto convertToCappedOp = makeCommandOplogEntry(nextOpTime(), nss, convertToCappedCmd);
+
+ // Ensure that NamespaceNotFound is acceptable.
+ ASSERT_OK(runOpInitialSync(convertToCappedOp));
+
+ AutoGetCollectionForReadCommand autoColl(_opCtx.get(), nss);
+
+ // Ensure that autoColl.getCollection() and autoColl.getDb() are both null.
+ ASSERT_FALSE(autoColl.getCollection());
+ ASSERT_FALSE(autoColl.getDb());
+}
+
} // namespace
} // namespace repl
} // namespace mongo