当前位置: 首页>>代码示例>>C++>>正文


C++ OperationContextImpl类代码示例

本文整理汇总了C++中OperationContextImpl的典型用法代码示例。如果您正苦于以下问题:C++ OperationContextImpl类的具体用法?C++ OperationContextImpl怎么用?C++ OperationContextImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OperationContextImpl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: lkf

    void FSyncLockThread::doRealWork() {
        SimpleMutex::scoped_lock lkf(filesLockedFsync);

        OperationContextImpl txn;
        ScopedTransaction transaction(&txn, MODE_X);
        Lock::GlobalWrite global(txn.lockState()); // No WriteUnitOfWork needed

        SimpleMutex::scoped_lock lk(fsyncCmd.m);
        
        invariant(!fsyncCmd.locked);    // impossible to get here if locked is true
        try { 
            getDur().syncDataAndTruncateJournal(&txn);
        } 
        catch( std::exception& e ) { 
            error() << "error doing syncDataAndTruncateJournal: " << e.what() << endl;
            fsyncCmd.err = e.what();
            fsyncCmd._threadSync.notify_one();
            fsyncCmd.locked = false;
            return;
        }

        txn.lockState()->downgradeGlobalXtoSForMMAPV1();

        try {
            StorageEngine* storageEngine = getGlobalEnvironment()->getGlobalStorageEngine();
            storageEngine->flushAllFiles(true);
        }
        catch( std::exception& e ) { 
            error() << "error doing flushAll: " << e.what() << endl;
            fsyncCmd.err = e.what();
            fsyncCmd._threadSync.notify_one();
            fsyncCmd.locked = false;
            return;
        }

        invariant(!fsyncCmd.locked);
        fsyncCmd.locked = true;
        
        fsyncCmd._threadSync.notify_one();

        while ( ! fsyncCmd.pendingUnlock ) {
            fsyncCmd._unlockSync.wait(fsyncCmd.m);
        }
        fsyncCmd.pendingUnlock = false;
        
        fsyncCmd.locked = false;
        fsyncCmd.err = "unlocked";

        fsyncCmd._unlockSync.notify_one();
    }
开发者ID:maxkeller,项目名称:mongo,代码行数:50,代码来源:fsync.cpp

示例2: getInitialSyncFlag

bool getInitialSyncFlag() {
    OperationContextImpl txn;
    MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
        ScopedTransaction transaction(&txn, MODE_IX);
        Lock::DBLock lk(txn.lockState(), "local", MODE_X);
        BSONObj mv;
        bool found = Helpers::getSingleton(&txn, minvalidNS, mv);
        if (found) {
            return mv[initialSyncFlagString].trueValue();
        }
        return false;
    }
    MONGO_WRITE_CONFLICT_RETRY_LOOP_END(&txn, "getInitialSyncFlags", minvalidNS);
}
开发者ID:DavidAlphaFox,项目名称:mongodb,代码行数:14,代码来源:minvalid.cpp

示例3: TEST

    TEST(DBHelperTests, FindDiskLocs) {
        OperationContextImpl txn;
        DBDirectClient client(&txn);

        // Some unique tag we can use to make sure we're pulling back the right data
        OID tag = OID::gen();
        client.remove( ns, BSONObj() );

        int numDocsInserted = 10;
        for ( int i = 0; i < numDocsInserted; ++i ) {
            client.insert( ns, BSON( "_id" << i << "tag" << tag ) );
        }

        long long maxSizeBytes = 1024 * 1024 * 1024;

        set<DiskLoc> locs;
        long long numDocsFound;
        long long estSizeBytes;
        {
            // search _id range (0, 10)
            Lock::DBRead lk(txn.lockState(), ns);

            KeyRange range( ns,
                            BSON( "_id" << 0 ),
                            BSON( "_id" << numDocsInserted ),
                            BSON( "_id" << 1 ) );

            Status result = Helpers::getLocsInRange( &txn,
                                                     range,
                                                     maxSizeBytes,
                                                     &locs,
                                                     &numDocsFound,
                                                     &estSizeBytes );

            ASSERT_EQUALS( result, Status::OK() );
            ASSERT_EQUALS( numDocsFound, numDocsInserted );
            ASSERT_NOT_EQUALS( estSizeBytes, 0 );
            ASSERT_LESS_THAN( estSizeBytes, maxSizeBytes );

            Database* db = dbHolder().get( &txn, nsToDatabase(range.ns) );
            const Collection* collection = db->getCollection(&txn, ns);

            // Make sure all the disklocs actually correspond to the right info
            for ( set<DiskLoc>::const_iterator it = locs.begin(); it != locs.end(); ++it ) {
                const BSONObj obj = collection->docFor(&txn, *it);
                ASSERT_EQUALS(obj["tag"].OID(), tag);
            }
        }
    }
开发者ID:Karl-Wu,项目名称:mongo,代码行数:49,代码来源:dbhelper_tests.cpp

示例4: lkf

    void FSyncLockThread::doRealWork() {
        SimpleMutex::scoped_lock lkf(filesLockedFsync);

        OperationContextImpl txn;   // XXX?
        Lock::GlobalWrite global(txn.lockState());

        SimpleMutex::scoped_lock lk(fsyncCmd.m);
        
        verify( ! fsyncCmd.locked ); // impossible to get here if locked is true
        try { 
            getDur().syncDataAndTruncateJournal();
        } 
        catch( std::exception& e ) { 
            error() << "error doing syncDataAndTruncateJournal: " << e.what() << endl;
            fsyncCmd.err = e.what();
            fsyncCmd._threadSync.notify_one();
            fsyncCmd.locked = false;
            return;
        }
        
        global.downgrade();
        
        try {
            MemoryMappedFile::flushAll(true);
        }
        catch( std::exception& e ) { 
            error() << "error doing flushAll: " << e.what() << endl;
            fsyncCmd.err = e.what();
            fsyncCmd._threadSync.notify_one();
            fsyncCmd.locked = false;
            return;
        }

        verify( ! fsyncCmd.locked );
        fsyncCmd.locked = true;
        
        fsyncCmd._threadSync.notify_one();

        while ( ! fsyncCmd.pendingUnlock ) {
            fsyncCmd._unlockSync.wait(fsyncCmd.m);
        }
        fsyncCmd.pendingUnlock = false;
        
        fsyncCmd.locked = false;
        fsyncCmd.err = "unlocked";

        fsyncCmd._unlockSync.notify_one();
    }
开发者ID:Robbie1977,项目名称:mongo,代码行数:48,代码来源:fsync.cpp

示例5: _dropAllDBs

void ServiceContextMongoDTest::_dropAllDBs() {
    OperationContextImpl txn;
    dropAllDatabasesExceptLocal(&txn);

    ScopedTransaction transaction(&txn, MODE_X);
    Lock::GlobalWrite lk(txn.lockState());
    AutoGetDb autoDBLocal(&txn, "local", MODE_X);
    const auto localDB = autoDBLocal.getDb();
    if (localDB) {
        MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
            // Do not wrap in a WriteUnitOfWork until SERVER-17103 is addressed.
            autoDBLocal.getDb()->dropDatabase(&txn, localDB);
        }
        MONGO_WRITE_CONFLICT_RETRY_LOOP_END(&txn, "_dropAllDBs", "local");
    }
}
开发者ID:goldengoat,项目名称:mongo,代码行数:16,代码来源:service_context_d_test_fixture.cpp

示例6: _logOpRS

    /** write an op to the oplog that is already built.
        todo : make _logOpRS() call this so we don't repeat ourself?
        */
    void _logOpObjRS(const BSONObj& op) {
        OperationContextImpl txn;
        Lock::DBWrite lk(txn.lockState(), "local");

        const OpTime ts = op["ts"]._opTime();
        long long h = op["h"].numberLong();

        {
            if ( localOplogRSCollection == 0 ) {
                Client::Context ctx(rsoplog, storageGlobalParams.dbpath);
                localDB = ctx.db();
                verify( localDB );
                localOplogRSCollection = localDB->getCollection( &txn, rsoplog );
                massert(13389,
                        "local.oplog.rs missing. did you drop it? if so restart server",
                        localOplogRSCollection);
            }
            Client::Context ctx(rsoplog, localDB);
            checkOplogInsert( localOplogRSCollection->insertDocument( &txn, op, false ) );

            /* todo: now() has code to handle clock skew.  but if the skew server to server is large it will get unhappy.
                     this code (or code in now() maybe) should be improved.
                     */
            if( theReplSet ) {
                if( !(theReplSet->lastOpTimeWritten<ts) ) {
                    log() << "replication oplog stream went back in time. previous timestamp: "
                          << theReplSet->lastOpTimeWritten << " newest timestamp: " << ts
                          << ". attempting to sync directly from primary." << endl;
                    std::string errmsg;
                    BSONObjBuilder result;
                    if (!theReplSet->forceSyncFrom(theReplSet->box.getPrimary()->fullName(),
                                                   errmsg, result)) {
                        log() << "Can't sync from primary: " << errmsg << endl;
                    }
                }
                theReplSet->lastOpTimeWritten = ts;
                theReplSet->lastH = h;
                ctx.getClient()->setLastOp( ts );

                BackgroundSync::notify();
            }
        }

        setNewOptime(ts);
    }
开发者ID:AndrewCEmil,项目名称:mongo,代码行数:48,代码来源:oplog.cpp

示例7: run

            void run() {
                const string dbName = "rollback_drop_collection";
                const string droppedName = dbName + ".dropped";
                const string rolledBackName = dbName + ".rolled_back";

                OperationContextImpl txn;

                ScopedTransaction transaction(&txn, MODE_IX);
                Lock::DBLock lk(txn.lockState(), dbName, MODE_X);

                bool justCreated;
                Database* db = dbHolder().openDb(&txn, dbName, &justCreated);
                ASSERT(justCreated);

                {
                    WriteUnitOfWork wunit(&txn);
                    ASSERT_FALSE(db->getCollection(droppedName));
                    Collection* droppedColl;
                    droppedColl = db->createCollection(&txn, droppedName);
                    ASSERT_EQUALS(db->getCollection(droppedName), droppedColl);
                    db->dropCollection(&txn, droppedName);
                    wunit.commit();
                }

                //  Should have been really dropped
                ASSERT_FALSE(db->getCollection(droppedName));

                {
                    WriteUnitOfWork wunit(&txn);
                    ASSERT_FALSE(db->getCollection(rolledBackName));
                    Collection* rolledBackColl = db->createCollection(&txn, rolledBackName);
                    wunit.commit();
                    ASSERT_EQUALS(db->getCollection(rolledBackName), rolledBackColl);
                    db->dropCollection(&txn, rolledBackName);
                    // not committing so dropping should be rolled back
                }

                // The rolledBackCollection dropping should have been rolled back.
                // Original Collection pointers are no longer valid.
                ASSERT(db->getCollection(rolledBackName));

                // The droppedCollection should not have been restored by the rollback.
                ASSERT_FALSE(db->getCollection(droppedName));
            }
开发者ID:ramgtv,项目名称:mongo,代码行数:44,代码来源:namespacetests.cpp

示例8: logStartup

static void logStartup() {
    BSONObjBuilder toLog;
    stringstream id;
    id << getHostNameCached() << "-" << jsTime().asInt64();
    toLog.append("_id", id.str());
    toLog.append("hostname", getHostNameCached());

    toLog.appendTimeT("startTime", time(0));
    toLog.append("startTimeLocal", dateToCtimeString(Date_t::now()));

    toLog.append("cmdLine", serverGlobalParams.parsedOpts);
    toLog.append("pid", ProcessId::getCurrent().asLongLong());


    BSONObjBuilder buildinfo(toLog.subobjStart("buildinfo"));
    appendBuildInfo(buildinfo);
    appendStorageEngineList(&buildinfo);
    buildinfo.doneFast();

    BSONObj o = toLog.obj();

    OperationContextImpl txn;

    ScopedTransaction transaction(&txn, MODE_X);
    Lock::GlobalWrite lk(txn.lockState());
    AutoGetOrCreateDb autoDb(&txn, "local", mongo::MODE_X);
    Database* db = autoDb.getDb();
    const std::string ns = "local.startup_log";
    Collection* collection = db->getCollection(ns);
    WriteUnitOfWork wunit(&txn);
    if (!collection) {
        BSONObj options = BSON("capped" << true << "size" << 10 * 1024 * 1024);
        bool shouldReplicateWrites = txn.writesAreReplicated();
        txn.setReplicatedWrites(false);
        ON_BLOCK_EXIT(&OperationContext::setReplicatedWrites, &txn, shouldReplicateWrites);
        uassertStatusOK(userCreateNS(&txn, db, ns, options));
        collection = db->getCollection(ns);
    }
    invariant(collection);
    uassertStatusOK(collection->insertDocument(&txn, o, false).getStatus());
    wunit.commit();
}
开发者ID:WeetLee,项目名称:mongo,代码行数:42,代码来源:db.cpp

示例9: applyOpsToOplog

    OpTime SyncTail::applyOpsToOplog(std::deque<BSONObj>* ops) {
        OpTime lastOpTime;
        {
            OperationContextImpl txn; // XXX?
            Lock::DBLock lk(txn.lockState(), "local", MODE_X);
            WriteUnitOfWork wunit(&txn);

            while (!ops->empty()) {
                const BSONObj& op = ops->front();
                // this updates lastOpTimeApplied
                lastOpTime = _logOpObjRS(&txn, op);
                ops->pop_front();
             }
            wunit.commit();
        }

        // Update write concern on primary
        BackgroundSync::get()->notify();
        return lastOpTime;
    }
开发者ID:Aaron20141021,项目名称:mongo,代码行数:20,代码来源:sync_tail.cpp

示例10: applyOpsToOplog

    void SyncTail::applyOpsToOplog(std::deque<BSONObj>* ops) {
        {
            OperationContextImpl txn; // XXX?
            Lock::DBWrite lk(txn.lockState(), "local");

            while (!ops->empty()) {
                const BSONObj& op = ops->front();
                // this updates theReplSet->lastOpTimeWritten
                _logOpObjRS(op);
                ops->pop_front();
             }
        }

        if (BackgroundSync::get()->isAssumingPrimary()) {
            LOG(1) << "notifying BackgroundSync";
        }
            
        // Update write concern on primary
        BackgroundSync::notify();
    }
开发者ID:Robbie1977,项目名称:mongo,代码行数:20,代码来源:sync_tail.cpp

示例11: pretouchN

void pretouchN(vector<BSONObj>& v, unsigned a, unsigned b) {
    Client* c = currentClient.get();
    if (c == 0) {
        Client::initThread("pretouchN");
        c = &cc();
    }

    OperationContextImpl txn;  // XXX
    ScopedTransaction transaction(&txn, MODE_S);
    Lock::GlobalRead lk(txn.lockState());

    for (unsigned i = a; i <= b; i++) {
        const BSONObj& op = v[i];
        const char* which = "o";
        const char* opType = op.getStringField("op");
        if (*opType == 'i')
            ;
        else if (*opType == 'u')
            which = "o2";
        else
            continue;
        /* todo : other operations */

        try {
            BSONObj o = op.getObjectField(which);
            BSONElement _id;
            if (o.getObjectID(_id)) {
                const char* ns = op.getStringField("ns");
                BSONObjBuilder b;
                b.append(_id);
                BSONObj result;
                Client::Context ctx(&txn, ns);
                if (Helpers::findById(&txn, ctx.db(), ns, b.done(), result))
                    _dummy_z += result.objsize();  // touch
            }
        } catch (DBException& e) {
            log() << "ignoring assertion in pretouchN() " << a << ' ' << b << ' ' << i << ' '
                  << e.toString() << endl;
        }
    }
}
开发者ID:DavidAlphaFox,项目名称:mongodb,代码行数:41,代码来源:master_slave.cpp

示例12: run

        void run() {
            for ( int i = 0; i < 10; ++i ) {
                client.insert( ns, BSON( "_id" << i ) );
            }

            {
                // Remove _id range [_min, _max).
                OperationContextImpl txn;
                Lock::DBWrite lk(txn.lockState(), ns);
                Client::Context ctx( ns );

                KeyRange range( ns,
                                BSON( "_id" << _min ),
                                BSON( "_id" << _max ),
                                BSON( "_id" << 1 ) );
                Helpers::removeRange( &txn, range );
            }

            // Check that the expected documents remain.
            ASSERT_EQUALS( expected(), docs() );
        }
开发者ID:AndrewCEmil,项目名称:mongo,代码行数:21,代码来源:dbhelper_tests.cpp

示例13: LOG

    void IndexBuilder::run() {
        Client::initThread(name().c_str());
        LOG(2) << "IndexBuilder building index " << _index;

        OperationContextImpl txn;
        txn.lockState()->setIsBatchWriter(true);

        txn.getClient()->getAuthorizationSession()->grantInternalAuthorization();

        txn.getCurOp()->reset(HostAndPort(), dbInsert);
        NamespaceString ns(_index["ns"].String());

        ScopedTransaction transaction(&txn, MODE_IX);
        Lock::DBLock dlk(txn.lockState(), ns.db(), MODE_X);
        Client::Context ctx(&txn, ns.getSystemIndexesCollection());

        Database* db = dbHolder().get(&txn, ns.db().toString());

        Status status = _build(&txn, db, true, &dlk);
        if ( !status.isOK() ) {
            error() << "IndexBuilder could not build index: " << status.toString();
            fassert(28555, ErrorCodes::isInterruption(status.code()));
        }

        txn.getClient()->shutdown();
    }
开发者ID:ramgtv,项目名称:mongo,代码行数:26,代码来源:index_builder.cpp

示例14: multiInitialSyncApply

// This free function is used by the initial sync writer threads to apply each op
void multiInitialSyncApply(const std::vector<BSONObj>& ops, SyncTail* st) {
    initializeWriterThread();

    OperationContextImpl txn;
    txn.setReplicatedWrites(false);
    DisableDocumentValidation validationDisabler(&txn);

    // allow us to get through the magic barrier
    txn.lockState()->setIsBatchWriter(true);

    bool convertUpdatesToUpserts = false;

    for (std::vector<BSONObj>::const_iterator it = ops.begin(); it != ops.end(); ++it) {
        try {
            const Status s = SyncTail::syncApply(&txn, *it, convertUpdatesToUpserts);
            if (!s.isOK()) {
                if (st->shouldRetry(&txn, *it)) {
                    const Status s2 = SyncTail::syncApply(&txn, *it, convertUpdatesToUpserts);
                    if (!s2.isOK()) {
                        severe() << "Error applying operation (" << it->toString() << "): " << s2;
                        fassertFailedNoTrace(15915);
                    }
                }

                // If shouldRetry() returns false, fall through.
                // This can happen if the document that was moved and missed by Cloner
                // subsequently got deleted and no longer exists on the Sync Target at all
            }
        } catch (const DBException& e) {
            severe() << "writer worker caught exception: " << causedBy(e)
                     << " on: " << it->toString();

            if (inShutdown()) {
                return;
            }

            fassertFailedNoTrace(16361);
        }
    }
}
开发者ID:Jaryli,项目名称:mongo,代码行数:41,代码来源:sync_tail.cpp

示例15: TEST

    TEST(DBHelperTests, FindDiskLocsTooBig) {

        DBDirectClient client;
        OperationContextImpl txn;

        client.remove( ns, BSONObj() );

        int numDocsInserted = 10;
        for ( int i = 0; i < numDocsInserted; ++i ) {
            client.insert( ns, BSON( "_id" << i ) );
        }

        // Very small max size
        long long maxSizeBytes = 10;

        set<DiskLoc> locs;
        long long numDocsFound;
        long long estSizeBytes;
        {
            Lock::DBRead lk(txn.lockState(), ns);
            Client::Context ctx( ns );
            KeyRange range( ns,
                            BSON( "_id" << 0 ),
                            BSON( "_id" << numDocsInserted ),
                            BSON( "_id" << 1 ) );

            Status result = Helpers::getLocsInRange( &txn,
                                                     range,
                                                     maxSizeBytes,
                                                     &locs,
                                                     &numDocsFound,
                                                     &estSizeBytes );

            // Make sure we get the right error code and our count and size estimates are valid
            ASSERT_EQUALS( result.code(), ErrorCodes::InvalidLength );
            ASSERT_EQUALS( numDocsFound, numDocsInserted );
            ASSERT_GREATER_THAN( estSizeBytes, maxSizeBytes );
        }
    }
开发者ID:AndrewCEmil,项目名称:mongo,代码行数:39,代码来源:dbhelper_tests.cpp


注:本文中的OperationContextImpl类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。