summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/catalog/drop_indexes.cpp4
-rw-r--r--src/mongo/db/catalog/drop_indexes.h1
-rw-r--r--src/mongo/db/commands/create_indexes.cpp3
-rw-r--r--src/mongo/db/commands/drop_indexes.cpp10
-rw-r--r--src/mongo/db/create_indexes.idl5
-rw-r--r--src/mongo/db/drop_indexes.idl5
-rw-r--r--src/mongo/dbtests/storage_timestamp_tests.cpp4
-rw-r--r--src/mongo/s/cluster_commands_helpers.cpp4
8 files changed, 32 insertions, 4 deletions
diff --git a/src/mongo/db/catalog/drop_indexes.cpp b/src/mongo/db/catalog/drop_indexes.cpp
index f58977c65b1..6def710a960 100644
--- a/src/mongo/db/catalog/drop_indexes.cpp
+++ b/src/mongo/db/catalog/drop_indexes.cpp
@@ -35,6 +35,7 @@
#include <boost/algorithm/string/join.hpp>
+#include "mongo/db/catalog/collection_uuid_mismatch.h"
#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/client.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
@@ -343,13 +344,16 @@ void assertMovePrimaryInProgress(OperationContext* opCtx, const NamespaceString&
DropIndexesReply dropIndexes(OperationContext* opCtx,
const NamespaceString& nss,
+ const boost::optional<UUID>& expectedUUID,
const IndexArgument& index) {
// We only need to hold an intent lock to send abort signals to the active index builder(s) we
// intend to abort.
boost::optional<AutoGetCollection> collection;
collection.emplace(opCtx, nss, MODE_IX);
+ checkCollectionUUIDMismatch(opCtx, collection->getCollection(), expectedUUID);
uassertStatusOK(checkView(opCtx, nss, collection->getCollection()));
+
const UUID collectionUUID = (*collection)->uuid();
const NamespaceStringOrUUID dbAndUUID = {nss.db().toString(), collectionUUID};
uassertStatusOK(checkReplState(opCtx, dbAndUUID, collection->getCollection()));
diff --git a/src/mongo/db/catalog/drop_indexes.h b/src/mongo/db/catalog/drop_indexes.h
index 74b90d75384..f0fa9dad5ef 100644
--- a/src/mongo/db/catalog/drop_indexes.h
+++ b/src/mongo/db/catalog/drop_indexes.h
@@ -52,6 +52,7 @@ using IndexArgument = stdx::variant<std::string, std::vector<std::string>, mongo
*/
DropIndexesReply dropIndexes(OperationContext* opCtx,
const NamespaceString& nss,
+ const boost::optional<UUID>& expectedUUID,
const IndexArgument& index);
/**
diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp
index aee568e6045..99f44396f33 100644
--- a/src/mongo/db/commands/create_indexes.cpp
+++ b/src/mongo/db/commands/create_indexes.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/catalog/clustered_collection_util.h"
#include "mongo/db/catalog/collection.h"
+#include "mongo/db/catalog/collection_uuid_mismatch.h"
#include "mongo/db/catalog/create_collection.h"
#include "mongo/db/catalog/database.h"
#include "mongo/db/catalog/database_holder.h"
@@ -440,6 +441,8 @@ CreateIndexesReply runCreateIndexesWithCoordinator(OperationContext* opCtx,
AutoGetCollection collection(opCtx, ns, MODE_IS);
CollectionShardingState::get(opCtx, ns)->checkShardVersionOrThrow(opCtx);
+ checkCollectionUUIDMismatch(opCtx, collection.getCollection(), cmd.getCollectionUUID());
+
// Before potentially taking an exclusive collection lock, check if all indexes already
// exist while holding an intent lock.
if (collection &&
diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp
index 3ccdc62c09a..9dd71eeefb0 100644
--- a/src/mongo/db/commands/drop_indexes.cpp
+++ b/src/mongo/db/commands/drop_indexes.cpp
@@ -102,10 +102,16 @@ public:
opCtx, request().getNamespace(), !isCommandOnTimeseriesBucketNamespace)) {
auto timeseriesCmd =
timeseries::makeTimeseriesDropIndexesCommand(opCtx, request(), *options);
- return dropIndexes(opCtx, timeseriesCmd.getNamespace(), timeseriesCmd.getIndex());
+ return dropIndexes(opCtx,
+ timeseriesCmd.getNamespace(),
+ request().getCollectionUUID(),
+ timeseriesCmd.getIndex());
}
- return dropIndexes(opCtx, request().getNamespace(), request().getIndex());
+ return dropIndexes(opCtx,
+ request().getNamespace(),
+ request().getCollectionUUID(),
+ request().getIndex());
}
};
} cmdDropIndexes;
diff --git a/src/mongo/db/create_indexes.idl b/src/mongo/db/create_indexes.idl
index 5a13227dd8c..d00b8f75801 100644
--- a/src/mongo/db/create_indexes.idl
+++ b/src/mongo/db/create_indexes.idl
@@ -226,3 +226,8 @@ commands:
type: bool
optional: true
unstable: false
+ collectionUUID:
+ type: uuid
+ description: "The expected UUID of the collection."
+ optional: true
+ unstable: true
diff --git a/src/mongo/db/drop_indexes.idl b/src/mongo/db/drop_indexes.idl
index ae4c9fe8fd1..a8e60f78a9f 100644
--- a/src/mongo/db/drop_indexes.idl
+++ b/src/mongo/db/drop_indexes.idl
@@ -81,4 +81,9 @@ commands:
type: bool
optional: true
unstable: false
+ collectionUUID:
+ type: uuid
+ description: "The expected UUID of the collection."
+ optional: true
+ unstable: true
reply_type: DropIndexesReply
diff --git a/src/mongo/dbtests/storage_timestamp_tests.cpp b/src/mongo/dbtests/storage_timestamp_tests.cpp
index 33f4a23b6f8..9622e723b80 100644
--- a/src/mongo/dbtests/storage_timestamp_tests.cpp
+++ b/src/mongo/dbtests/storage_timestamp_tests.cpp
@@ -2695,7 +2695,7 @@ public:
const LogicalTime beforeDropTs = currentTime.clusterTime();
// Drop all of the indexes.
- dropIndexes(_opCtx, nss, "*");
+ dropIndexes(_opCtx, nss, boost::none, "*");
// Assert that each index is dropped individually and with its own timestamp. The order of
// dropping and creating are not guaranteed to be the same, but assert all of the created
@@ -2770,7 +2770,7 @@ public:
const LogicalTime beforeDropTs = currentTime.clusterTime();
// Drop all of the indexes.
- dropIndexes(_opCtx, nss, std::vector<std::string>{"a_1", "b_1", "c_1"});
+ dropIndexes(_opCtx, nss, boost::none, std::vector<std::string>{"a_1", "b_1", "c_1"});
// Assert that each index is dropped individually and with its own timestamp. The order of
// dropping and creating are not guaranteed to be the same, but assert all of the created
diff --git a/src/mongo/s/cluster_commands_helpers.cpp b/src/mongo/s/cluster_commands_helpers.cpp
index 35b351556da..c5e73bfe707 100644
--- a/src/mongo/s/cluster_commands_helpers.cpp
+++ b/src/mongo/s/cluster_commands_helpers.cpp
@@ -621,6 +621,10 @@ RawResponsesResult appendRawResponses(
output->append("code", firstError.code());
output->append("codeName", ErrorCodes::errorString(firstError.code()));
*errmsg = firstError.reason();
+ if (auto extra = firstError.extraInfo()) {
+ extra->serialize(output);
+ }
+
return {false, shardsWithSuccessResponses, successARSResponses, firstStaleConfigErrorReceived};
}