From 5ecaaa4eb7f210fcc5b2f6cd27b409f124bfd11e Mon Sep 17 00:00:00 2001 From: Benety Goh Date: Wed, 26 Aug 2015 22:01:13 -0400 Subject: Revert "SERVER-20052 yield when waiting/blocking for read committed" This reverts commit 6fbd22f5f812885002b5d4cdd23a8bfec843ce82. --- src/mongo/db/db_raii.cpp | 80 +++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 52 deletions(-) (limited to 'src/mongo/db/db_raii.cpp') diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp index 5a0c9f964bd..a987062b11b 100644 --- a/src/mongo/db/db_raii.cpp +++ b/src/mongo/db/db_raii.cpp @@ -38,7 +38,6 @@ #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/stats/top.h" #include "mongo/s/d_state.h" -#include "mongo/util/scopeguard.h" namespace mongo { @@ -74,63 +73,40 @@ AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* txn, const AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* txn, const NamespaceString& nss) : _txn(txn), _transaction(txn, MODE_IS), _autoColl(txn, nss, MODE_IS) { - { - auto curOp = CurOp::get(_txn); - stdx::lock_guard lk(*_txn->getClient()); + // We have both the DB and collection locked, which the prerequisite to do a stable shard + // version check + ensureShardVersionOKOrThrow(_txn, nss.ns()); - // TODO: OldClientContext legacy, needs to be removed - curOp->ensureStarted(); - curOp->setNS_inlock(nss.ns()); - - // At this point, we are locked in shared mode for the database by the DB lock in the - // constructor, so it is safe to load the DB pointer. - if (_autoColl.getDb()) { - // TODO: OldClientContext legacy, needs to be removed - curOp->enter_inlock(nss.ns().c_str(), _autoColl.getDb()->getProfilingLevel()); - } - } + auto curOp = CurOp::get(_txn); + stdx::lock_guard lk(*_txn->getClient()); - // 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. - ON_BLOCK_EXIT([&]() { ensureShardVersionOKOrThrow(_txn, nss.ns()); }); + // TODO: OldClientContext legacy, needs to be removed + curOp->ensureStarted(); + curOp->setNS_inlock(nss.ns()); - if (!getCollection()) { - return; - } - auto minSnapshot = getCollection()->getMinimumVisibleSnapshot(); - if (!minSnapshot) { - return; - } - auto mySnapshot = _txn->recoveryUnit()->getMajorityCommittedSnapshot(); - if (!mySnapshot) { - return; - } - if (mySnapshot > minSnapshot) { - return; + // At this point, we are locked in shared mode for the database by the DB lock in the + // constructor, so it is safe to load the DB pointer. + if (_autoColl.getDb()) { + // TODO: OldClientContext legacy, needs to be removed + curOp->enter_inlock(nss.ns().c_str(), _autoColl.getDb()->getProfilingLevel()); } - // Save lock state for yielding. - Locker* locker = _txn->lockState(); - Locker::LockSnapshot lockStateBackup; - massert(28795, - str::stream() << "Unable to yield to wait for readConcern=majority " - << "snapshot to be available for " << nss.ns(), - locker->saveLockStateAndUnlock(&lockStateBackup)); - ON_BLOCK_EXIT([&]() { locker->restoreLockState(lockStateBackup); }); - - // Wait until a snapshot is available. - while (mySnapshot < minSnapshot) { - repl::ReplicationCoordinator::get(_txn)->waitForNewSnapshot(_txn); - - Status status = _txn->recoveryUnit()->setReadFromMajorityCommittedSnapshot(); - uassert(28786, - "failed to set read from majority-committed snapshot", - status.isOK()); - mySnapshot = _txn->recoveryUnit()->getMajorityCommittedSnapshot(); + if (getCollection()) { + if (auto minSnapshot = getCollection()->getMinimumVisibleSnapshot()) { + if (auto mySnapshot = _txn->recoveryUnit()->getMajorityCommittedSnapshot()) { + while (mySnapshot < minSnapshot) { + // Wait until a snapshot is available. + repl::ReplicationCoordinator::get(_txn)->waitForNewSnapshot(_txn); + + Status status = _txn->recoveryUnit()->setReadFromMajorityCommittedSnapshot(); + uassert(28786, + "failed to set read from majority-committed snapshot", + status.isOK()); + mySnapshot = _txn->recoveryUnit()->getMajorityCommittedSnapshot(); + } + } + } } - - stdx::lock_guard lk(*_txn->getClient()); - CurOp::get(_txn)->yielded(); } AutoGetCollectionForRead::~AutoGetCollectionForRead() { -- cgit v1.2.1