summaryrefslogtreecommitdiff
path: root/src/mongo/db/db_raii.cpp
diff options
context:
space:
mode:
authorMaria van Keulen <maria@mongodb.com>2017-03-07 12:00:08 -0500
committerMaria van Keulen <maria@mongodb.com>2017-03-07 12:00:08 -0500
commit589a5c169ced8f6e9ddcd3d182ae1b75db6b7d79 (patch)
treec7a090ffdd56a91ae677e2492c61b820af44f964 /src/mongo/db/db_raii.cpp
parent3cba97198638df3750e3b455e2ad57af7ee536ae (diff)
downloadmongo-589a5c169ced8f6e9ddcd3d182ae1b75db6b7d79.tar.gz
SERVER-27938 Rename all OperationContext variables to opCtx
This commit is an automated rename of all whole word instances of txn, _txn, and txnPtr to opCtx, _opCtx, and opCtxPtr, respectively in all .cpp and .h files in src/mongo.
Diffstat (limited to 'src/mongo/db/db_raii.cpp')
-rw-r--r--src/mongo/db/db_raii.cpp98
1 files changed, 49 insertions, 49 deletions
diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp
index 2808c7e0e35..051d9141ebf 100644
--- a/src/mongo/db/db_raii.cpp
+++ b/src/mongo/db/db_raii.cpp
@@ -41,30 +41,30 @@
namespace mongo {
-AutoGetDb::AutoGetDb(OperationContext* txn, StringData ns, LockMode mode)
- : _dbLock(txn->lockState(), ns, mode), _db(dbHolder().get(txn, ns)) {}
+AutoGetDb::AutoGetDb(OperationContext* opCtx, StringData ns, LockMode mode)
+ : _dbLock(opCtx->lockState(), ns, mode), _db(dbHolder().get(opCtx, ns)) {}
-AutoGetCollection::AutoGetCollection(OperationContext* txn,
+AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
const NamespaceString& nss,
LockMode modeDB,
LockMode modeColl,
ViewMode viewMode)
: _viewMode(viewMode),
- _autoDb(txn, nss.db(), modeDB),
- _collLock(txn->lockState(), nss.ns(), modeColl),
+ _autoDb(opCtx, nss.db(), modeDB),
+ _collLock(opCtx->lockState(), nss.ns(), modeColl),
_coll(_autoDb.getDb() ? _autoDb.getDb()->getCollection(nss) : nullptr) {
Database* db = _autoDb.getDb();
// If the database exists, but not the collection, check for views.
if (_viewMode == ViewMode::kViewsForbidden && db && !_coll &&
- db->getViewCatalog()->lookup(txn, nss.ns()))
+ db->getViewCatalog()->lookup(opCtx, nss.ns()))
uasserted(ErrorCodes::CommandNotSupportedOnView,
str::stream() << "Namespace " << nss.ns() << " is a view, not a collection");
}
-AutoGetOrCreateDb::AutoGetOrCreateDb(OperationContext* txn, StringData ns, LockMode mode)
- : _transaction(txn, MODE_IX),
- _dbLock(txn->lockState(), ns, mode),
- _db(dbHolder().get(txn, ns)) {
+AutoGetOrCreateDb::AutoGetOrCreateDb(OperationContext* opCtx, StringData ns, LockMode mode)
+ : _transaction(opCtx, MODE_IX),
+ _dbLock(opCtx->lockState(), ns, mode),
+ _db(dbHolder().get(opCtx, ns)) {
invariant(mode == MODE_IX || mode == MODE_X);
_justCreated = false;
// If the database didn't exist, relock in MODE_X
@@ -72,20 +72,20 @@ AutoGetOrCreateDb::AutoGetOrCreateDb(OperationContext* txn, StringData ns, LockM
if (mode != MODE_X) {
_dbLock.relockWithMode(MODE_X);
}
- _db = dbHolder().openDb(txn, ns);
+ _db = dbHolder().openDb(opCtx, ns);
_justCreated = true;
}
}
-AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* txn,
+AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* opCtx,
const NamespaceString& nss,
AutoGetCollection::ViewMode viewMode)
- : _txn(txn), _transaction(txn, MODE_IS) {
+ : _opCtx(opCtx), _transaction(opCtx, MODE_IS) {
{
- _autoColl.emplace(txn, nss, MODE_IS, MODE_IS, viewMode);
+ _autoColl.emplace(opCtx, nss, MODE_IS, MODE_IS, viewMode);
- auto curOp = CurOp::get(_txn);
- stdx::lock_guard<Client> lk(*_txn->getClient());
+ auto curOp = CurOp::get(_opCtx);
+ stdx::lock_guard<Client> lk(*_opCtx->getClient());
// TODO: OldClientContext legacy, needs to be removed
curOp->ensureStarted();
@@ -104,15 +104,15 @@ AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* txn,
// We have both the DB and collection locked, which is the prerequisite to do a stable shard
// version check, but we'd like to do the check after we have a satisfactory snapshot.
- auto css = CollectionShardingState::get(txn, nss);
- css->checkShardVersionOrThrow(txn);
+ auto css = CollectionShardingState::get(opCtx, nss);
+ css->checkShardVersionOrThrow(opCtx);
}
AutoGetCollectionForRead::~AutoGetCollectionForRead() {
// Report time spent in read lock
- auto currentOp = CurOp::get(_txn);
- Top::get(_txn->getClient()->getServiceContext())
- .record(_txn,
+ auto currentOp = CurOp::get(_opCtx);
+ Top::get(_opCtx->getClient()->getServiceContext())
+ .record(_opCtx,
currentOp->getNS(),
currentOp->getLogicalOp(),
-1, // "read locked"
@@ -131,7 +131,7 @@ void AutoGetCollectionForRead::_ensureMajorityCommittedSnapshotIsValid(const Nam
if (!minSnapshot) {
return;
}
- auto mySnapshot = _txn->recoveryUnit()->getMajorityCommittedSnapshot();
+ auto mySnapshot = _opCtx->recoveryUnit()->getMajorityCommittedSnapshot();
if (!mySnapshot) {
return;
}
@@ -142,25 +142,25 @@ void AutoGetCollectionForRead::_ensureMajorityCommittedSnapshotIsValid(const Nam
// Yield locks.
_autoColl = boost::none;
- repl::ReplicationCoordinator::get(_txn)->waitUntilSnapshotCommitted(_txn, *minSnapshot);
+ repl::ReplicationCoordinator::get(_opCtx)->waitUntilSnapshotCommitted(_opCtx, *minSnapshot);
- uassertStatusOK(_txn->recoveryUnit()->setReadFromMajorityCommittedSnapshot());
+ uassertStatusOK(_opCtx->recoveryUnit()->setReadFromMajorityCommittedSnapshot());
{
- stdx::lock_guard<Client> lk(*_txn->getClient());
- CurOp::get(_txn)->yielded();
+ stdx::lock_guard<Client> lk(*_opCtx->getClient());
+ CurOp::get(_opCtx)->yielded();
}
// Relock.
- _autoColl.emplace(_txn, nss, MODE_IS);
+ _autoColl.emplace(_opCtx, nss, MODE_IS);
}
}
-AutoGetCollectionOrViewForRead::AutoGetCollectionOrViewForRead(OperationContext* txn,
+AutoGetCollectionOrViewForRead::AutoGetCollectionOrViewForRead(OperationContext* opCtx,
const NamespaceString& nss)
- : AutoGetCollectionForRead(txn, nss, AutoGetCollection::ViewMode::kViewsPermitted),
+ : AutoGetCollectionForRead(opCtx, nss, AutoGetCollection::ViewMode::kViewsPermitted),
_view(_autoColl->getDb() && !getCollection()
- ? _autoColl->getDb()->getViewCatalog()->lookup(txn, nss.ns())
+ ? _autoColl->getDb()->getViewCatalog()->lookup(opCtx, nss.ns())
: nullptr) {}
void AutoGetCollectionOrViewForRead::releaseLocksForView() noexcept {
@@ -169,32 +169,32 @@ void AutoGetCollectionOrViewForRead::releaseLocksForView() noexcept {
_autoColl = boost::none;
}
-OldClientContext::OldClientContext(OperationContext* txn,
+OldClientContext::OldClientContext(OperationContext* opCtx,
const std::string& ns,
Database* db,
bool justCreated)
- : _justCreated(justCreated), _doVersion(true), _ns(ns), _db(db), _txn(txn) {
+ : _justCreated(justCreated), _doVersion(true), _ns(ns), _db(db), _opCtx(opCtx) {
_finishInit();
}
-OldClientContext::OldClientContext(OperationContext* txn,
+OldClientContext::OldClientContext(OperationContext* opCtx,
const std::string& ns,
bool doVersion)
: _justCreated(false), // set for real in finishInit
_doVersion(doVersion),
_ns(ns),
_db(NULL),
- _txn(txn) {
+ _opCtx(opCtx) {
_finishInit();
}
void OldClientContext::_finishInit() {
- _db = dbHolder().get(_txn, _ns);
+ _db = dbHolder().get(_opCtx, _ns);
if (_db) {
_justCreated = false;
} else {
- invariant(_txn->lockState()->isDbLockedForMode(nsToDatabaseSubstring(_ns), MODE_X));
- _db = dbHolder().openDb(_txn, _ns, &_justCreated);
+ invariant(_opCtx->lockState()->isDbLockedForMode(nsToDatabaseSubstring(_ns), MODE_X));
+ _db = dbHolder().openDb(_opCtx, _ns, &_justCreated);
invariant(_db);
}
@@ -202,32 +202,32 @@ void OldClientContext::_finishInit() {
_checkNotStale();
}
- stdx::lock_guard<Client> lk(*_txn->getClient());
- CurOp::get(_txn)->enter_inlock(_ns.c_str(), _db->getProfilingLevel());
+ stdx::lock_guard<Client> lk(*_opCtx->getClient());
+ CurOp::get(_opCtx)->enter_inlock(_ns.c_str(), _db->getProfilingLevel());
}
void OldClientContext::_checkNotStale() const {
- switch (CurOp::get(_txn)->getNetworkOp()) {
+ switch (CurOp::get(_opCtx)->getNetworkOp()) {
case dbGetMore: // getMore is special and should be handled elsewhere.
case dbUpdate: // update & delete check shard version in instance.cpp, so don't check
case dbDelete: // here as well.
break;
default:
- auto css = CollectionShardingState::get(_txn, _ns);
- css->checkShardVersionOrThrow(_txn);
+ auto css = CollectionShardingState::get(_opCtx, _ns);
+ css->checkShardVersionOrThrow(_opCtx);
}
}
OldClientContext::~OldClientContext() {
// Lock must still be held
- invariant(_txn->lockState()->isLocked());
+ invariant(_opCtx->lockState()->isLocked());
- auto currentOp = CurOp::get(_txn);
- Top::get(_txn->getClient()->getServiceContext())
- .record(_txn,
+ auto currentOp = CurOp::get(_opCtx);
+ Top::get(_opCtx->getClient()->getServiceContext())
+ .record(_opCtx,
currentOp->getNS(),
currentOp->getLogicalOp(),
- _txn->lockState()->isWriteLocked() ? 1 : -1,
+ _opCtx->lockState()->isWriteLocked() ? 1 : -1,
_timer.micros(),
currentOp->isCommand(),
currentOp->getReadWriteType());
@@ -235,7 +235,7 @@ OldClientContext::~OldClientContext() {
OldClientWriteContext::OldClientWriteContext(OperationContext* opCtx, const std::string& ns)
- : _txn(opCtx),
+ : _opCtx(opCtx),
_nss(ns),
_autodb(opCtx, _nss.db(), MODE_IX),
_collk(opCtx->lockState(), ns, MODE_IX),
@@ -244,7 +244,7 @@ OldClientWriteContext::OldClientWriteContext(OperationContext* opCtx, const std:
if (!_collection && !_autodb.justCreated()) {
// relock database in MODE_X to allow collection creation
_collk.relockAsDatabaseExclusive(_autodb.lock());
- Database* db = dbHolder().get(_txn, ns);
+ Database* db = dbHolder().get(_opCtx, ns);
invariant(db == _c.db());
}
}