diff options
author | Judah Schvimer <judah@mongodb.com> | 2016-06-23 10:12:04 -0400 |
---|---|---|
committer | Judah Schvimer <judah@mongodb.com> | 2016-06-23 10:12:15 -0400 |
commit | c7bafe54b512d6b8ea832f25996a67406a710cc3 (patch) | |
tree | b97e9ace33d8534f0e95c99c419cf2ae836b5dc8 | |
parent | a7dc0fd86e56e719939ad76c6c361d92bf2ee258 (diff) | |
download | mongo-c7bafe54b512d6b8ea832f25996a67406a710cc3.tar.gz |
SERVER-24728 replace NoSuchKey error code with CollectionIsEmpty where appropriate
-rw-r--r-- | src/mongo/base/error_codes.err | 1 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_buffer_collection.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_buffer_collection_test.cpp | 18 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_interface_local.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_interface_remote.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/repl/storage_interface_impl.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/storage_interface_impl_test.cpp | 19 | ||||
-rw-r--r-- | src/mongo/db/repl/sync_tail_test.cpp | 2 |
8 files changed, 28 insertions, 24 deletions
diff --git a/src/mongo/base/error_codes.err b/src/mongo/base/error_codes.err index 0fc6e583dae..0de23d27cb6 100644 --- a/src/mongo/base/error_codes.err +++ b/src/mongo/base/error_codes.err @@ -160,6 +160,7 @@ error_code("MustUpgrade", 158) error_code("DurationOverflow", 159) error_code("MaxStalenessOutOfRange", 160) error_code("IncompatibleCollationVersion", 161) +error_code("CollectionIsEmpty", 162) # Non-sequential error codes (for compatibility only) error_code("SocketException", 9001) diff --git a/src/mongo/db/repl/oplog_buffer_collection.cpp b/src/mongo/db/repl/oplog_buffer_collection.cpp index dd8227def54..5c578ed77ab 100644 --- a/src/mongo/db/repl/oplog_buffer_collection.cpp +++ b/src/mongo/db/repl/oplog_buffer_collection.cpp @@ -199,7 +199,7 @@ bool OplogBufferCollection::_doPop_inlock(OperationContext* txn, Value* value) { auto scanDirection = StorageInterface::ScanDirection::kForward; auto result = _storageInterface->deleteOne(txn, _nss, kIdObj, scanDirection); if (!result.isOK()) { - if (result != ErrorCodes::NoSuchKey) { + if (result != ErrorCodes::CollectionIsEmpty) { fassert(40162, result.getStatus()); } return false; @@ -219,7 +219,7 @@ bool OplogBufferCollection::_peekOneSide_inlock(OperationContext* txn, : StorageInterface::ScanDirection::kBackward; auto result = _storageInterface->findOne(txn, _nss, kIdObj, scanDirection); if (!result.isOK()) { - if (result != ErrorCodes::NoSuchKey) { + if (result != ErrorCodes::CollectionIsEmpty) { fassert(40163, result.getStatus()); } return false; diff --git a/src/mongo/db/repl/oplog_buffer_collection_test.cpp b/src/mongo/db/repl/oplog_buffer_collection_test.cpp index 62fbd40c36b..8dde9864b10 100644 --- a/src/mongo/db/repl/oplog_buffer_collection_test.cpp +++ b/src/mongo/db/repl/oplog_buffer_collection_test.cpp @@ -209,7 +209,7 @@ TEST_F(OplogBufferCollectionTest, PushOneDocumentWithPushAllNonBlockingAddsDocum ASSERT_EQUALS(oplog[0], OplogBufferCollection::extractEmbeddedOplogDocument( unittest::assertGet(iter->next()).first)); - ASSERT_EQUALS(ErrorCodes::NoSuchKey, iter->next().getStatus()); + ASSERT_EQUALS(ErrorCodes::CollectionIsEmpty, iter->next().getStatus()); } } @@ -229,7 +229,7 @@ TEST_F(OplogBufferCollectionTest, PushOneDocumentWithPushAddsDocument) { ASSERT_EQUALS(oplog, OplogBufferCollection::extractEmbeddedOplogDocument( unittest::assertGet(iter->next()).first)); - ASSERT_EQUALS(ErrorCodes::NoSuchKey, iter->next().getStatus()); + ASSERT_EQUALS(ErrorCodes::CollectionIsEmpty, iter->next().getStatus()); } } @@ -249,7 +249,7 @@ TEST_F(OplogBufferCollectionTest, PushOneDocumentWithPushEvenIfFullAddsDocument) ASSERT_EQUALS(oplog, OplogBufferCollection::extractEmbeddedOplogDocument( unittest::assertGet(iter->next()).first)); - ASSERT_EQUALS(ErrorCodes::NoSuchKey, iter->next().getStatus()); + ASSERT_EQUALS(ErrorCodes::CollectionIsEmpty, iter->next().getStatus()); } } @@ -274,7 +274,7 @@ TEST_F(OplogBufferCollectionTest, PeekDoesNotRemoveDocument) { ASSERT_EQUALS(oplog, OplogBufferCollection::extractEmbeddedOplogDocument( unittest::assertGet(iter->next()).first)); - ASSERT_EQUALS(ErrorCodes::NoSuchKey, iter->next().getStatus()); + ASSERT_EQUALS(ErrorCodes::CollectionIsEmpty, iter->next().getStatus()); } } @@ -293,7 +293,7 @@ TEST_F(OplogBufferCollectionTest, PeekWithNoDocumentsReturnsFalse) { { OplogInterfaceLocal collectionReader(_txn.get(), nss.ns()); auto iter = collectionReader.makeIterator(); - ASSERT_EQUALS(ErrorCodes::NoSuchKey, iter->next().getStatus()); + ASSERT_EQUALS(ErrorCodes::CollectionIsEmpty, iter->next().getStatus()); } } @@ -315,7 +315,7 @@ TEST_F(OplogBufferCollectionTest, PopRemovesDocument) { { OplogInterfaceLocal collectionReader(_txn.get(), nss.ns()); auto iter = collectionReader.makeIterator(); - ASSERT_EQUALS(ErrorCodes::NoSuchKey, iter->next().getStatus()); + ASSERT_EQUALS(ErrorCodes::CollectionIsEmpty, iter->next().getStatus()); } } @@ -334,7 +334,7 @@ TEST_F(OplogBufferCollectionTest, PopWithNoDocumentsReturnsFalse) { { OplogInterfaceLocal collectionReader(_txn.get(), nss.ns()); auto iter = collectionReader.makeIterator(); - ASSERT_EQUALS(ErrorCodes::NoSuchKey, iter->next().getStatus()); + ASSERT_EQUALS(ErrorCodes::CollectionIsEmpty, iter->next().getStatus()); } } @@ -362,7 +362,7 @@ TEST_F(OplogBufferCollectionTest, PopAndPeekReturnDocumentsInOrder) { ASSERT_EQUALS(oplog[0], OplogBufferCollection::extractEmbeddedOplogDocument( unittest::assertGet(iter->next()).first)); - ASSERT_EQUALS(ErrorCodes::NoSuchKey, iter->next().getStatus()); + ASSERT_EQUALS(ErrorCodes::CollectionIsEmpty, iter->next().getStatus()); } BSONObj doc; @@ -446,7 +446,7 @@ TEST_F(OplogBufferCollectionTest, ClearClearsCollection) { { OplogInterfaceLocal collectionReader(_txn.get(), nss.ns()); auto iter = collectionReader.makeIterator(); - ASSERT_EQUALS(ErrorCodes::NoSuchKey, iter->next().getStatus()); + ASSERT_EQUALS(ErrorCodes::CollectionIsEmpty, iter->next().getStatus()); } BSONObj doc; diff --git a/src/mongo/db/repl/oplog_interface_local.cpp b/src/mongo/db/repl/oplog_interface_local.cpp index 88aa50436ee..03b93892885 100644 --- a/src/mongo/db/repl/oplog_interface_local.cpp +++ b/src/mongo/db/repl/oplog_interface_local.cpp @@ -72,7 +72,8 @@ StatusWith<OplogInterface::Iterator::Value> OplogIteratorLocal::next() { PlanExecutor::ExecState state; if (PlanExecutor::ADVANCED != (state = _exec->getNext(&obj, &recordId))) { - return StatusWith<Value>(ErrorCodes::NoSuchKey, "no more operations in local oplog"); + return StatusWith<Value>(ErrorCodes::CollectionIsEmpty, + "no more operations in local oplog"); } // Non-yielding collection scans from InternalPlanner will never error. diff --git a/src/mongo/db/repl/oplog_interface_remote.cpp b/src/mongo/db/repl/oplog_interface_remote.cpp index 74623e7a395..1463eb53390 100644 --- a/src/mongo/db/repl/oplog_interface_remote.cpp +++ b/src/mongo/db/repl/oplog_interface_remote.cpp @@ -56,7 +56,8 @@ StatusWith<OplogInterface::Iterator::Value> OplogIteratorRemote::next() { return StatusWith<Value>(ErrorCodes::NamespaceNotFound, "no cursor for remote oplog"); } if (!_cursor->more()) { - return StatusWith<Value>(ErrorCodes::NoSuchKey, "no more operations in remote oplog"); + return StatusWith<Value>(ErrorCodes::CollectionIsEmpty, + "no more operations in remote oplog"); } return StatusWith<Value>(std::make_pair(_cursor->nextSafe(), RecordId())); } diff --git a/src/mongo/db/repl/storage_interface_impl.cpp b/src/mongo/db/repl/storage_interface_impl.cpp index a057b603cc8..010124d4328 100644 --- a/src/mongo/db/repl/storage_interface_impl.cpp +++ b/src/mongo/db/repl/storage_interface_impl.cpp @@ -479,7 +479,7 @@ StatusWith<BSONObj> _findOrDeleteOne(OperationContext* txn, BSONObj doc; auto state = planExecutor->getNext(&doc, nullptr); if (PlanExecutor::IS_EOF == state) { - return {ErrorCodes::NoSuchKey, + return {ErrorCodes::CollectionIsEmpty, str::stream() << "Collection is empty, ns: " << nss.ns() << ", index: " << indexKeyPattern}; } diff --git a/src/mongo/db/repl/storage_interface_impl_test.cpp b/src/mongo/db/repl/storage_interface_impl_test.cpp index a7ddcd208d5..b59eb3396be 100644 --- a/src/mongo/db/repl/storage_interface_impl_test.cpp +++ b/src/mongo/db/repl/storage_interface_impl_test.cpp @@ -370,7 +370,7 @@ TEST_F(StorageInterfaceImplTest, InsertDocumentsSavesOperationsReturnsOpTimeOfLa auto iter = oplog.makeIterator(); ASSERT_EQUALS(op2, unittest::assertGet(iter->next()).first); ASSERT_EQUALS(op1, unittest::assertGet(iter->next()).first); - ASSERT_EQUALS(ErrorCodes::NoSuchKey, iter->next().getStatus()); + ASSERT_EQUALS(ErrorCodes::CollectionIsEmpty, iter->next().getStatus()); } TEST_F(StorageInterfaceImplTest, @@ -574,13 +574,13 @@ TEST_F(StorageInterfaceImplWithReplCoordTest, storage.findOne(txn, nss, keyPattern, StorageInterface::ScanDirection::kForward)); } -TEST_F(StorageInterfaceImplWithReplCoordTest, FindOneReturnsNoSuchKeyIfCollectionIsEmpty) { +TEST_F(StorageInterfaceImplWithReplCoordTest, FindOneReturnsCollectionIsEmptyIfCollectionIsEmpty) { auto txn = getOperationContext(); StorageInterfaceImpl storage; auto nss = makeNamespace(_agent); auto keyPattern = BSON("_id" << 1); ASSERT_OK(storage.createCollection(txn, nss, CollectionOptions())); - ASSERT_EQUALS(ErrorCodes::NoSuchKey, + ASSERT_EQUALS(ErrorCodes::CollectionIsEmpty, storage.findOne(txn, nss, keyPattern, StorageInterface::ScanDirection::kForward)); } @@ -602,7 +602,7 @@ TEST_F(StorageInterfaceImplWithReplCoordTest, ASSERT_EQUALS(BSON("_id" << 2), unittest::assertGet(iter->next()).first); ASSERT_EQUALS(BSON("_id" << 1), unittest::assertGet(iter->next()).first); ASSERT_EQUALS(BSON("_id" << 0), unittest::assertGet(iter->next()).first); - ASSERT_EQUALS(ErrorCodes::NoSuchKey, iter->next().getStatus()); + ASSERT_EQUALS(ErrorCodes::CollectionIsEmpty, iter->next().getStatus()); } TEST_F(StorageInterfaceImplWithReplCoordTest, @@ -624,7 +624,7 @@ TEST_F(StorageInterfaceImplWithReplCoordTest, ASSERT_EQUALS(BSON("_id" << 2), unittest::assertGet(iter->next()).first); ASSERT_EQUALS(BSON("_id" << 1), unittest::assertGet(iter->next()).first); ASSERT_EQUALS(BSON("_id" << 0), unittest::assertGet(iter->next()).first); - ASSERT_EQUALS(ErrorCodes::NoSuchKey, iter->next().getStatus()); + ASSERT_EQUALS(ErrorCodes::CollectionIsEmpty, iter->next().getStatus()); } TEST_F(StorageInterfaceImplWithReplCoordTest, @@ -649,14 +649,15 @@ TEST_F(StorageInterfaceImplWithReplCoordTest, DeleteOneReturnsIndexNotFoundIfInd storage.deleteOne(txn, nss, keyPattern, StorageInterface::ScanDirection::kForward)); } -TEST_F(StorageInterfaceImplWithReplCoordTest, DeleteOneReturnsNoSuchKeyIfCollectionIsEmpty) { +TEST_F(StorageInterfaceImplWithReplCoordTest, + DeleteOneReturnsCollectionIsEmptyIfCollectionIsEmpty) { auto txn = getOperationContext(); StorageInterfaceImpl storage; auto nss = makeNamespace(_agent); auto keyPattern = BSON("_id" << 1); ASSERT_OK(storage.createCollection(txn, nss, CollectionOptions())); ASSERT_EQUALS( - ErrorCodes::NoSuchKey, + ErrorCodes::CollectionIsEmpty, storage.deleteOne(txn, nss, keyPattern, StorageInterface::ScanDirection::kForward)); } @@ -678,7 +679,7 @@ TEST_F(StorageInterfaceImplWithReplCoordTest, auto iter = oplog.makeIterator(); ASSERT_EQUALS(BSON("_id" << 2), unittest::assertGet(iter->next()).first); ASSERT_EQUALS(BSON("_id" << 1), unittest::assertGet(iter->next()).first); - ASSERT_EQUALS(ErrorCodes::NoSuchKey, iter->next().getStatus()); + ASSERT_EQUALS(ErrorCodes::CollectionIsEmpty, iter->next().getStatus()); } TEST_F(StorageInterfaceImplWithReplCoordTest, @@ -699,7 +700,7 @@ TEST_F(StorageInterfaceImplWithReplCoordTest, auto iter = oplog.makeIterator(); ASSERT_EQUALS(BSON("_id" << 1), unittest::assertGet(iter->next()).first); ASSERT_EQUALS(BSON("_id" << 0), unittest::assertGet(iter->next()).first); - ASSERT_EQUALS(ErrorCodes::NoSuchKey, iter->next().getStatus()); + ASSERT_EQUALS(ErrorCodes::CollectionIsEmpty, iter->next().getStatus()); } } // namespace diff --git a/src/mongo/db/repl/sync_tail_test.cpp b/src/mongo/db/repl/sync_tail_test.cpp index 53b1983c5df..23270ddcb80 100644 --- a/src/mongo/db/repl/sync_tail_test.cpp +++ b/src/mongo/db/repl/sync_tail_test.cpp @@ -885,7 +885,7 @@ TEST_F(SyncTailTest, MultiInitialSyncApplyRetriesFailedUpdateIfDocumentIsAvailab OplogInterfaceLocal collectionReader(_txn.get(), nss.ns()); auto iter = collectionReader.makeIterator(); ASSERT_EQUALS(updatedDocument, unittest::assertGet(iter->next()).first); - ASSERT_EQUALS(ErrorCodes::NoSuchKey, iter->next().getStatus()); + ASSERT_EQUALS(ErrorCodes::CollectionIsEmpty, iter->next().getStatus()); } TEST_F(SyncTailTest, MultiInitialSyncApplyPassesThroughSyncApplyErrorAfterFailingToRetryBadOp) { |