summaryrefslogtreecommitdiff
path: root/src/mongo/db/db_raii.cpp
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2015-08-26 22:01:13 -0400
committerBenety Goh <benety@mongodb.com>2015-08-26 22:01:13 -0400
commit5ecaaa4eb7f210fcc5b2f6cd27b409f124bfd11e (patch)
tree356a8b6d70160c39e61c1db650f6c3e640b10f6d /src/mongo/db/db_raii.cpp
parente91d30995cbfeb69ca49db04c8e32257336898e4 (diff)
downloadmongo-5ecaaa4eb7f210fcc5b2f6cd27b409f124bfd11e.tar.gz
Revert "SERVER-20052 yield when waiting/blocking for read committed"
This reverts commit 6fbd22f5f812885002b5d4cdd23a8bfec843ce82.
Diffstat (limited to 'src/mongo/db/db_raii.cpp')
-rw-r--r--src/mongo/db/db_raii.cpp80
1 files changed, 28 insertions, 52 deletions
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<Client> 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<Client> 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<Client> lk(*_txn->getClient());
- CurOp::get(_txn)->yielded();
}
AutoGetCollectionForRead::~AutoGetCollectionForRead() {