summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2019-01-25 15:37:25 -0500
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2019-01-28 18:22:31 -0500
commitd0b2a623ee1838ba060713d0ff9bd1ba94d9e7d8 (patch)
tree4353289df98ac4c5d0fe46418c4aca9ffd31fe2d /src/mongo
parente990d25622d96897d78e72b362db61f2a4f9d99c (diff)
downloadmongo-d0b2a623ee1838ba060713d0ff9bd1ba94d9e7d8.tar.gz
SERVER-38813 Replace AlternativeOpCtx with AlternativeClientRegion
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/operation_context.h29
-rw-r--r--src/mongo/db/repl/replication_recovery.cpp10
2 files changed, 6 insertions, 33 deletions
diff --git a/src/mongo/db/operation_context.h b/src/mongo/db/operation_context.h
index df8694b0e05..e1ea8e6d61d 100644
--- a/src/mongo/db/operation_context.h
+++ b/src/mongo/db/operation_context.h
@@ -468,35 +468,6 @@ private:
bool _writesAreReplicated = true;
};
-/**
- * RAII-style class to temporarily swap the operation context associated with the client.
- *
- * Use this class to bind a new operation context to a client for the duration of the
- * AlternativeOpCtx's lifetime and restore the prior opCtx at the end of the block.
- */
-class AlternativeOpCtx {
-public:
- explicit AlternativeOpCtx(mongo::OperationContext* originalOpCtx)
- : _client(originalOpCtx->getClient()), _originalOpCtx(originalOpCtx) {
- _client->resetOperationContext();
- _alternateOpCtx = _client->makeOperationContext();
- }
-
- ~AlternativeOpCtx() {
- _alternateOpCtx.reset();
- _client->setOperationContext(_originalOpCtx);
- }
-
- mongo::OperationContext* getOperationContext() {
- return _alternateOpCtx.get();
- }
-
-private:
- Client* _client = nullptr;
- mongo::OperationContext* _originalOpCtx = nullptr;
- ServiceContext::UniqueOperationContext _alternateOpCtx;
-};
-
namespace repl {
/**
* RAII-style class to turn off replicated writes. Writes do not create oplog entries while the
diff --git a/src/mongo/db/repl/replication_recovery.cpp b/src/mongo/db/repl/replication_recovery.cpp
index f28f4ca7f86..ec6a31a99ac 100644
--- a/src/mongo/db/repl/replication_recovery.cpp
+++ b/src/mongo/db/repl/replication_recovery.cpp
@@ -302,12 +302,14 @@ void ReplicationRecoveryImpl::_reconstructPreparedTransactions(OperationContext*
{
// Make a new opCtx so that we can set the lsid when applying the prepare transaction
- // oplog entry. After going out of scope, the former opCtx will be restored.
- AlternativeOpCtx aoc(opCtx);
- const auto newOpCtx = aoc.getOperationContext();
+ // oplog entry.
+ auto newClient =
+ opCtx->getServiceContext()->makeClient("reconstruct-prepared-transactions");
+ AlternativeClientRegion acr(newClient);
+ const auto newOpCtx = cc().makeOperationContext();
// Checks out the session, applies the operations and prepares the transactions.
- uassertStatusOK(applyRecoveredPrepareTransaction(newOpCtx, prepareOplogEntry));
+ uassertStatusOK(applyRecoveredPrepareTransaction(newOpCtx.get(), prepareOplogEntry));
}
}
}