summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/resharding
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2022-08-04 19:26:29 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-04 20:38:04 +0000
commit41c45d0d0725f3e9745469755fe8beacb24b9c5e (patch)
tree664e61162f54cd985d7b93118018a87209f84409 /src/mongo/db/s/resharding
parentf78662269fe4ed8067d0560c99015cb630b02018 (diff)
downloadmongo-41c45d0d0725f3e9745469755fe8beacb24b9c5e.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.
Diffstat (limited to 'src/mongo/db/s/resharding')
-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 6a085b49e47..67bd7c2ba54 100644
--- a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
+++ b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
@@ -565,26 +565,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.
*/
@@ -682,11 +662,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,
ReshardingMetrics* metrics,
const ReshardingCoordinatorDocument& coordinatorDoc) {
@@ -1304,7 +1302,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)
@@ -1807,11 +1808,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;
@@ -1838,8 +1839,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 1dc006cafe1..dcf221d1a3a 100644
--- a/src/mongo/db/s/resharding/resharding_coordinator_service.h
+++ b/src/mongo/db/s/resharding/resharding_coordinator_service.h
@@ -61,6 +61,9 @@ void writeDecisionPersistedState(OperationContext* opCtx,
OID newCollectionEpoch,
Timestamp newCollectionTimestamp);
+void updateTagsDocsForTempNss(OperationContext* opCtx,
+ const ReshardingCoordinatorDocument& coordinatorDoc);
+
void insertCoordDocAndChangeOrigCollEntry(OperationContext* opCtx,
ReshardingMetrics* metrics,
const ReshardingCoordinatorDocument& coordinatorDoc);
@@ -417,11 +420,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 40e6a2296e6..bd6919f02af 100644
--- a/src/mongo/db/s/resharding/resharding_coordinator_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_coordinator_test.cpp
@@ -630,6 +630,8 @@ protected:
_finalEpoch,
_finalTimestamp);
+ updateTagsDocsForTempNss(operationContext(), expectedCoordinatorDoc);
+
// Check that config.reshardingOperations and config.collections entries are updated
// correctly
assertStateAndCatalogEntriesMatchExpected(opCtx, expectedCoordinatorDoc, _finalEpoch);