Skip to content

Commit 7c8935c

Browse files
jannaerinEvergreen Agent
authored andcommitted
SERVER-49019 Run commitTransaction for refineShardKey on fresh opCtx
1 parent 574976d commit 7c8935c

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,22 +204,33 @@ Status updateShardingCatalogEntryForCollectionInTxn(OperationContext* opCtx,
204204
}
205205

206206
Status commitTxnForConfigDocument(OperationContext* opCtx, TxnNumber txnNumber) {
207+
// Swap out the clients in order to get a fresh opCtx. Previous operations in this transaction
208+
// that have been run on this opCtx would have set the timeout in the locker on the opCtx, but
209+
// commit should not have a lock timeout.
210+
auto newClient = getGlobalServiceContext()->makeClient("commitRefineShardKey");
211+
AlternativeClientRegion acr(newClient);
212+
auto commitOpCtx = cc().makeOperationContext();
213+
AuthorizationSession::get(commitOpCtx.get()->getClient())
214+
->grantInternalAuthorization(commitOpCtx.get()->getClient());
215+
commitOpCtx.get()->setLogicalSessionId(opCtx->getLogicalSessionId().get());
216+
commitOpCtx.get()->setTxnNumber(txnNumber);
217+
207218
BSONObjBuilder bob;
208219
bob.append("commitTransaction", true);
209220
bob.append("autocommit", false);
210221
bob.append(OperationSessionInfo::kTxnNumberFieldName, txnNumber);
211222
bob.append(WriteConcernOptions::kWriteConcernField, WriteConcernOptions::Majority);
212223

213224
BSONObjBuilder lsidBuilder(bob.subobjStart("lsid"));
214-
opCtx->getLogicalSessionId()->serialize(&bob);
225+
commitOpCtx->getLogicalSessionId()->serialize(&bob);
215226
lsidBuilder.doneFast();
216227

217228
const auto cmdObj = bob.obj();
218229

219230
const auto replyOpMsg =
220-
OpMsg::parseOwned(opCtx->getServiceContext()
231+
OpMsg::parseOwned(commitOpCtx->getServiceContext()
221232
->getServiceEntryPoint()
222-
->handleRequest(opCtx,
233+
->handleRequest(commitOpCtx.get(),
223234
OpMsgRequest::fromDBAndBody(
224235
NamespaceString::kAdminDb.toString(), cmdObj)
225236
.serialize())

0 commit comments

Comments
 (0)