summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorAntonio Fuschetto <antonio.fuschetto@mongodb.com>2023-04-14 21:44:52 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-04-14 22:41:42 +0000
commit424a3d3cd9f684e47b29595ad5b8098d3a1266b0 (patch)
tree808b35647052040822fb013df88a80d066de2c15 /src/mongo
parent998ca44b7d38ef5939c7550cba5e56361e1c3dd5 (diff)
downloadmongo-424a3d3cd9f684e47b29595ad5b8098d3a1266b0.tar.gz
SERVER-75792 Fix session handling in movePrimary coordinator
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/s/move_primary_coordinator.cpp22
-rw-r--r--src/mongo/db/s/move_primary_coordinator.h4
-rw-r--r--src/mongo/db/s/sharding_ddl_coordinator.h5
3 files changed, 16 insertions, 15 deletions
diff --git a/src/mongo/db/s/move_primary_coordinator.cpp b/src/mongo/db/s/move_primary_coordinator.cpp
index 89b2f12b9a0..80b9e9e20bd 100644
--- a/src/mongo/db/s/move_primary_coordinator.cpp
+++ b/src/mongo/db/s/move_primary_coordinator.cpp
@@ -233,14 +233,13 @@ ExecutorFuture<void> MovePrimaryCoordinator::runMovePrimaryWorkflow(
auto* opCtx = opCtxHolder.get();
getForwardableOpMetadata().setOn(opCtx);
- _updateSession(opCtx);
if (!_firstExecution) {
// Perform a noop write on the recipient in order to
// advance the txnNumber for this coordinator's logical
// session. This prevents requests with older txnNumbers
// from being processed.
_performNoopRetryableWriteOnAllShardsAndConfigsvr(
- opCtx, getCurrentSession(), **executor);
+ opCtx, getNewSession(opCtx), **executor);
}
blockReads(opCtx);
@@ -286,14 +285,13 @@ ExecutorFuture<void> MovePrimaryCoordinator::runMovePrimaryWorkflow(
auto* opCtx = opCtxHolder.get();
getForwardableOpMetadata().setOn(opCtx);
- _updateSession(opCtx);
if (!_firstExecution) {
// Perform a noop write on the recipient in order to
// advance the txnNumber for this coordinator's logical
// session. This prevents requests with older txnNumbers
// from being processed.
_performNoopRetryableWriteOnAllShardsAndConfigsvr(
- opCtx, getCurrentSession(), **executor);
+ opCtx, getNewSession(opCtx), **executor);
}
unblockReadsAndWrites(opCtx);
@@ -399,9 +397,8 @@ ExecutorFuture<void> MovePrimaryCoordinator::_cleanupOnAbort(
auto* opCtx = opCtxHolder.get();
getForwardableOpMetadata().setOn(opCtx);
- _updateSession(opCtx);
_performNoopRetryableWriteOnAllShardsAndConfigsvr(
- opCtx, getCurrentSession(), **executor);
+ opCtx, getNewSession(opCtx), **executor);
if (useOnlineCloner()) {
cleanupOnAbortWithOnlineCloner(opCtx, token, status);
@@ -722,15 +719,14 @@ void MovePrimaryCoordinator::dropOrphanedDataOnRecipient(
return;
}
- // Make a copy of this container since `_updateSession` changes the coordinator document.
+ // Make a copy of this container since `getNewSession` changes the coordinator document.
const auto collectionsToClone = *_doc.getCollectionsToClone();
for (const auto& nss : collectionsToClone) {
- _updateSession(opCtx);
sharding_ddl_util::sendDropCollectionParticipantCommandToShards(opCtx,
nss,
{_doc.getToShardId()},
**executor,
- getCurrentSession(),
+ getNewSession(opCtx),
false /* fromMigrate */);
}
}
@@ -762,14 +758,14 @@ void MovePrimaryCoordinator::unblockReadsAndWrites(OperationContext* opCtx) cons
opCtx, NamespaceString(_dbName), _csReason, ShardingCatalogClient::kLocalWriteConcern);
}
-void MovePrimaryCoordinator::enterCriticalSectionOnRecipient(OperationContext* opCtx) const {
+void MovePrimaryCoordinator::enterCriticalSectionOnRecipient(OperationContext* opCtx) {
const auto enterCriticalSectionCommand = [&] {
ShardsvrMovePrimaryEnterCriticalSection request(_dbName);
request.setDbName(DatabaseName::kAdmin);
request.setReason(_csReason);
auto command = CommandHelpers::appendMajorityWriteConcern(request.toBSON({}));
- return command.addFields(getCurrentSession().toBSON());
+ return command.addFields(getNewSession(opCtx).toBSON());
}();
const auto& toShardId = _doc.getToShardId();
@@ -792,14 +788,14 @@ void MovePrimaryCoordinator::enterCriticalSectionOnRecipient(OperationContext* o
_dbName.toStringForErrorMsg(), toShardId.toString()));
}
-void MovePrimaryCoordinator::exitCriticalSectionOnRecipient(OperationContext* opCtx) const {
+void MovePrimaryCoordinator::exitCriticalSectionOnRecipient(OperationContext* opCtx) {
const auto exitCriticalSectionCommand = [&] {
ShardsvrMovePrimaryExitCriticalSection request(_dbName);
request.setDbName(DatabaseName::kAdmin);
request.setReason(_csReason);
auto command = CommandHelpers::appendMajorityWriteConcern(request.toBSON({}));
- return command.addFields(getCurrentSession().toBSON());
+ return command.addFields(getNewSession(opCtx).toBSON());
}();
const auto& toShardId = _doc.getToShardId();
diff --git a/src/mongo/db/s/move_primary_coordinator.h b/src/mongo/db/s/move_primary_coordinator.h
index 22a03c2a460..89a99c3ab9e 100644
--- a/src/mongo/db/s/move_primary_coordinator.h
+++ b/src/mongo/db/s/move_primary_coordinator.h
@@ -190,13 +190,13 @@ private:
* Requests the recipient to enter the critical section on the database, causing the database
* metadata refreshes to block.
*/
- void enterCriticalSectionOnRecipient(OperationContext* opCtx) const;
+ void enterCriticalSectionOnRecipient(OperationContext* opCtx);
/**
* Requests the recipient to exit the critical section on the database, causing the database
* metadata refreshes to unblock.
*/
- void exitCriticalSectionOnRecipient(OperationContext* opCtx) const;
+ void exitCriticalSectionOnRecipient(OperationContext* opCtx);
void cleanupOnlineCloner(OperationContext* opCtx, const CancellationToken& token);
void cleanupOnAbortWithoutOnlineCloner(OperationContext* opCtx,
diff --git a/src/mongo/db/s/sharding_ddl_coordinator.h b/src/mongo/db/s/sharding_ddl_coordinator.h
index 7b53a15e6f7..db0827d1142 100644
--- a/src/mongo/db/s/sharding_ddl_coordinator.h
+++ b/src/mongo/db/s/sharding_ddl_coordinator.h
@@ -409,6 +409,11 @@ protected:
return osi;
}
+ OperationSessionInfo getNewSession(OperationContext* opCtx) {
+ _updateSession(opCtx);
+ return getCurrentSession();
+ }
+
virtual boost::optional<Status> getAbortReason() const override {
const auto& status = _doc.getAbortReason();
invariant(!status || !status->isOK(), "when persisted, status must be an error");