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


C++ OperationContextImpl::lockState方法代码示例

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


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

示例1: 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();
        for (std::vector<BSONObj>::const_iterator it = ops.begin();
             it != ops.end();
             ++it) {
            try {
                OperationContextImpl txn;

                if (!st->syncApply(&txn, *it)) {
                    bool status;
                    {
                        Lock::GlobalWrite lk(txn.lockState());
                        status = st->shouldRetry(&txn, *it);
                    }

                    if (status) {
                        // retry
                        if (!st->syncApply(&txn, *it)) {
                            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) {
                error() << "exception: " << causedBy(e) << " on: " << it->toString() << endl;
                fassertFailedNoTrace(16361);
            }
        }
    }
开发者ID:Robbie1977,项目名称:mongo,代码行数:33,代码来源:sync_tail.cpp

示例2: _assumePrimary

    void ReplSetImpl::_assumePrimary() {
        LOG(1) << "replSet assuming primary" << endl;
        verify(iAmPotentiallyHot());

        // Wait for replication to stop and buffer to be consumed
        LOG(1) << "replSet waiting for replication to finish before becoming primary" << endl;
        BackgroundSync::get()->stopReplicationAndFlushBuffer();

        // Lock here to prevent stepping down & becoming primary from getting interleaved
        LOG(1) << "replSet waiting for global write lock";

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

        initOpTimeFromOplog(&txn, "local.oplog.rs");

        // Generate new election unique id
        elect.setElectionId(OID::gen());
        LOG(1) << "replSet truly becoming primary";
        changeState(MemberState::RS_PRIMARY);

        // This must be done after becoming primary but before releasing the write lock. This adds
        // the dropCollection entries for every temp collection to the opLog since we want it to be
        // replicated to secondaries.
        dropAllTempCollections(&txn);
    }
开发者ID:JsonRuby,项目名称:mongo,代码行数:26,代码来源:repl_set_impl.cpp

示例3: replMasterThread

static void replMasterThread() {
    sleepsecs(4);
    Client::initThread("replmaster");
    int toSleep = 10;
    while (1) {
        sleepsecs(toSleep);

        // Write a keep-alive like entry to the log. This will make things like
        // printReplicationStatus() and printSlaveReplicationStatus() stay up-to-date even
        // when things are idle.
        OperationContextImpl txn;
        txn.getClient()->getAuthorizationSession()->grantInternalAuthorization();

        Lock::GlobalWrite globalWrite(txn.lockState(), 1);
        if (globalWrite.isLocked()) {
            toSleep = 10;

            try {
                WriteUnitOfWork wuow(&txn);
                logKeepalive(&txn);
                wuow.commit();
            } catch (...) {
                log() << "caught exception in replMasterThread()" << endl;
            }
        } else {
            LOG(5) << "couldn't logKeepalive" << endl;
            toSleep = 1;
        }
    }
}
开发者ID:DavidAlphaFox,项目名称:mongodb,代码行数:30,代码来源:master_slave.cpp

示例4: run

    void run() {
        OperationContextImpl txn;
        DBDirectClient client(&txn);

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

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

            KeyRange range( ns,
                            BSON( "_id" << _min ),
                            BSON( "_id" << _max ),
                            BSON( "_id" << 1 ) );
            mongo::WriteConcernOptions dummyWriteConcern;
            Helpers::removeRange(&txn, range, false, dummyWriteConcern);
            wunit.commit();
        }

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

示例5: client

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

        client.remove( ns, BSONObj() );
        client.insert( ns, BSON( "_id" << OID::gen() ) );

        long long maxSizeBytes = 1024 * 1024 * 1024;

        set<DiskLoc> locs;
        long long numDocsFound;
        long long estSizeBytes;
        {
            Lock::DBRead lk(txn.lockState(), ns);

            // search invalid index range
            KeyRange range( ns,
                            BSON( "badIndex" << 0 ),
                            BSON( "badIndex" << 10 ),
                            BSON( "badIndex" << 1 ) );

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

            // Make sure we get the right error code
            ASSERT_EQUALS( result.code(), ErrorCodes::IndexNotFound );
            ASSERT_EQUALS( static_cast<long long>( locs.size() ), 0 );
            ASSERT_EQUALS( numDocsFound, 0 );
            ASSERT_EQUALS( estSizeBytes, 0 );
        }
    }
开发者ID:Karl-Wu,项目名称:mongo,代码行数:35,代码来源:dbhelper_tests.cpp

示例6: multiSyncApply

// This free function is used by the writer threads to apply each op
void multiSyncApply(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 = true;

    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()) {
                severe() << "Error applying operation (" << it->toString() << "): " << s;
                fassertFailedNoTrace(16359);
            }
        } catch (const DBException& e) {
            severe() << "writer worker caught exception: " << causedBy(e)
                     << " on: " << it->toString();

            if (inShutdown()) {
                return;
            }

            fassertFailedNoTrace(16360);
        }
    }
}
开发者ID:VonRosenchild,项目名称:percona-server-mongodb,代码行数:32,代码来源:sync_tail.cpp

示例7: logStartup

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

        toLog.appendTimeT( "startTime", time(0) );
        toLog.append( "startTimeLocal", dateToCtimeString(curTimeMillis64()) );

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


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

        BSONObj o = toLog.obj();

        OperationContextImpl txn;

        Lock::GlobalWrite lk(txn.lockState());
        DBDirectClient c(&txn);

        static const char* name = "local.startup_log";
        c.createCollection( name, 10 * 1024 * 1024, true );
        c.insert( name, o);
    }
开发者ID:davande,项目名称:mongo,代码行数:29,代码来源:db.cpp

示例8: getEarliestOpTimeWritten

 OpTime ReplSetImpl::getEarliestOpTimeWritten() const {
     OperationContextImpl txn; // XXX?
     Lock::DBRead lk(txn.lockState(), rsoplog);
     BSONObj o;
     uassert(17347, "Problem reading earliest entry from oplog",
             Helpers::getFirst(&txn, rsoplog, o));
     return o["ts"]._opTime();
 }
开发者ID:Rockyit,项目名称:mongo,代码行数:8,代码来源:repl_set_impl.cpp

示例9: getMinValid

 OpTime ReplSetImpl::getMinValid() {
     OperationContextImpl txn; // XXX?
     Lock::DBRead lk(txn.lockState(), "local.replset.minvalid");
     BSONObj mv;
     if (Helpers::getSingleton(&txn, "local.replset.minvalid", mv)) {
         return mv["ts"]._opTime();
     }
     return OpTime();
 }
开发者ID:AndrewCEmil,项目名称:mongo,代码行数:9,代码来源:repl_set_impl.cpp

示例10: run

        void run() {
            OperationContextImpl txn;
            Lock::DBWrite lk(txn.lockState(), _cappedNs);

            BSONObj op = updateFail();

            Sync s("");
            verify(!s.shouldRetry(&txn, op));
        }
开发者ID:AndrewCEmil,项目名称:mongo,代码行数:9,代码来源:replsettests.cpp

示例11: getInitialSyncFlag

 bool ReplSetImpl::getInitialSyncFlag() {
     OperationContextImpl txn; // XXX?
     Lock::DBRead lk (txn.lockState(), "local");
     BSONObj mv;
     if (Helpers::getSingleton(&txn, minvalidNS, mv)) {
         return mv[_initialSyncFlagString].trueValue();
     }
     return false;
 }
开发者ID:Rockyit,项目名称:mongo,代码行数:9,代码来源:repl_set_impl.cpp

示例12: lk

        ~IndexIteratorTests() {
            OperationContextImpl txn;
            Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(_ns), MODE_X);
            Client::Context ctx(&txn, _ns);
            WriteUnitOfWork wuow(&txn);

            _db->dropCollection(&txn, _ns);
            wuow.commit();
        }
开发者ID:Karl-Wu,项目名称:mongo,代码行数:9,代码来源:indexcatalogtests.cpp

示例13: setMinValid

    void ReplSetImpl::setMinValid(BSONObj obj) {
        BSONObjBuilder builder;
        BSONObjBuilder subobj(builder.subobjStart("$set"));
        subobj.appendTimestamp("ts", obj["ts"].date());
        subobj.done();

        OperationContextImpl txn; // XXX?
        Lock::DBWrite lk(txn.lockState(), "local");
        Helpers::putSingleton(&txn, "local.replset.minvalid", builder.obj());
    }
开发者ID:AndrewCEmil,项目名称:mongo,代码行数:10,代码来源:repl_set_impl.cpp

示例14: loadLastOpTimeWritten

 void ReplSetImpl::loadLastOpTimeWritten(bool quiet) {
     OperationContextImpl txn; // XXX?
     Lock::DBRead lk(txn.lockState(), rsoplog);
     BSONObj o;
     if (Helpers::getLast(&txn, rsoplog, o)) {
         lastH = o["h"].numberLong();
         lastOpTimeWritten = o["ts"]._opTime();
         uassert(13290, "bad replSet oplog entry?", quiet || !lastOpTimeWritten.isNull());
     }
 }
开发者ID:AndrewCEmil,项目名称:mongo,代码行数:10,代码来源:repl_set_impl.cpp

示例15: runCallbackWithGlobalExclusiveLock

    void NetworkInterfaceImpl::runCallbackWithGlobalExclusiveLock(
            const stdx::function<void (OperationContext*)>& callback) {

        std::ostringstream sb;
        sb << "repl" << boost::this_thread::get_id();
        Client::initThreadIfNotAlready(sb.str().c_str());
        OperationContextImpl txn;
        Lock::GlobalWrite lk(txn.lockState());
        callback(&txn);
    }
开发者ID:DieterLutz,项目名称:mongo,代码行数:10,代码来源:network_interface_impl.cpp


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