summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2022-01-07 12:44:15 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-01-11 15:32:06 +0000
commit550cfa96862fd47a6608deaab055f314754deab2 (patch)
tree702e531116581eeaa2bb67cb43ecfa4d9b1658bf
parent84cd050cee78239d3c3688ef94eeb4bbbcf9a4cd (diff)
downloadmongo-550cfa96862fd47a6608deaab055f314754deab2.tar.gz
SERVER-62429 Add `CollectionUUIDMismatch` error code
-rw-r--r--src/mongo/base/error_codes.yml2
-rw-r--r--src/mongo/db/SConscript1
-rw-r--r--src/mongo/db/catalog/SConscript22
-rw-r--r--src/mongo/db/catalog/collection_uuid_mismatch.cpp43
-rw-r--r--src/mongo/db/catalog/collection_uuid_mismatch.h36
-rw-r--r--src/mongo/db/catalog/collection_uuid_mismatch_info.cpp50
-rw-r--r--src/mongo/db/catalog/collection_uuid_mismatch_info.h53
7 files changed, 207 insertions, 0 deletions
diff --git a/src/mongo/base/error_codes.yml b/src/mongo/base/error_codes.yml
index 8724b2d3311..8d919914e73 100644
--- a/src/mongo/base/error_codes.yml
+++ b/src/mongo/base/error_codes.yml
@@ -461,6 +461,8 @@ error_codes:
- {code: 360, name: ShardVersionRefreshCanceled, categories: [InternalOnly]}
+ - {code: 361, name: CollectionUUIDMismatch, extra: CollectionUUIDMismatchInfo}
+
# Error codes 4000-8999 are reserved.
# Non-sequential error codes for compatibility only)
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index 7ccdc35e99b..00a806642d2 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -69,6 +69,7 @@ env.Library(
LIBDEPS=[
'$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/db/catalog/cannot_enable_index_constraint_info',
+ '$BUILD_DIR/mongo/db/catalog/collection_uuid_mismatch_info',
'$BUILD_DIR/mongo/db/index_names',
'$BUILD_DIR/mongo/db/repl/tenant_migration_errors',
'$BUILD_DIR/mongo/db/write_concern_options',
diff --git a/src/mongo/db/catalog/SConscript b/src/mongo/db/catalog/SConscript
index 2997869599c..ba23f0234a7 100644
--- a/src/mongo/db/catalog/SConscript
+++ b/src/mongo/db/catalog/SConscript
@@ -563,6 +563,28 @@ env.Library(
],
)
+env.Library(
+ target='collection_uuid_mismatch_info',
+ source=[
+ 'collection_uuid_mismatch_info.cpp',
+ ],
+ LIBDEPS_PRIVATE=[
+ '$BUILD_DIR/mongo/base',
+ ],
+)
+
+env.Library(
+ target='collection_uuid_mismatch',
+ source=[
+ 'collection_uuid_mismatch.cpp',
+ ],
+ LIBDEPS_PRIVATE=[
+ '$BUILD_DIR/mongo/base',
+ 'collection_catalog',
+ 'collection_uuid_mismatch_info',
+ ],
+)
+
if wiredtiger:
env.CppUnitTest(
target='db_catalog_test',
diff --git a/src/mongo/db/catalog/collection_uuid_mismatch.cpp b/src/mongo/db/catalog/collection_uuid_mismatch.cpp
new file mode 100644
index 00000000000..13354d6ab36
--- /dev/null
+++ b/src/mongo/db/catalog/collection_uuid_mismatch.cpp
@@ -0,0 +1,43 @@
+/**
+ * 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/collection_uuid_mismatch.h"
+
+#include "mongo/db/catalog/collection_catalog.h"
+#include "mongo/db/catalog/collection_uuid_mismatch_info.h"
+
+namespace mongo {
+void uassertCollectionUUIDMismatch(OperationContext* opCtx, const UUID& uuid) {
+ uassertStatusOK({CollectionUUIDMismatchInfo{uuid,
+ CollectionCatalog::get(opCtx)
+ ->lookupNSSByUUID(opCtx, uuid)
+ .value_or(NamespaceString{})},
+ "Collection UUID does not match that specified"});
+}
+} // namespace mongo
diff --git a/src/mongo/db/catalog/collection_uuid_mismatch.h b/src/mongo/db/catalog/collection_uuid_mismatch.h
new file mode 100644
index 00000000000..de79c57ddb4
--- /dev/null
+++ b/src/mongo/db/catalog/collection_uuid_mismatch.h
@@ -0,0 +1,36 @@
+/**
+ * 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.
+ */
+
+#pragma once
+
+#include "mongo/db/operation_context.h"
+
+namespace mongo {
+void uassertCollectionUUIDMismatch(OperationContext* opCtx, const UUID& uuid);
+} // namespace mongo
diff --git a/src/mongo/db/catalog/collection_uuid_mismatch_info.cpp b/src/mongo/db/catalog/collection_uuid_mismatch_info.cpp
new file mode 100644
index 00000000000..0e2d51d2e9e
--- /dev/null
+++ b/src/mongo/db/catalog/collection_uuid_mismatch_info.cpp
@@ -0,0 +1,50 @@
+/**
+ * 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/collection_uuid_mismatch_info.h"
+
+#include "mongo/base/init.h"
+#include "mongo/bson/bsonobjbuilder.h"
+
+namespace mongo {
+namespace {
+MONGO_INIT_REGISTER_ERROR_EXTRA_INFO(CollectionUUIDMismatchInfo);
+} // namespace
+
+std::shared_ptr<const ErrorExtraInfo> CollectionUUIDMismatchInfo::parse(const BSONObj& obj) {
+ return std::make_shared<CollectionUUIDMismatchInfo>(
+ UUID::parse(obj["collectionUUID"]).getValue(),
+ NamespaceString{obj.getStringField("actualNamespace")});
+}
+
+void CollectionUUIDMismatchInfo::serialize(BSONObjBuilder* builder) const {
+ _collectionUUID.appendToBuilder(builder, "collectionUUID");
+ builder->append("actualNamespace", _actualNamespace.ns());
+}
+} // namespace mongo
diff --git a/src/mongo/db/catalog/collection_uuid_mismatch_info.h b/src/mongo/db/catalog/collection_uuid_mismatch_info.h
new file mode 100644
index 00000000000..a1e97980bcf
--- /dev/null
+++ b/src/mongo/db/catalog/collection_uuid_mismatch_info.h
@@ -0,0 +1,53 @@
+/**
+ * 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.
+ */
+
+#pragma once
+
+#include "mongo/base/error_extra_info.h"
+
+#include "mongo/db/namespace_string.h"
+
+namespace mongo {
+class CollectionUUIDMismatchInfo final : public ErrorExtraInfo {
+public:
+ static constexpr auto code = ErrorCodes::CollectionUUIDMismatch;
+
+ explicit CollectionUUIDMismatchInfo(const UUID& collectionUUID,
+ const NamespaceString& actualNamespace)
+ : _collectionUUID(collectionUUID), _actualNamespace(actualNamespace) {}
+
+ static std::shared_ptr<const ErrorExtraInfo> parse(const BSONObj& obj);
+
+ void serialize(BSONObjBuilder* builder) const override;
+
+private:
+ UUID _collectionUUID;
+ NamespaceString _actualNamespace;
+};
+} // namespace mongo