diff options
author | Rui Liu <rui.liu@mongodb.com> | 2021-09-08 11:21:30 +0100 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-09-22 09:40:23 +0000 |
commit | 27d9632d277e63f42752b117ac5e93ac4f0e37a7 (patch) | |
tree | 66c9ad8824969309cdd1ca7d0b9f0b264f924374 /src/mongo/db | |
parent | 7a0a6ec04debd09d2f6d14612beb14ce78b93ed1 (diff) | |
download | mongo-27d9632d277e63f42752b117ac5e93ac4f0e37a7.tar.gz |
SERVER-57570 Disable updating granularity on sharded time-series collection
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/commands/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/commands/dbcommands.cpp | 18 |
2 files changed, 19 insertions, 0 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: |