summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2022-08-09 22:13:26 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-09 22:38:12 +0000
commit183c7ba5e53452fb18408f120b1f00ae15d94630 (patch)
treed5a5e5afa638ba72e3700e5552e70c4b79700184 /src
parentfdf8ebad385373697ba8ee72993ca662290369e0 (diff)
downloadmongo-183c7ba5e53452fb18408f120b1f00ae15d94630.tar.gz
SERVER-68495 Update resharded zones after kCommitting transition.
Attempting to update the namespace of the config.tags documents may otherwise repeatedly fail with a WriteConflict due to WT cache eviction aborting the transaction. (cherry picked from commit 41c45d0d0725f3e9745469755fe8beacb24b9c5e)
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/s/resharding/resharding_coordinator_service.cpp51
-rw-r--r--src/mongo/db/s/resharding/resharding_coordinator_service.h6
-rw-r--r--src/mongo/db/s/resharding/resharding_coordinator_test.cpp2
-rw-r--r--src/mongo/s/write_ops/batched_command_request.cpp6
-rw-r--r--src/mongo/s/write_ops/batched_command_request.h3
5 files changed, 39 insertions, 29 deletions
diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
index 03661628885..2c1db827a34 100644
--- a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
+++ b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
@@ -518,24 +518,6 @@ void removeChunkAndTagsDocs(OperationContext* opCtx,
opCtx, TagsType::ConfigNS, tagsQuery, kMajorityWriteConcern, tagDeleteOperationHint));
}
-void updateChunkAndTagsDocsForTempNss(OperationContext* opCtx,
- const ReshardingCoordinatorDocument& coordinatorDoc,
- OID newCollectionEpoch,
- TxnNumber txnNumber) {
- auto tagsRequest = BatchedCommandRequest::buildUpdateOp(
- TagsType::ConfigNS,
- BSON(TagsType::ns(coordinatorDoc.getTempReshardingNss().ns())), // query
- BSON("$set" << BSON("ns" << coordinatorDoc.getSourceNss().ns())), // update
- false, // upsert
- true // multi
- );
-
- // Update the 'ns' field to be the original collection namespace for all tags documents that
- // currently have 'ns' as the temporary collection namespace
- auto tagsRes = ShardingCatalogManager::get(opCtx)->writeToConfigDocumentInTxn(
- opCtx, TagsType::ConfigNS, tagsRequest, txnNumber);
-}
-
/**
* Executes metadata changes in a transaction without bumping the collection version.
*/
@@ -626,11 +608,29 @@ void writeDecisionPersistedState(OperationContext* opCtx,
// shard key, new epoch, and new UUID
updateConfigCollectionsForOriginalNss(
opCtx, coordinatorDoc, newCollectionEpoch, newCollectionTimestamp, txnNumber);
-
- updateChunkAndTagsDocsForTempNss(opCtx, coordinatorDoc, newCollectionEpoch, txnNumber);
});
}
+void updateTagsDocsForTempNss(OperationContext* opCtx,
+ const ReshardingCoordinatorDocument& coordinatorDoc) {
+ auto hint = BSON("ns" << 1 << "min" << 1);
+ auto tagsRequest = BatchedCommandRequest::buildUpdateOp(
+ TagsType::ConfigNS,
+ BSON(TagsType::ns(coordinatorDoc.getTempReshardingNss().ns())), // query
+ BSON("$set" << BSON("ns" << coordinatorDoc.getSourceNss().ns())), // update
+ false, // upsert
+ true, // multi
+ hint // hint
+ );
+
+ // Update the 'ns' field to be the original collection namespace for all tags documents that
+ // currently have 'ns' as the temporary collection namespace.
+ DBDirectClient client(opCtx);
+ BSONObj tagsRes;
+ client.runCommand(tagsRequest.getNS().db().toString(), tagsRequest.toBSON(), tagsRes);
+ uassertStatusOK(getStatusFromWriteCommandReply(tagsRes));
+}
+
void insertCoordDocAndChangeOrigCollEntry(OperationContext* opCtx,
const ReshardingCoordinatorDocument& coordinatorDoc) {
ShardingCatalogManager::get(opCtx)->bumpCollectionVersionAndChangeMetadataInTxn(
@@ -1252,7 +1252,10 @@ ReshardingCoordinatorService::ReshardingCoordinator::_commitAndFinishReshardOper
return resharding::WithAutomaticRetry([this, executor, updatedCoordinatorDoc] {
return ExecutorFuture<void>(**executor)
.then([this, executor, updatedCoordinatorDoc] {
- return _commit(updatedCoordinatorDoc);
+ _commit(updatedCoordinatorDoc);
+
+ auto opCtx = _cancelableOpCtxFactory->makeOperationContext(&cc());
+ resharding::updateTagsDocsForTempNss(opCtx.get(), updatedCoordinatorDoc);
})
.then([this] { return _waitForMajority(_ctHolder->getStepdownToken()); })
.thenRunOn(**executor)
@@ -1755,11 +1758,11 @@ ReshardingCoordinatorService::ReshardingCoordinator::_awaitAllRecipientsInStrict
.thenRunOn(**executor);
}
-Future<void> ReshardingCoordinatorService::ReshardingCoordinator::_commit(
+void ReshardingCoordinatorService::ReshardingCoordinator::_commit(
const ReshardingCoordinatorDocument& coordinatorDoc) {
if (_coordinatorDoc.getState() > CoordinatorStateEnum::kBlockingWrites) {
invariant(_coordinatorDoc.getState() != CoordinatorStateEnum::kAborting);
- return Status::OK();
+ return;
}
ReshardingCoordinatorDocument updatedCoordinatorDoc = coordinatorDoc;
@@ -1785,8 +1788,6 @@ Future<void> ReshardingCoordinatorService::ReshardingCoordinator::_commit(
// Update the in memory state
installCoordinatorDoc(opCtx.get(), updatedCoordinatorDoc);
-
- return Status::OK();
}
ExecutorFuture<void>
diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service.h b/src/mongo/db/s/resharding/resharding_coordinator_service.h
index edfdc312cb1..bf6e975718d 100644
--- a/src/mongo/db/s/resharding/resharding_coordinator_service.h
+++ b/src/mongo/db/s/resharding/resharding_coordinator_service.h
@@ -59,6 +59,9 @@ void writeDecisionPersistedState(OperationContext* opCtx,
OID newCollectionEpoch,
Timestamp newCollectionTimestamp);
+void updateTagsDocsForTempNss(OperationContext* opCtx,
+ const ReshardingCoordinatorDocument& coordinatorDoc);
+
void insertCoordDocAndChangeOrigCollEntry(OperationContext* opCtx,
const ReshardingCoordinatorDocument& coordinatorDoc);
@@ -399,11 +402,10 @@ private:
* Does the following writes:
* 1. Updates the config.collections entry for the new sharded collection
* 2. Updates config.chunks entries for the new sharded collection
- * 3. Updates config.tags for the new sharded collection
*
* Transitions to 'kCommitting'.
*/
- Future<void> _commit(const ReshardingCoordinatorDocument& updatedDoc);
+ void _commit(const ReshardingCoordinatorDocument& updatedDoc);
/**
* Waits on _reshardingCoordinatorObserver to notify that:
diff --git a/src/mongo/db/s/resharding/resharding_coordinator_test.cpp b/src/mongo/db/s/resharding/resharding_coordinator_test.cpp
index 1b28740050e..4017312d6b2 100644
--- a/src/mongo/db/s/resharding/resharding_coordinator_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_coordinator_test.cpp
@@ -615,6 +615,8 @@ protected:
writeDecisionPersistedState(
operationContext(), expectedCoordinatorDoc, _finalEpoch, _finalTimestamp);
+ updateTagsDocsForTempNss(operationContext(), expectedCoordinatorDoc);
+
// Check that config.reshardingOperations and config.collections entries are updated
// correctly
assertStateAndCatalogEntriesMatchExpected(opCtx, expectedCoordinatorDoc, _finalEpoch);
diff --git a/src/mongo/s/write_ops/batched_command_request.cpp b/src/mongo/s/write_ops/batched_command_request.cpp
index f274e69482f..297d6022566 100644
--- a/src/mongo/s/write_ops/batched_command_request.cpp
+++ b/src/mongo/s/write_ops/batched_command_request.cpp
@@ -266,7 +266,8 @@ BatchedCommandRequest BatchedCommandRequest::buildUpdateOp(const NamespaceString
const BSONObj& query,
const BSONObj& update,
bool upsert,
- bool multi) {
+ bool multi,
+ const boost::optional<BSONObj>& hint) {
return BatchedCommandRequest([&] {
write_ops::UpdateCommandRequest updateOp(nss);
updateOp.setUpdates({[&] {
@@ -275,6 +276,9 @@ BatchedCommandRequest BatchedCommandRequest::buildUpdateOp(const NamespaceString
entry.setU(write_ops::UpdateModification::parseFromClassicUpdate(update));
entry.setUpsert(upsert);
entry.setMulti(multi);
+ if (hint) {
+ entry.setHint(hint.value());
+ }
return entry;
}()});
return updateOp;
diff --git a/src/mongo/s/write_ops/batched_command_request.h b/src/mongo/s/write_ops/batched_command_request.h
index cac280533e8..7c58cbda271 100644
--- a/src/mongo/s/write_ops/batched_command_request.h
+++ b/src/mongo/s/write_ops/batched_command_request.h
@@ -175,7 +175,8 @@ public:
const BSONObj& query,
const BSONObj& update,
bool upsert,
- bool multi);
+ bool multi,
+ const boost::optional<BSONObj>& hint = boost::none);
/**
* Returns batch of pipeline update operations to be attached to a transaction