summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/dbcommands.cpp
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/mongo/db/commands/dbcommands.cpp
parent7a0a6ec04debd09d2f6d14612beb14ce78b93ed1 (diff)
downloadmongo-27d9632d277e63f42752b117ac5e93ac4f0e37a7.tar.gz
SERVER-57570 Disable updating granularity on sharded time-series collection
Diffstat (limited to 'src/mongo/db/commands/dbcommands.cpp')
-rw-r--r--src/mongo/db/commands/dbcommands.cpp18
1 files changed, 18 insertions, 0 deletions
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: