diff options
| author | Matthew Saltz <matthew.saltz@mongodb.com> | 2022-09-19 20:13:52 +0000 |
|---|---|---|
| committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-09-19 21:13:34 +0000 |
| commit | 01414fd3f2bc599a651a1b89536b142974784f37 (patch) | |
| tree | d8f5dbfad3ec7a76d0caab20db058e91421eac34 /src/mongo | |
| parent | 5f965bd777834a96e9fcffff740250240f28124c (diff) | |
| download | mongo-01414fd3f2bc599a651a1b89536b142974784f37.tar.gz | |
SERVER-63257 Convert NamespaceNotFound error on config.system.indexBuilds to an anonymous error
Diffstat (limited to 'src/mongo')
| -rw-r--r-- | src/mongo/db/commands/SConscript | 3 | ||||
| -rw-r--r-- | src/mongo/db/commands/create_indexes_test.cpp | 78 | ||||
| -rw-r--r-- | src/mongo/db/index_builds_coordinator.cpp | 11 | ||||
| -rw-r--r-- | src/mongo/db/repl/tenant_migration_recipient_service.cpp | 4 | ||||
| -rw-r--r-- | src/mongo/db/repl/tenant_migration_recipient_service_test.cpp | 2 |
5 files changed, 97 insertions, 1 deletions
diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript index 77573fa709c..99ef69c2bbf 100644 --- a/src/mongo/db/commands/SConscript +++ b/src/mongo/db/commands/SConscript @@ -793,6 +793,7 @@ env.CppUnitTest( env.CppUnitTest( target="db_commands_test", source=[ + "create_indexes_test.cpp", "index_filter_commands_test.cpp", "fle_compact_test.cpp", "list_collections_filter_test.cpp", @@ -806,7 +807,9 @@ env.CppUnitTest( "$BUILD_DIR/mongo/crypto/encrypted_field_config", "$BUILD_DIR/mongo/crypto/fle_crypto", "$BUILD_DIR/mongo/db/auth/authmocks", + "$BUILD_DIR/mongo/db/catalog/catalog_test_fixture", "$BUILD_DIR/mongo/db/catalog/collection", + "$BUILD_DIR/mongo/db/catalog/collection_crud", "$BUILD_DIR/mongo/db/commands/list_collections_filter", "$BUILD_DIR/mongo/db/concurrency/exception_util", "$BUILD_DIR/mongo/db/dbdirectclient", diff --git a/src/mongo/db/commands/create_indexes_test.cpp b/src/mongo/db/commands/create_indexes_test.cpp new file mode 100644 index 00000000000..b7977ef5e67 --- /dev/null +++ b/src/mongo/db/commands/create_indexes_test.cpp @@ -0,0 +1,78 @@ +/** + * Copyright (C) 2022-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/db/catalog/catalog_test_fixture.h" +#include "mongo/db/catalog/collection_write_path.h" +#include "mongo/db/catalog_raii.h" +#include "mongo/db/dbdirectclient.h" + +namespace mongo { +namespace { + +class CreateIndexesTest : public CatalogTestFixture {}; + +TEST_F(CreateIndexesTest, CreateIndexesFailsWhenIndexBuildsCollectionIsMissing) { + auto opCtx = operationContext(); + // Drop config.system.indexBuilds collection. + ASSERT_OK( + storageInterface()->dropCollection(opCtx, NamespaceString::kIndexBuildEntryNamespace)); + + NamespaceString nss("unittests.timestampMultiIndexBuilds"); + + ASSERT_OK(storageInterface()->createCollection(operationContext(), nss, {})); + + { + AutoGetCollection collection(opCtx, nss, MODE_X); + invariant(collection); + + WriteUnitOfWork wuow(opCtx); + ASSERT_OK(collection_internal::insertDocument( + opCtx, *collection, InsertStatement(BSONObj(BSON("_id" << 0 << "a" << 1))), nullptr)); + wuow.commit(); + } // Release the X lock on the collection. + + DBDirectClient client(opCtx); + const auto kIndexVersion = IndexDescriptor::IndexVersion::kV2; + { + // Disable index build commit quorum as we don't have support of replication subsystem + // for voting. + auto index = BSON("v" << kIndexVersion << "key" << BSON("a" << 1) << "name" + << "a_1"); + auto createIndexesCmdObj = BSON( + "createIndexes" << nss.coll() << "indexes" << BSON_ARRAY(index) << "commitQuorum" << 0); + BSONObj result; + // This should fail since config.system.indexBuilds does not exist. + ASSERT_FALSE(client.runCommand(nss.db().toString(), createIndexesCmdObj, result)) << result; + ASSERT(result.hasField("code")); + ASSERT_EQ(result.getIntField("code"), 6325700); + } +} + +} // namespace +} // namespace mongo diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp index 7708d48886d..d4307107cb2 100644 --- a/src/mongo/db/index_builds_coordinator.cpp +++ b/src/mongo/db/index_builds_coordinator.cpp @@ -2038,7 +2038,16 @@ IndexBuildsCoordinator::PostSetupAction IndexBuildsCoordinator::_setUpIndexBuild replState->collectionUUID, indexBuildOptions.commitQuorum.value(), replState->indexNames); - uassertStatusOK(indexbuildentryhelpers::addIndexBuildEntry(opCtx, indexBuildEntry)); + + try { + uassertStatusOK(indexbuildentryhelpers::addIndexBuildEntry(opCtx, indexBuildEntry)); + } catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>& e) { + // If config.system.indexBuilds is not found, convert the NamespaceNotFound + // exception to an anonymous error code. This is to distinguish from + // a NamespaceNotFound exception on the user collection, which callers sometimes + // interpret as not being an error condition. + uasserted(6325700, e.reason()); + } opCtx->getServiceContext()->getOpObserver()->onStartIndexBuild( opCtx, diff --git a/src/mongo/db/repl/tenant_migration_recipient_service.cpp b/src/mongo/db/repl/tenant_migration_recipient_service.cpp index 5901de19cd9..847b8283788 100644 --- a/src/mongo/db/repl/tenant_migration_recipient_service.cpp +++ b/src/mongo/db/repl/tenant_migration_recipient_service.cpp @@ -179,6 +179,7 @@ MONGO_FAIL_POINT_DEFINE(fpWaitUntilTimestampMajorityCommitted); MONGO_FAIL_POINT_DEFINE(hangAfterUpdatingTransactionEntry); MONGO_FAIL_POINT_DEFINE(fpBeforeAdvancingStableTimestamp); MONGO_FAIL_POINT_DEFINE(hangMigrationBeforeRetryCheck); +MONGO_FAIL_POINT_DEFINE(skipCreatingIndexDuringRebuildService); namespace { // We never restart just the oplog fetcher. If a failure occurs, we restart the whole state machine @@ -298,6 +299,9 @@ void TenantMigrationRecipientService::abortAllMigrations(OperationContext* opCtx ExecutorFuture<void> TenantMigrationRecipientService::_rebuildService( std::shared_ptr<executor::ScopedTaskExecutor> executor, const CancellationToken& token) { return AsyncTry([this] { + if (MONGO_unlikely(skipCreatingIndexDuringRebuildService.shouldFail())) { + return; + } auto nss = getStateDocumentsNS(); AllowOpCtxWhenServiceRebuildingBlock allowOpCtxBlock(Client::getCurrent()); diff --git a/src/mongo/db/repl/tenant_migration_recipient_service_test.cpp b/src/mongo/db/repl/tenant_migration_recipient_service_test.cpp index 9c820e3a469..0452db238ac 100644 --- a/src/mongo/db/repl/tenant_migration_recipient_service_test.cpp +++ b/src/mongo/db/repl/tenant_migration_recipient_service_test.cpp @@ -3670,6 +3670,7 @@ TEST_F(TenantMigrationRecipientServiceTest, RecipientReceivesNonRetriableClonerE } TEST_F(TenantMigrationRecipientServiceTest, IncrementNumRestartsDueToRecipientFailureCounter) { + FailPointEnableBlock createIndexesFailpointBlock("skipCreatingIndexDuringRebuildService"); stopFailPointEnableBlock fp("fpAfterPersistingTenantMigrationRecipientInstanceStateDoc"); const UUID migrationUUID = UUID::gen(); const OpTime topOfOplogOpTime(Timestamp(1, 1), 1); @@ -3723,6 +3724,7 @@ TEST_F(TenantMigrationRecipientServiceTest, IncrementNumRestartsDueToRecipientFa TEST_F(TenantMigrationRecipientServiceTest, RecipientFailureCounterNotIncrementedWhenMigrationForgotten) { + FailPointEnableBlock createIndexesFailpointBlock("skipCreatingIndexDuringRebuildService"); const UUID migrationUUID = UUID::gen(); const OpTime topOfOplogOpTime(Timestamp(1, 1), 1); |
