summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRui Liu <rui.liu@mongodb.com>2021-09-08 11:21:30 +0100
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-09-22 09:40:23 +0000
commit27d9632d277e63f42752b117ac5e93ac4f0e37a7 (patch)
tree66c9ad8824969309cdd1ca7d0b9f0b264f924374 /src
parent7a0a6ec04debd09d2f6d14612beb14ce78b93ed1 (diff)
downloadmongo-27d9632d277e63f42752b117ac5e93ac4f0e37a7.tar.gz
SERVER-57570 Disable updating granularity on sharded time-series collection
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/commands/SConscript1
-rw-r--r--src/mongo/db/commands/dbcommands.cpp18
-rw-r--r--src/mongo/s/commands/cluster_collection_mod_cmd.cpp7
3 files changed, 23 insertions, 3 deletions
diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript
index cc726b7385f..3ba4712b8ad 100644
--- a/src/mongo/db/commands/SConscript
+++ b/src/mongo/db/commands/SConscript
@@ -375,6 +375,7 @@ env.Library(
'$BUILD_DIR/mongo/executor/async_request_executor',
'$BUILD_DIR/mongo/idl/feature_flag',
'$BUILD_DIR/mongo/rpc/rewrite_state_change_errors',
+ '$BUILD_DIR/mongo/s/grid',
'$BUILD_DIR/mongo/util/log_and_backoff',
'$BUILD_DIR/mongo/util/net/http_client',
'core',
diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp
index 7ce8384eeeb..fbf3dbaad96 100644
--- a/src/mongo/db/commands/dbcommands.cpp
+++ b/src/mongo/db/commands/dbcommands.cpp
@@ -99,6 +99,7 @@
#include "mongo/db/write_concern.h"
#include "mongo/executor/async_request_executor.h"
#include "mongo/logv2/log.h"
+#include "mongo/s/grid.h"
#include "mongo/scripting/engine.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/future.h"
@@ -631,6 +632,23 @@ public:
!cmd->getChangeStreamPreAndPostImages().has_value());
}
+ // Updating granularity on sharded time-series collections is not allowed.
+ if (Grid::get(opCtx)->catalogClient() && cmd->getTimeseries() &&
+ cmd->getTimeseries()->getGranularity()) {
+ auto& nss = cmd->getNamespace();
+ auto bucketNss =
+ nss.isTimeseriesBucketsCollection() ? nss : nss.makeTimeseriesBucketsNamespace();
+ try {
+ auto coll = Grid::get(opCtx)->catalogClient()->getCollection(opCtx, bucketNss);
+ uassert(ErrorCodes::NotImplemented,
+ str::stream()
+ << "Cannot update granularity of a sharded time-series collection.",
+ !coll.getTimeseriesFields());
+ } catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) {
+ // Collection is not sharded, skip check.
+ }
+ }
+
// If the target namespace refers to a time-series collection, we will redirect the
// collection modification request to the underlying bucket collection.
// Aliasing collMod on a time-series collection in this manner has a few advantages:
diff --git a/src/mongo/s/commands/cluster_collection_mod_cmd.cpp b/src/mongo/s/commands/cluster_collection_mod_cmd.cpp
index 0d895756b91..ac369c6a8ba 100644
--- a/src/mongo/s/commands/cluster_collection_mod_cmd.cpp
+++ b/src/mongo/s/commands/cluster_collection_mod_cmd.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/coll_mod_reply_validation.h"
#include "mongo/db/commands.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"
@@ -91,12 +92,12 @@ public:
"namespace"_attr = nss,
"command"_attr = redact(cmdObj));
- auto routingInfo =
- uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss));
+ const auto targeter = ChunkManagerTargeter(opCtx, nss);
+ const auto& routingInfo = targeter.getRoutingInfo();
auto shardResponses = scatterGatherVersionedTargetByRoutingTable(
opCtx,
cmd.getDbName(),
- nss,
+ targeter.getNS(),
routingInfo,
applyReadWriteConcern(
opCtx,