summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMisha Tyulenev <misha.tyulenev@mongodb.com>2022-05-10 14:02:55 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-05-10 17:08:31 +0000
commiteb274d65a49a9ce1e8a75e2ba25c45fa017b4f9c (patch)
tree6ae1beef0544b23460e4be250e799dbcbff0608f /src
parent167fbe34c32640d77d80c1b178379841af7df19f (diff)
downloadmongo-eb274d65a49a9ce1e8a75e2ba25c45fa017b4f9c.tar.gz
SERVER-65908 update fields for reshardCollection noop message
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/s/reshard_collection_coordinator.cpp72
-rw-r--r--src/mongo/db/s/reshard_collection_coordinator_document.idl8
2 files changed, 59 insertions, 21 deletions
diff --git a/src/mongo/db/s/reshard_collection_coordinator.cpp b/src/mongo/db/s/reshard_collection_coordinator.cpp
index a78e4a88447..30ff299e538 100644
--- a/src/mongo/db/s/reshard_collection_coordinator.cpp
+++ b/src/mongo/db/s/reshard_collection_coordinator.cpp
@@ -46,22 +46,49 @@ namespace mongo {
namespace {
-void writeOpLogOnReshardCollectionDone(OperationContext* opCtx,
- const NamespaceString& collNss,
- const KeyPattern& shardKey,
- BSONObj cmd,
- UUID reshardingUUID) {
+void notifyChangeStreamsOnReshardCollectionComplete(OperationContext* opCtx,
+ const NamespaceString& collNss,
+ const ReshardCollectionCoordinatorDocument& doc,
+ const UUID& reshardUUID) {
const std::string oMessage = str::stream()
- << "Reshard collection " << collNss << " with shard key " << shardKey.toString();
+ << "Reshard collection " << collNss << " with shard key " << doc.getKey().toString();
+
+ BSONObjBuilder cmdBuilder;
+ tassert(6590800, "Did not set old collectionUUID", doc.getOldCollectionUUID());
+ tassert(6590801, "Did not set old ShardKey", doc.getOldShardKey());
+ UUID collUUID = *doc.getOldCollectionUUID();
+ cmdBuilder.append("reshardCollection", collNss.ns());
+ reshardUUID.appendToBuilder(&cmdBuilder, "reshardUUID");
+ cmdBuilder.append("shardKey", doc.getKey());
+ cmdBuilder.append("oldShardKey", *doc.getOldShardKey());
+
+ cmdBuilder.append("unique", doc.getUnique().get_value_or(false));
+ if (doc.getNumInitialChunks()) {
+ cmdBuilder.append("numInitialChunks", doc.getNumInitialChunks().get());
+ }
+ if (doc.getCollation()) {
+ cmdBuilder.append("collation", doc.getCollation().get());
+ }
+
+ if (doc.getZones()) {
+ BSONArrayBuilder zonesBSON(cmdBuilder.subarrayStart("zones"));
+ for (const auto& zone : *doc.getZones()) {
+ zonesBSON.append(zone.toBSON());
+ }
+ zonesBSON.doneFast();
+ }
+
auto const serviceContext = opCtx->getClient()->getServiceContext();
+ const auto cmd = cmdBuilder.obj();
+
writeConflictRetry(opCtx, "ReshardCollection", NamespaceString::kRsOplogNamespace.ns(), [&] {
AutoGetOplog oplogWrite(opCtx, OplogAccessMode::kWrite);
WriteUnitOfWork uow(opCtx);
serviceContext->getOpObserver()->onInternalOpMessage(opCtx,
collNss,
- reshardingUUID,
+ collUUID,
BSON("msg" << oMessage),
cmd,
boost::none,
@@ -161,6 +188,20 @@ ExecutorFuture<void> ReshardCollectionCoordinator::_runImpl(
checkCollectionUUIDMismatch(opCtx, nss(), *coll, _doc.getCollectionUUID());
}
+ const auto cmOld = uassertStatusOK(
+ Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(
+ opCtx, nss()));
+
+ if (_persistCoordinatorDocument) {
+ StateDoc newDoc(_doc);
+ newDoc.setOldShardKey(cmOld.getShardKeyPattern().getKeyPattern().toBSON());
+ newDoc.setOldCollectionUUID(cmOld.getUUID());
+ _doc = _updateStateDocument(opCtx, std::move(newDoc));
+ } else {
+ _doc.setOldShardKey(cmOld.getShardKeyPattern().getKeyPattern().toBSON());
+ _doc.setOldCollectionUUID(cmOld.getUUID());
+ }
+
ConfigsvrReshardCollection configsvrReshardCollection(nss(), _doc.getKey());
configsvrReshardCollection.setDbName(nss().db());
configsvrReshardCollection.setUnique(_doc.getUnique());
@@ -187,21 +228,10 @@ ExecutorFuture<void> ReshardCollectionCoordinator::_runImpl(
Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(
opCtx, nss()));
- BSONObjBuilder cmdBuilder;
- cmdBuilder.append("reshardCollection", nss().ns());
- cm.getUUID().appendToBuilder(&cmdBuilder, "reshardUUID");
- cmdBuilder.append("key", _doc.getKey());
-
- cmdBuilder.append("unique", _doc.getUnique().get_value_or(false));
- if (_doc.getNumInitialChunks()) {
- cmdBuilder.append("numInitialChunks", _doc.getNumInitialChunks().get());
- }
- if (_doc.getCollation()) {
- cmdBuilder.append("collation", _doc.getCollation().get());
+ if (_doc.getOldCollectionUUID() && _doc.getOldCollectionUUID() != cm.getUUID()) {
+ notifyChangeStreamsOnReshardCollectionComplete(
+ opCtx, nss(), _doc, cm.getUUID());
}
-
- writeOpLogOnReshardCollectionDone(
- opCtx, nss(), _doc.getKey(), cmdBuilder.obj(), cm.getUUID());
}))
.onError([this, anchor = shared_from_this()](const Status& status) {
LOGV2_ERROR(6206401,
diff --git a/src/mongo/db/s/reshard_collection_coordinator_document.idl b/src/mongo/db/s/reshard_collection_coordinator_document.idl
index 2d3032957b6..e3d9134a8ac 100644
--- a/src/mongo/db/s/reshard_collection_coordinator_document.idl
+++ b/src/mongo/db/s/reshard_collection_coordinator_document.idl
@@ -59,3 +59,11 @@ structs:
type: ReshardCollectionCoordinatorPhase
description: "Coordinator phase."
default: kUnset
+ oldShardKey:
+ type: object
+ description: "The shard key of the collection before resharding."
+ optional: true
+ oldCollectionUUID:
+ type: uuid
+ description: "The UUID of the collection before resharding."
+ optional: true