summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2022-08-09 22:14:15 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-09 22:45:19 +0000
commit71c2798d8749dca09a6d4e6d7838b6cdbe218f2d (patch)
tree6d5c691df636535f4a2480b417cf86dacddd260e
parent05a3cac3162258651b57b0c1e4d40cbac85aa38f (diff)
downloadmongo-71c2798d8749dca09a6d4e6d7838b6cdbe218f2d.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)
-rw-r--r--src/mongo/db/s/resharding/resharding_coordinator_service.cpp53
-rw-r--r--src/mongo/db/s/resharding/resharding_coordinator_service.h6
-rw-r--r--src/mongo/db/s/resharding/resharding_coordinator_test.cpp2
3 files changed, 32 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 134017fafd7..4aca7cd1a7a 100644
--- a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
+++ b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
@@ -522,26 +522,6 @@ void removeChunkAndTagsDocs(OperationContext* opCtx,
opCtx, TagsType::ConfigNS, tagsQuery, kMajorityWriteConcern, tagDeleteOperationHint));
}
-void updateChunkAndTagsDocsForTempNss(OperationContext* opCtx,
- const ReshardingCoordinatorDocument& coordinatorDoc,
- OID newCollectionEpoch,
- TxnNumber txnNumber) {
- 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
- auto tagsRes = ShardingCatalogManager::get(opCtx)->writeToConfigDocumentInTxn(
- opCtx, TagsType::ConfigNS, tagsRequest, txnNumber);
-}
-
/**
* Executes metadata changes in a transaction without bumping the collection version.
*/
@@ -634,11 +614,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(
@@ -1243,7 +1241,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)
@@ -1746,11 +1747,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;
@@ -1776,8 +1777,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 a24569ecc44..9759078eda1 100644
--- a/src/mongo/db/s/resharding/resharding_coordinator_service.h
+++ b/src/mongo/db/s/resharding/resharding_coordinator_service.h
@@ -58,6 +58,9 @@ void writeDecisionPersistedState(OperationContext* opCtx,
OID newCollectionEpoch,
Timestamp newCollectionTimestamp);
+void updateTagsDocsForTempNss(OperationContext* opCtx,
+ const ReshardingCoordinatorDocument& coordinatorDoc);
+
void insertCoordDocAndChangeOrigCollEntry(OperationContext* opCtx,
const ReshardingCoordinatorDocument& coordinatorDoc);
@@ -404,11 +407,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 a8fb4d83889..0c23575f37e 100644
--- a/src/mongo/db/s/resharding/resharding_coordinator_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_coordinator_test.cpp
@@ -619,6 +619,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);