AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* txn, const NamespaceString& nss) : _txn(txn), _transaction(txn, MODE_IS) { { _autoColl.emplace(txn, nss, MODE_IS); auto curOp = CurOp::get(_txn); stdx::lock_guard<Client> lk(*_txn->getClient()); // 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()); } } // Note: this can yield. _ensureMajorityCommittedSnapshotIsValid(nss); // 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); }
void AutoGetCollectionForRead::_init(const std::string& ns, StringData coll) { massert(28535, "need a non-empty collection name", !coll.empty()); // We have both the DB and collection locked, which the prerequisite to do a stable shard // version check. ensureShardVersionOKOrThrow(_txn, ns); auto curOp = CurOp::get(_txn); stdx::lock_guard<Client> lk(*_txn->getClient()); // TODO: OldClientContext legacy, needs to be removed curOp->ensureStarted(); curOp->setNS_inlock(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 (_db.getDb()) { // TODO: OldClientContext legacy, needs to be removed curOp->enter_inlock(ns.c_str(), _db.getDb()->getProfilingLevel()); _coll = _db.getDb()->getCollection(ns); } if (_coll) { if (auto minSnapshot = _coll->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(); } } } } }
void AutoGetCollectionForRead::_init(const std::string& ns, StringData coll) { massert(28535, "need a non-empty collection name", !coll.empty()); // We have both the DB and collection locked, which the prerequisite to do a stable shard // version check. ensureShardVersionOKOrThrow(_txn->getClient(), ns); auto curOp = CurOp::get(_txn); stdx::lock_guard<Client> lk(*_txn->getClient()); // TODO: OldClientContext legacy, needs to be removed curOp->ensureStarted(); curOp->setNS_inlock(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 (_db.getDb()) { // TODO: OldClientContext legacy, needs to be removed curOp->enter_inlock(ns.c_str(), _db.getDb()->getProfilingLevel()); _coll = _db.getDb()->getCollection(ns); } }