Beispiel #1
0
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);
}
Beispiel #2
0
    void CurOp::enter( Client::Context * context ) {
        ensureStarted();

        strncpy( _ns, context->ns(), Namespace::MaxNsLen);
        _ns[Namespace::MaxNsLen] = 0;

        _dbprofile = std::max( context->_db ? context->_db->profile : 0 , _dbprofile );
    }
Beispiel #3
0
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();
                }
            }
        }
    }
}
Beispiel #4
0
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);
    }
}
Beispiel #5
0
 void CurOp::enter( Client::Context * context ) {
     ensureStarted();
     _ns = context->ns();
     _dbprofile = std::max( context->_db ? context->_db->getProfilingLevel() : 0 , _dbprofile );
 }
Beispiel #6
0
 void CurOp::enter( Client::Context * context ) {
     ensureStarted();
     setNS( context->ns() );
     _dbprofile = context->_db ? context->_db->profile : 0;
 }
Beispiel #7
0
 void CurOp::enter(const char* ns, int dbProfileLevel) {
     ensureStarted();
     _ns = ns;
     _dbprofile = std::max(dbProfileLevel, _dbprofile);
 }