summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/sharding/timeseries_coll_mod.js2
-rw-r--r--src/mongo/db/commands/set_feature_compatibility_version_command.cpp9
-rw-r--r--src/mongo/db/s/collmod_coordinator.cpp43
-rw-r--r--src/mongo/db/s/collmod_coordinator.h3
-rw-r--r--src/mongo/db/s/collmod_coordinator_document.idl1
-rw-r--r--src/mongo/db/s/sharding_ddl_coordinator.idl4
-rw-r--r--src/mongo/db/s/sharding_ddl_coordinator_service.cpp2
-rw-r--r--src/mongo/db/s/shardsvr_collmod_command.cpp26
-rw-r--r--src/mongo/s/sharding_feature_flags.idl5
9 files changed, 78 insertions, 17 deletions
diff --git a/jstests/sharding/timeseries_coll_mod.js b/jstests/sharding/timeseries_coll_mod.js
index a4aa23bcc01..08e882ef64a 100644
--- a/jstests/sharding/timeseries_coll_mod.js
+++ b/jstests/sharding/timeseries_coll_mod.js
@@ -74,6 +74,7 @@ function runBasicTest() {
assert.eq(getGranularity(), 'minutes');
assert.commandWorked(db.runCommand({collMod: collName, timeseries: {granularity: 'hours'}}));
assert.eq(getGranularity(), 'hours');
+ assert.eq(0, st.config.collections.countDocuments({allowMigrations: {$exists: true}}));
st.stop();
}
@@ -155,6 +156,7 @@ function runReadAfterWriteTest() {
// Assert that we can use 'hours' granularity and find both documents through mongos1.
assert.eq(mongos1.getDB(dbName).getCollection(collName).countDocuments({[timeField]: time}), 2);
+ assert.eq(0, st.config.collections.countDocuments({allowMigrations: {$exists: true}}));
st.stop();
}
diff --git a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
index 211286e2dbd..f7ed910e167 100644
--- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
+++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
@@ -350,6 +350,15 @@ public:
if (request.getPhase() == SetFCVPhaseEnum::kStart) {
invariant(serverGlobalParams.clusterRole == ClusterRole::ShardServer);
+ // TODO SERVER-68008: Remove collMod draining mechanism after 7.0 becomes last LTS.
+ if (actualVersion > requestedVersion &&
+ !feature_flags::gCollModCoordinatorV3.isEnabledOnVersion(requestedVersion)) {
+ // Drain all running collMod v3 coordinator because they produce backward
+ // incompatible on disk metadata
+ ShardingDDLCoordinatorService::getService(opCtx)
+ ->waitForCoordinatorsOfGivenTypeToComplete(
+ opCtx, DDLCoordinatorTypeEnum::kCollMod);
+ }
// If we are only running phase-1, then we are done
return true;
}
diff --git a/src/mongo/db/s/collmod_coordinator.cpp b/src/mongo/db/s/collmod_coordinator.cpp
index f59d350e827..06e8cd028dd 100644
--- a/src/mongo/db/s/collmod_coordinator.cpp
+++ b/src/mongo/db/s/collmod_coordinator.cpp
@@ -97,6 +97,11 @@ void CollModCoordinator::appendCommandInfo(BSONObjBuilder* cmdInfoBuilder) const
cmdInfoBuilder->appendElements(_request.toBSON());
};
+// TODO SERVER-68008 Remove once 7.0 becomes last LTS
+bool CollModCoordinator::_isPre61Compatible() const {
+ return operationType() == DDLCoordinatorTypeEnum::kCollModPre61Compatible;
+}
+
void CollModCoordinator::_performNoopRetryableWriteOnParticipants(
OperationContext* opCtx, const std::shared_ptr<executor::TaskExecutor>& executor) {
auto shardsAndConfigsvr = [&] {
@@ -174,6 +179,26 @@ ExecutorFuture<void> CollModCoordinator::_runImpl(
*_request.getTimeseries()->getGranularity()));
}
})
+ .then([this, executor = executor, anchor = shared_from_this()] {
+ if (_isPre61Compatible()) {
+ return;
+ }
+ _executePhase(
+ Phase::kFreezeMigrations, [this, executor = executor, anchor = shared_from_this()] {
+ auto opCtxHolder = cc().makeOperationContext();
+ auto* opCtx = opCtxHolder.get();
+ getForwardableOpMetadata().setOn(opCtx);
+
+ _saveCollectionInfoOnCoordinatorIfNecessary(opCtx);
+
+ if (_collInfo->isSharded) {
+ _doc.setCollUUID(
+ sharding_ddl_util::getCollectionUUID(opCtx, _collInfo->nsForTargeting));
+ sharding_ddl_util::stopMigrations(
+ opCtx, _collInfo->nsForTargeting, _doc.getCollUUID());
+ }
+ });
+ })
.then(_executePhase(
Phase::kBlockShards,
[this, executor = executor, anchor = shared_from_this()] {
@@ -185,10 +210,7 @@ ExecutorFuture<void> CollModCoordinator::_runImpl(
_saveCollectionInfoOnCoordinatorIfNecessary(opCtx);
- if (_collInfo->isSharded) {
- // TODO SERVER-67686 use the translated namespace `_collInfo->nsForTargeting`
- // here so that in case of timeseries collection we block migrations on the
- // bucket namespace and not the timeseries view namespace `originalNss()`
+ if (_isPre61Compatible() && _collInfo->isSharded) {
_doc.setCollUUID(sharding_ddl_util::getCollectionUUID(
opCtx, originalNss(), true /* allowViews */));
sharding_ddl_util::stopMigrations(opCtx, originalNss(), _doc.getCollUUID());
@@ -290,7 +312,10 @@ ExecutorFuture<void> CollModCoordinator::_runImpl(
CommandHelpers::appendSimpleCommandStatus(builder, ok, errmsg);
}
_result = builder.obj();
- sharding_ddl_util::resumeMigrations(opCtx, originalNss(), _doc.getCollUUID());
+ sharding_ddl_util::resumeMigrations(
+ opCtx,
+ _isPre61Compatible() ? originalNss() : _collInfo->nsForTargeting,
+ _doc.getCollUUID());
} else {
CollMod cmd(originalNss());
cmd.setCollModRequest(_request);
@@ -325,10 +350,10 @@ ExecutorFuture<void> CollModCoordinator::_runImpl(
auto* opCtx = opCtxHolder.get();
getForwardableOpMetadata().setOn(opCtx);
- // TODO SERVER-67686 use the translated namespace `_collInfo->nsForTargeting`
- // here so that in case of timeseries collection we unblock migrations on the
- // bucket namespace and not the timeseries view namespace `originalNss()`
- sharding_ddl_util::resumeMigrations(opCtx, originalNss(), _doc.getCollUUID());
+ sharding_ddl_util::resumeMigrations(
+ opCtx,
+ _isPre61Compatible() ? originalNss() : _collInfo->nsForTargeting,
+ _doc.getCollUUID());
}
}
return status;
diff --git a/src/mongo/db/s/collmod_coordinator.h b/src/mongo/db/s/collmod_coordinator.h
index 4b65502f78d..d27f981c93e 100644
--- a/src/mongo/db/s/collmod_coordinator.h
+++ b/src/mongo/db/s/collmod_coordinator.h
@@ -88,6 +88,9 @@ private:
void _saveShardingInfoOnCoordinatorIfNecessary(OperationContext* opCtx);
+ // TODO SERVER-68008 Remove once 7.0 becomes last LTS
+ bool _isPre61Compatible() const;
+
const mongo::CollModRequest _request;
boost::optional<BSONObj> _result;
diff --git a/src/mongo/db/s/collmod_coordinator_document.idl b/src/mongo/db/s/collmod_coordinator_document.idl
index 1f2bc418e34..e77d1b8a9e7 100644
--- a/src/mongo/db/s/collmod_coordinator_document.idl
+++ b/src/mongo/db/s/collmod_coordinator_document.idl
@@ -46,6 +46,7 @@ enums:
type: string
values:
kUnset: "unset"
+ kFreezeMigrations: "FreezeMigrations"
kBlockShards: "BlockShards"
kUpdateConfig: "UpdateConfig"
kUpdateShards: "UpdateShards"
diff --git a/src/mongo/db/s/sharding_ddl_coordinator.idl b/src/mongo/db/s/sharding_ddl_coordinator.idl
index 2f0b23af57f..89ae4cd6fb6 100644
--- a/src/mongo/db/s/sharding_ddl_coordinator.idl
+++ b/src/mongo/db/s/sharding_ddl_coordinator.idl
@@ -50,7 +50,9 @@ enums:
kCreateCollection: "createCollection_V2"
kRefineCollectionShardKey: "refineCollectionShardKey"
kSetAllowMigrations: "setAllowMigrations"
- kCollMod: "collMod_V2"
+ kCollMod: "collMod_V3"
+ # TODO SERVER-68008: Remove once 7.0 becomes last LTS
+ kCollModPre61Compatible: "collMod_V2"
kReshardCollection: "reshardCollection"
kCompactStructuredEncryptionData: "compactStructuredEncryptionData"
diff --git a/src/mongo/db/s/sharding_ddl_coordinator_service.cpp b/src/mongo/db/s/sharding_ddl_coordinator_service.cpp
index 101846166a0..954c5cb66c3 100644
--- a/src/mongo/db/s/sharding_ddl_coordinator_service.cpp
+++ b/src/mongo/db/s/sharding_ddl_coordinator_service.cpp
@@ -88,6 +88,8 @@ std::shared_ptr<ShardingDDLCoordinator> constructShardingDDLCoordinatorInstance(
std::move(initialState));
break;
case DDLCoordinatorTypeEnum::kCollMod:
+ case DDLCoordinatorTypeEnum::kCollModPre61Compatible: // TODO SERVER-68008 Remove once 7.0
+ // becomes last LTS
return std::make_shared<CollModCoordinator>(service, std::move(initialState));
break;
case DDLCoordinatorTypeEnum::kReshardCollection:
diff --git a/src/mongo/db/s/shardsvr_collmod_command.cpp b/src/mongo/db/s/shardsvr_collmod_command.cpp
index 503deb5158f..96400a31776 100644
--- a/src/mongo/db/s/shardsvr_collmod_command.cpp
+++ b/src/mongo/db/s/shardsvr_collmod_command.cpp
@@ -33,12 +33,14 @@
#include "mongo/db/coll_mod_gen.h"
#include "mongo/db/coll_mod_reply_validation.h"
#include "mongo/db/commands.h"
+#include "mongo/db/commands/feature_compatibility_version.h"
#include "mongo/db/curop.h"
#include "mongo/db/s/collmod_coordinator.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/s/sharding_util.h"
#include "mongo/db/timeseries/catalog_helper.h"
#include "mongo/logv2/log.h"
+#include "mongo/s/sharding_feature_flags_gen.h"
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding
@@ -102,13 +104,23 @@ public:
CurOp::get(opCtx)->raiseDbProfileLevel(
CollectionCatalog::get(opCtx)->getDatabaseProfileLevel(cmd.getNamespace().dbName()));
- auto coordinatorDoc = CollModCoordinatorDocument();
- coordinatorDoc.setCollModRequest(cmd.getCollModRequest());
- coordinatorDoc.setShardingDDLCoordinatorMetadata(
- {{cmd.getNamespace(), DDLCoordinatorTypeEnum::kCollMod}});
- auto service = ShardingDDLCoordinatorService::getService(opCtx);
- auto collModCoordinator = checked_pointer_cast<CollModCoordinator>(
- service->getOrCreateInstance(opCtx, coordinatorDoc.toBSON()));
+ auto collModCoordinator = [&] {
+ FixedFCVRegion fcvRegion(opCtx);
+ auto coordinatorType = DDLCoordinatorTypeEnum::kCollMod;
+ if (!feature_flags::gCollModCoordinatorV3.isEnabled(
+ serverGlobalParams.featureCompatibility)) {
+ // TODO SERVER-68008 Remove once 7.0 becomes last LTS
+ coordinatorType = DDLCoordinatorTypeEnum::kCollModPre61Compatible;
+ }
+ auto coordinatorDoc = CollModCoordinatorDocument();
+ coordinatorDoc.setCollModRequest(cmd.getCollModRequest());
+ coordinatorDoc.setShardingDDLCoordinatorMetadata(
+ {{cmd.getNamespace(), coordinatorType}});
+ auto service = ShardingDDLCoordinatorService::getService(opCtx);
+ return checked_pointer_cast<CollModCoordinator>(
+ service->getOrCreateInstance(opCtx, coordinatorDoc.toBSON()));
+ }();
+
result.appendElements(collModCoordinator->getResult(opCtx));
return true;
}
diff --git a/src/mongo/s/sharding_feature_flags.idl b/src/mongo/s/sharding_feature_flags.idl
index e2c4040dcc8..17cf03d4771 100644
--- a/src/mongo/s/sharding_feature_flags.idl
+++ b/src/mongo/s/sharding_feature_flags.idl
@@ -55,3 +55,8 @@ feature_flags:
description: "Feature flag protecting instantiation and usages of the range deleter service"
cpp_varname: feature_flags::gRangeDeleterService
default: false
+ featureFlagCollModCoordinatorV3:
+ description: "Feature for enabling new coll mod coordinator v3"
+ cpp_varname: feature_flags::gCollModCoordinatorV3
+ default: true
+ version: 6.1