summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/drop_indexes.cpp
diff options
context:
space:
mode:
authorArun Banala <arun.banala@mongodb.com>2021-08-25 15:53:30 +0100
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-08-31 16:18:15 +0000
commitdb491c42fffd8af3ceee9e39750913f613186ecb (patch)
tree47be35501ccc5a8c90ad3077f3fb1187f78ef5c6 /src/mongo/db/commands/drop_indexes.cpp
parenta88433c2c78516e30b1356404df5cf977fe37c31 (diff)
downloadmongo-db491c42fffd8af3ceee9e39750913f613186ecb.tar.gz
SERVER-57572 Rewrite secondary indexes on mongos for sharded time-series collections
Diffstat (limited to 'src/mongo/db/commands/drop_indexes.cpp')
-rw-r--r--src/mongo/db/commands/drop_indexes.cpp46
1 files changed, 5 insertions, 41 deletions
diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp
index 606b630fd4b..781e71259e6 100644
--- a/src/mongo/db/commands/drop_indexes.cpp
+++ b/src/mongo/db/commands/drop_indexes.cpp
@@ -51,7 +51,7 @@
#include "mongo/db/index_builds_coordinator.h"
#include "mongo/db/op_observer.h"
#include "mongo/db/service_context.h"
-#include "mongo/db/timeseries/timeseries_index_schema_conversion_functions.h"
+#include "mongo/db/timeseries/timeseries_commands_conversion_helper.h"
#include "mongo/db/timeseries/timeseries_options.h"
#include "mongo/db/vector_clock.h"
#include "mongo/db/views/view_catalog.h"
@@ -65,44 +65,6 @@ namespace {
MONGO_FAIL_POINT_DEFINE(reIndexCrashAfterDrop);
-/**
- * Returns a DropIndexes for dropping indexes on the bucket collection.
- *
- * The 'index' dropIndexes parameter may refer to an index name, or array of names, or "*" for all
- * indexes, or an index spec key (an object). Only the index spec key has to be translated for the
- * bucket collection. The other forms of 'index' can be passed along unmodified.
- *
- * Returns null if 'origCmd' is not for a time-series collection.
- */
-std::unique_ptr<DropIndexes> makeTimeseriesDropIndexesCommand(OperationContext* opCtx,
- const DropIndexes& origCmd) {
- const auto& origNs = origCmd.getNamespace();
-
- auto timeseriesOptions = timeseries::getTimeseriesOptions(opCtx, origNs);
-
- // Return early with null if we are not working with a time-series collection.
- if (!timeseriesOptions) {
- return {};
- }
-
- auto ns = origNs.makeTimeseriesBucketsNamespace();
-
- const auto& origIndex = origCmd.getIndex();
- if (auto keyPtr = stdx::get_if<BSONObj>(&origIndex)) {
- auto bucketsIndexSpecWithStatus =
- timeseries::createBucketsIndexSpecFromTimeseriesIndexSpec(*timeseriesOptions, *keyPtr);
-
- uassert(ErrorCodes::IndexNotFound,
- str::stream() << bucketsIndexSpecWithStatus.getStatus().toString()
- << " Command request: " << redact(origCmd.toBSON({})),
- bucketsIndexSpecWithStatus.isOK());
-
- return std::make_unique<DropIndexes>(ns, std::move(bucketsIndexSpecWithStatus.getValue()));
- }
-
- return std::make_unique<DropIndexes>(ns, origIndex);
-}
-
class CmdDropIndexes : public DropIndexesCmdVersion1Gen<CmdDropIndexes> {
public:
AllowedOnSecondary secondaryAllowed(ServiceContext*) const override {
@@ -134,8 +96,10 @@ public:
Reply typedRun(OperationContext* opCtx) final {
// If the request namespace refers to a time-series collection, transform the user
// time-series index request to one on the underlying bucket.
- if (auto timeseriesCmd = makeTimeseriesDropIndexesCommand(opCtx, request())) {
- return dropIndexes(opCtx, timeseriesCmd->getNamespace(), timeseriesCmd->getIndex());
+ if (auto options = timeseries::getTimeseriesOptions(opCtx, request().getNamespace())) {
+ auto timeseriesCmd =
+ timeseries::makeTimeseriesDropIndexesCommand(opCtx, request(), *options);
+ return dropIndexes(opCtx, timeseriesCmd.getNamespace(), timeseriesCmd.getIndex());
}
return dropIndexes(opCtx, request().getNamespace(), request().getIndex());