示例#1
0
    void profile(OperationContext* txn, const Client& c, int op, CurOp& currentOp) {
        // initialize with 1kb to start, to avoid realloc later
        // doing this outside the dblock to improve performance
        BufBuilder profileBufBuilder(1024);

        try {
            // NOTE: It's kind of weird that we lock the op's namespace, but have to for now since
            // we're sometimes inside the lock already
            Lock::DBWrite lk(txn->lockState(), currentOp.getNS() );
            if (dbHolder().get(txn, nsToDatabase(currentOp.getNS())) != NULL) {
                // We are ok with the profiling happening in a different WUOW from the actual op.
                WriteUnitOfWork wunit(txn->recoveryUnit());
                Client::Context cx(txn, currentOp.getNS(), false);
                _profile(txn, c, cx.db(), currentOp, profileBufBuilder);
                wunit.commit();
            }
            else {
                mongo::log() << "note: not profiling because db went away - probably a close on: "
                             << currentOp.getNS() << endl;
            }
        }
        catch (const AssertionException& assertionEx) {
            warning() << "Caught Assertion while trying to profile " << opToString(op)
                      << " against " << currentOp.getNS()
                      << ": " << assertionEx.toString() << endl;
        }
    }
示例#2
0
void profile(OperationContext* txn, const Client& c, int op, CurOp& currentOp) {
    // initialize with 1kb to start, to avoid realloc later
    // doing this outside the dblock to improve performance
    BufBuilder profileBufBuilder(1024);

    try {
        // NOTE: It's kind of weird that we lock the op's namespace, but have to for now since
        // we're sometimes inside the lock already
        Lock::DBWrite lk( currentOp.getNS() );
        if (dbHolder()._isLoaded(nsToDatabase(currentOp.getNS()), storageGlobalParams.dbpath)) {
            Client::Context cx(currentOp.getNS(), storageGlobalParams.dbpath, false);
            _profile(txn, c, cx.db(),
                     currentOp, profileBufBuilder);
        }
        else {
            mongo::log() << "note: not profiling because db went away - probably a close on: "
                         << currentOp.getNS() << endl;
        }
    }
    catch (const AssertionException& assertionEx) {
        warning() << "Caught Assertion while trying to profile " << opToString(op)
                  << " against " << currentOp.getNS()
                  << ": " << assertionEx.toString() << endl;
    }
}
示例#3
0
    void profile(OperationContext* txn, const Client& c, int op, CurOp& currentOp) {
        // initialize with 1kb to start, to avoid realloc later
        // doing this outside the dblock to improve performance
        BufBuilder profileBufBuilder(1024);

        bool tryAgain = false;
        while ( 1 ) {
            try {
                // NOTE: It's kind of weird that we lock the op's namespace, but have to for now
                // since we're sometimes inside the lock already
                const string dbname(nsToDatabase(currentOp.getNS()));
                scoped_ptr<Lock::DBLock> lk;

                // todo: this can be slow, perhaps can re-work
                if ( !txn->lockState()->isDbLockedForMode( dbname, MODE_IX ) ) {
                    lk.reset( new Lock::DBLock( txn->lockState(),
                                                dbname,
                                                tryAgain ? MODE_X : MODE_IX) );
                }
                Database* db = dbHolder().get(txn, dbname);
                if (db != NULL) {
                    // We want the profiling to happen in a different WUOW from the actual op.
                    Lock::CollectionLock clk(txn->lockState(), db->getProfilingNS(), MODE_X);
                    WriteUnitOfWork wunit(txn);
                    Client::Context cx(txn, currentOp.getNS(), false);
                    if ( !_profile(txn, c, cx.db(), currentOp, profileBufBuilder ) && lk.get() ) {
                        if ( tryAgain ) {
                            // we couldn't profile, but that's ok, we should have logged already
                            break;
                        }
                        // we took an IX lock, so now we try again with an X lock
                        tryAgain = true;
                        continue;
                    }
                    wunit.commit();
                }
                else {
                    mongo::log() << "note: not profiling because db went away - "
                                 << "probably a close on: " << currentOp.getNS();
                }
                return;
            }
            catch (const AssertionException& assertionEx) {
                warning() << "Caught Assertion while trying to profile " << opToString(op)
                          << " against " << currentOp.getNS()
                          << ": " << assertionEx.toString() << endl;
                return;
            }
        }
    }
示例#4
0
    void profile(const Client& c, int op, CurOp& currentOp) {
        // initialize with 1kb to start, to avoid realloc later
        // doing this outside the dblock to improve performance
        BufBuilder profileBufBuilder(1024);

        try {
            Lock::DBWrite lk( currentOp.getNS() );
            if ( dbHolder()._isLoaded( nsToDatabase( currentOp.getNS() ) , dbpath ) ) {
                Client::Context cx(currentOp.getNS(), dbpath);
                _profile(c, currentOp, profileBufBuilder);
            }
            else {
                mongo::log() << "note: not profiling because db went away - probably a close on: "
                             << currentOp.getNS() << endl;
            }
        }
        catch (const AssertionException& assertionEx) {
            warning() << "Caught Assertion while trying to profile " << opToString(op)
                      << " against " << currentOp.getNS()
                      << ": " << assertionEx.toString() << endl;
        }
    }