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


C++ OplogReader::getRollbackCursor方法代码示例

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


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

示例1: runRollback

    void BackgroundSync::runRollback(OplogReader& r, uint64_t oplogTS) {
        // starting from ourLast, we need to read the remote oplog
        // backwards until we find an entry in the remote oplog
        // that has the same GTID, timestamp, and hash as
        // what we have in our oplog. If we don't find one that is within
        // some reasonable timeframe, then we go fatal
        GTID ourLast = theReplSet->gtidManager->getLiveState();
        GTID idToRollbackTo;
        uint64_t rollbackPointTS = 0;
        uint64_t rollbackPointHash = 0;
        incRBID();
        try {
            shared_ptr<DBClientCursor> rollbackCursor = r.getRollbackCursor(ourLast);
            while (rollbackCursor->more()) {
                BSONObj remoteObj = rollbackCursor->next();
                GTID remoteGTID = getGTIDFromBSON("_id", remoteObj);
                uint64_t remoteTS = remoteObj["ts"]._numberLong();
                uint64_t remoteLastHash = remoteObj["h"].numberLong();
                if (remoteTS + 1800*1000 < oplogTS) {
                    log() << "Rollback takes us too far back, throwing exception. remoteTS: " << remoteTS << " oplogTS: " << oplogTS << rsLog;
                    throw RollbackOplogException("replSet rollback too long a time period for a rollback (at least 30 minutes).");
                    break;
                }
                //now try to find an entry in our oplog with that GTID
                BSONObjBuilder localQuery;
                BSONObj localObj;
                addGTIDToBSON("_id", remoteGTID, localQuery);
                bool foundLocally = false;
                {
                    LOCK_REASON(lockReason, "repl: looking up oplog entry for rollback");
                    Client::ReadContext ctx(rsoplog, lockReason);
                    Client::Transaction transaction(DB_SERIALIZABLE);
                    foundLocally = Collection::findOne(rsoplog, localQuery.done(), localObj);
                    transaction.commit();
                }
                if (foundLocally) {
                    GTID localGTID = getGTIDFromBSON("_id", localObj);
                    uint64_t localTS = localObj["ts"]._numberLong();
                    uint64_t localLastHash = localObj["h"].numberLong();
                    if (localLastHash == remoteLastHash &&
                        localTS == remoteTS &&
                        GTID::cmp(localGTID, remoteGTID) == 0
                        )
                    {
                        idToRollbackTo = localGTID;
                        rollbackPointTS = localTS;
                        rollbackPointHash = localLastHash;
                        log() << "found id to rollback to " << idToRollbackTo << rsLog;
                        break;
                    }
                }
            }
            // At this point, either we have found the point to try to rollback to,
            // or we have determined that we cannot rollback
            if (idToRollbackTo.isInitial()) {
                // we cannot rollback
                throw RollbackOplogException("could not find ID to rollback to");
            }
        }
        catch (DBException& e) {
            log() << "Caught DBException during rollback " << e.toString() << rsLog;
            throw RollbackOplogException("DBException while trying to find ID to rollback to: " + e.toString());
        }
        catch (std::exception& e2) {
            log() << "Caught std::exception during rollback " << e2.what() << rsLog;
            throw RollbackOplogException(str::stream() << "Exception while trying to find ID to rollback to: " << e2.what());
        }

        // proceed with the rollback to point idToRollbackTo
        // probably ought to grab a global write lock while doing this
        // I don't think we want oplog cursors reading from this machine
        // while we are rolling back. Or at least do something to protect against this

        // first, let's get all the operations that are being applied out of the way,
        // we don't want to rollback an item in the oplog while simultaneously,
        // the applier thread is applying it to the oplog
        {
            boost::unique_lock<boost::mutex> lock(_mutex);
            while (_deque.size() > 0) {
                log() << "waiting for applier to finish work before doing rollback " << rsLog;
                _queueDone.wait(lock);
            }
            verifySettled();
        }

        // now let's tell the system we are going to rollback, to do so,
        // abort live multi statement transactions, invalidate cursors, and
        // change the state to RS_ROLLBACK
        {
            // so we know nothing is simultaneously occurring
            RWLockRecursive::Exclusive e(operationLock);
            LOCK_REASON(lockReason, "repl: killing all operations for rollback");
            Lock::GlobalWrite lk(lockReason);
            ClientCursor::invalidateAllCursors();
            Client::abortLiveTransactions();
            theReplSet->goToRollbackState();
        }

        try {
            // now that we are settled, we have to take care of the GTIDManager
//.........这里部分代码省略.........
开发者ID:igagnidz,项目名称:tokumx,代码行数:101,代码来源:bgsync.cpp

示例2: findRollbackPoint

 void findRollbackPoint(
     OplogReader& r, uint64_t oplogTS,
     GTID* idToRollbackTo,
     uint64_t* rollbackPointTS,
     uint64_t* rollbackPointHash
     )
 {
     bool gtidFound = false;
     try {
         GTID ourLast = theReplSet->gtidManager->getLiveState();
         shared_ptr<DBClientCursor> rollbackCursor = r.getRollbackCursor(ourLast);
         uassert(17350, "rollback failed to get a cursor to start reading backwards from.", rollbackCursor.get());
         while (rollbackCursor->more()) {
             BSONObj remoteObj = rollbackCursor->next();
             GTID remoteGTID = getGTIDFromBSON("_id", remoteObj);
             uint64_t remoteTS = remoteObj["ts"]._numberLong();
             uint64_t remoteLastHash = remoteObj["h"].numberLong();
             if (remoteTS + 1800*1000 < oplogTS) {
                 log() << "Rollback takes us too far back, throwing exception. remoteTS: " << remoteTS << " oplogTS: " << oplogTS << rsLog;
                 throw RollbackOplogException("replSet rollback too long a time period for a rollback (at least 30 minutes).");
                 break;
             }
             //now try to find an entry in our oplog with that GTID
             BSONObjBuilder localQuery;
             BSONObj localObj;
             addGTIDToBSON("_id", remoteGTID, localQuery);
             bool foundLocally = false;
             {
                 LOCK_REASON(lockReason, "repl: looking up oplog entry for rollback");
                 Client::ReadContext ctx(rsoplog, lockReason);
                 Client::Transaction transaction(DB_SERIALIZABLE);
                 foundLocally = Collection::findOne(rsoplog, localQuery.done(), localObj);
                 transaction.commit();
             }
             if (foundLocally) {
                 GTID localGTID = getGTIDFromBSON("_id", localObj);
                 uint64_t localTS = localObj["ts"]._numberLong();
                 uint64_t localLastHash = localObj["h"].numberLong();
                 if (localLastHash == remoteLastHash &&
                     localTS == remoteTS &&
                     GTID::cmp(localGTID, remoteGTID) == 0
                     )
                 {
                     *idToRollbackTo = localGTID;
                     *rollbackPointTS = localTS;
                     *rollbackPointHash = localLastHash;
                     gtidFound = true;
                     log() << "found id to rollback to " << idToRollbackTo->toString() << rsLog;
                     break;
                 }
             }
         }
         // At this point, either we have found the point to try to rollback to,
         // or we have determined that we cannot rollback
         if (!gtidFound) {
             // we cannot rollback
             throw RollbackOplogException("could not find ID to rollback to");
         }
     }
     catch (DBException& e) {
         log() << "Caught DBException during rollback " << e.toString() << rsLog;
         throw RollbackOplogException("DBException while trying to find ID to rollback to: " + e.toString());
     }
     catch (std::exception& e2) {
         log() << "Caught std::exception during rollback " << e2.what() << rsLog;
         throw RollbackOplogException(str::stream() << "Exception while trying to find ID to rollback to: " << e2.what());
     }
 }
开发者ID:7segments,项目名称:mongo,代码行数:68,代码来源:rs_rollback.cpp


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