summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2022-05-17 14:22:34 +0000
committerRandolph Tan <randolph@10gen.com>2022-05-18 13:17:23 -0400
commit8035d1b6c19437528e6e58717283636d56dd962e (patch)
tree5216a0550af51f363ad99475a1ea7e7ae6a7092c
parentd9c20985e261581434eaaed05962a2f4c54819bb (diff)
downloadmongo-8035d1b6c19437528e6e58717283636d56dd962e.tar.gz
SERVER-66264 shardsvrDropIndex should use timeseries namespace in the shardVersionRetry loop
(cherry picked from commit d5a929be4f4604497a07186e72d477f8c1b7e7a6)
-rw-r--r--etc/backports_required_for_multiversion_tests.yml4
-rw-r--r--jstests/sharding/timeseries_multiple_mongos.js7
-rw-r--r--src/mongo/db/s/shardsvr_drop_indexes_command.cpp113
3 files changed, 69 insertions, 55 deletions
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml
index 45dfac12e7a..04b72bd3329 100644
--- a/etc/backports_required_for_multiversion_tests.yml
+++ b/etc/backports_required_for_multiversion_tests.yml
@@ -220,6 +220,8 @@ last-continuous:
test_file: jstests/replsets/initial_sync_with_partial_transaction.js
- ticket: SERVER-65947
test_file: jstests/sharding/migration_retries_on_write_conflict_exceptions.js
+ - ticket: SERVER-66264
+ test_file: jstests/sharding/timeseries_multiple_mongos.js
# Tests that should only be excluded from particular suites should be listed under that suite.
suites:
@@ -575,6 +577,8 @@ last-lts:
test_file: jstests/replsets/initial_sync_with_partial_transaction.js
- ticket: SERVER-65947
test_file: jstests/sharding/migration_retries_on_write_conflict_exceptions.js
+ - ticket: SERVER-66264
+ test_file: jstests/sharding/timeseries_multiple_mongos.js
# Tests that should only be excluded from particular suites should be listed under that suite.
suites:
diff --git a/jstests/sharding/timeseries_multiple_mongos.js b/jstests/sharding/timeseries_multiple_mongos.js
index 0a99e52dbe3..dbf88f6fa56 100644
--- a/jstests/sharding/timeseries_multiple_mongos.js
+++ b/jstests/sharding/timeseries_multiple_mongos.js
@@ -60,6 +60,7 @@ function runTest({shardKey, cmdObj, numProfilerEntries}) {
const isDelete = cmdObj["delete"] !== undefined;
const isUpdate = cmdObj["update"] !== undefined;
const isCollMod = cmdObj["collMod"] !== undefined;
+ const isDropIndex = cmdObj["dropIndexes"] !== undefined;
const cmdCollName = cmdObj[Object.keys(cmdObj)[0]];
const shardKeyHasMetaField = shardKey[metaField] !== undefined;
@@ -174,8 +175,10 @@ function runTest({shardKey, cmdObj, numProfilerEntries}) {
assert.commandWorked(mongos0.createCollection(
collName, {timeseries: {timeField: timeField, metaField: metaField}}));
- // When unsharded, the command should be run against the user requested namespace.
- validateCommand(cmdCollName, numProfilerEntries.unsharded, true);
+ // When unsharded, the command should be run against the user requested namespace, except for
+ // dropIndex.
+ validateCommand(
+ isDropIndex ? bucketsCollName : cmdCollName, numProfilerEntries.unsharded, true);
}
/**
diff --git a/src/mongo/db/s/shardsvr_drop_indexes_command.cpp b/src/mongo/db/s/shardsvr_drop_indexes_command.cpp
index 0c6d2d4260b..cd1defb11f7 100644
--- a/src/mongo/db/s/shardsvr_drop_indexes_command.cpp
+++ b/src/mongo/db/s/shardsvr_drop_indexes_command.cpp
@@ -36,9 +36,9 @@
#include "mongo/db/s/database_sharding_state.h"
#include "mongo/db/s/dist_lock_manager.h"
#include "mongo/db/s/sharding_state.h"
+#include "mongo/db/timeseries/catalog_helper.h"
#include "mongo/db/timeseries/timeseries_commands_conversion_helper.h"
#include "mongo/logv2/log.h"
-#include "mongo/s/chunk_manager_targeter.h"
#include "mongo/s/cluster_commands_helpers.h"
#include "mongo/s/grid.h"
#include "mongo/s/request_types/sharded_ddl_commands_gen.h"
@@ -159,61 +159,68 @@ ShardsvrDropIndexesCommand::Invocation::Response ShardsvrDropIndexesCommand::Inv
// Check under the dbLock if this is still the primary shard for the database
DatabaseShardingState::checkIsPrimaryShardForDb(opCtx, ns().db());
- auto nsLocalLock = distLockManager->lockDirectLocally(opCtx, ns().ns(), lockTimeout);
+ auto resolvedNs = ns();
+ auto dropIdxBSON = dropIdxCmd.toBSON({});
- StaleConfigRetryState retryState;
- return shardVersionRetry(opCtx, Grid::get(opCtx)->catalogCache(), ns(), "dropIndexes", [&] {
- // If the collection is sharded, we target only the primary shard and the shards that own
- // chunks for the collection.
- auto targeter = ChunkManagerTargeter(opCtx, ns());
- auto routingInfo = targeter.getRoutingInfo();
-
- auto cmdToBeSent = dropIdxCmd.toBSON({});
- if (targeter.timeseriesNamespaceNeedsRewrite(ns())) {
- cmdToBeSent =
- timeseries::makeTimeseriesCommand(cmdToBeSent,
- ns(),
- DropIndexes::kCommandName,
- DropIndexes::kIsTimeseriesNamespaceFieldName);
- }
+ if (auto timeseriesOptions = timeseries::getTimeseriesOptions(opCtx, ns(), true)) {
+ dropIdxBSON =
+ timeseries::makeTimeseriesCommand(dropIdxBSON,
+ ns(),
+ DropIndexes::kCommandName,
+ DropIndexes::kIsTimeseriesNamespaceFieldName);
- cmdToBeSent = CommandHelpers::filterCommandRequestForPassthrough(
- CommandHelpers::appendMajorityWriteConcern(cmdToBeSent));
-
- auto shardResponses =
- scatterGatherVersionedTargetByRoutingTableNoThrowOnStaleShardVersionErrors(
- opCtx,
- ns().db(),
- targeter.getNS(),
- routingInfo,
- retryState.shardsWithSuccessResponses,
- applyReadWriteConcern(
- opCtx, this, CommandHelpers::filterCommandRequestForPassthrough(cmdToBeSent)),
- ReadPreferenceSetting::get(opCtx),
- Shard::RetryPolicy::kNotIdempotent,
- BSONObj() /* query */,
- BSONObj() /* collation */);
-
- // Append responses we've received from previous retries of this operation due to a stale
- // config error.
- shardResponses.insert(shardResponses.end(),
- retryState.shardSuccessResponses.begin(),
- retryState.shardSuccessResponses.end());
-
- std::string errmsg;
- BSONObjBuilder output;
- const auto aggregateResponse =
- appendRawResponses(opCtx, &errmsg, &output, std::move(shardResponses));
-
- // If we have a stale config error, update the success shards for the upcoming retry.
- if (!aggregateResponse.responseOK && aggregateResponse.firstStaleConfigError) {
- updateStateForStaleConfigRetry(opCtx, aggregateResponse, &retryState);
- uassertStatusOK(*aggregateResponse.firstStaleConfigError);
- }
+ resolvedNs = ns().makeTimeseriesBucketsNamespace();
+ }
+
+ auto nsLocalLock = distLockManager->lockDirectLocally(opCtx, resolvedNs.ns(), lockTimeout);
+
+ StaleConfigRetryState retryState;
+ return shardVersionRetry(
+ opCtx, Grid::get(opCtx)->catalogCache(), resolvedNs, "dropIndexes", [&] {
+ // If the collection is sharded, we target only the primary shard and the shards that
+ // own chunks for the collection.
+ const auto routingInfo = uassertStatusOK(
+ Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, resolvedNs));
+
+ auto cmdToBeSent = CommandHelpers::filterCommandRequestForPassthrough(
+ CommandHelpers::appendMajorityWriteConcern(dropIdxBSON));
+
+ auto shardResponses =
+ scatterGatherVersionedTargetByRoutingTableNoThrowOnStaleShardVersionErrors(
+ opCtx,
+ resolvedNs.db(),
+ resolvedNs,
+ routingInfo,
+ retryState.shardsWithSuccessResponses,
+ applyReadWriteConcern(
+ opCtx,
+ this,
+ CommandHelpers::filterCommandRequestForPassthrough(cmdToBeSent)),
+ ReadPreferenceSetting::get(opCtx),
+ Shard::RetryPolicy::kNotIdempotent,
+ BSONObj() /* query */,
+ BSONObj() /* collation */);
+
+ // Append responses we've received from previous retries of this operation due to a
+ // stale config error.
+ shardResponses.insert(shardResponses.end(),
+ retryState.shardSuccessResponses.begin(),
+ retryState.shardSuccessResponses.end());
+
+ std::string errmsg;
+ BSONObjBuilder output;
+ const auto aggregateResponse =
+ appendRawResponses(opCtx, &errmsg, &output, std::move(shardResponses));
+
+ // If we have a stale config error, update the success shards for the upcoming retry.
+ if (!aggregateResponse.responseOK && aggregateResponse.firstStaleConfigError) {
+ updateStateForStaleConfigRetry(opCtx, aggregateResponse, &retryState);
+ uassertStatusOK(*aggregateResponse.firstStaleConfigError);
+ }
- CommandHelpers::appendSimpleCommandStatus(output, aggregateResponse.responseOK, errmsg);
- return Response(output.obj());
- });
+ CommandHelpers::appendSimpleCommandStatus(output, aggregateResponse.responseOK, errmsg);
+ return Response(output.obj());
+ });
}
} // namespace