• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ WriteBackManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _writebackQueueLock

namespace mongo {

    // ---------- WriteBackManager class ----------

    // TODO init at mongod startup
    WriteBackManager writeBackManager;

    WriteBackManager::WriteBackManager() : _writebackQueueLock("sharding:writebackQueueLock") {
    }

    WriteBackManager::~WriteBackManager() {
    }

    OID WriteBackManager::queueWriteBack( const string& remote , BSONObjBuilder& b ) {
        static mongo::mutex writebackIDOrdering( "WriteBackManager::queueWriteBack id ordering" );
        
        scoped_lock lk( writebackIDOrdering );

        OID writebackID;
        writebackID.initSequential();
        b.append( "id", writebackID );
        
        getWritebackQueue( remote )->queue.push( b.obj() );

        return writebackID;
    }

    shared_ptr<WriteBackManager::QueueInfo> WriteBackManager::getWritebackQueue( const string& remote ) {
        scoped_lock lk ( _writebackQueueLock );
        shared_ptr<QueueInfo>& q = _writebackQueues[remote];
        if ( ! q )
            q.reset( new QueueInfo() );
        q->lastCall = Listener::getElapsedTimeMillis();
        return q;
    }

    bool WriteBackManager::queuesEmpty() const {
        scoped_lock lk( _writebackQueueLock );
        for ( WriteBackQueuesMap::const_iterator it = _writebackQueues.begin(); it != _writebackQueues.end(); ++it ) {
            const shared_ptr<QueueInfo> queue = it->second;
            if (! queue->queue.empty() ) {
                return false;
            }
        }
        return true;
    }

    void WriteBackManager::appendStats( BSONObjBuilder& b ) const {
        BSONObjBuilder sub;
        long long totalQueued = 0;
        long long now = Listener::getElapsedTimeMillis();
        {
            scoped_lock lk( _writebackQueueLock );
            for ( WriteBackQueuesMap::const_iterator it = _writebackQueues.begin(); it != _writebackQueues.end(); ++it ) {
                const shared_ptr<QueueInfo> queue = it->second;

                BSONObjBuilder t( sub.subobjStart( it->first ) );
                t.appendNumber( "n" , queue->queue.size() );
                t.appendNumber( "minutesSinceLastCall" , ( now - queue->lastCall ) / ( 1000 * 60 ) );
                t.done();

                totalQueued += queue->queue.size();
            }
        }

        b.appendBool( "hasOpsQueued" , totalQueued > 0 );
        b.appendNumber( "totalOpsQueued" , totalQueued );
        b.append( "queues" , sub.obj() );
    }

    bool WriteBackManager::cleanupOldQueues() {
        long long now = Listener::getElapsedTimeMillis();

        scoped_lock lk( _writebackQueueLock );
        for ( WriteBackQueuesMap::iterator it = _writebackQueues.begin(); it != _writebackQueues.end(); ++it ) {
            const shared_ptr<QueueInfo> queue = it->second;
            long long sinceMinutes = ( now - queue->lastCall ) / ( 1000 * 60 );

            if ( sinceMinutes < 60 ) // minutes of inactivity.
                continue;

            log() << "deleting queue from: " << it->first
                  << " of size: " << queue->queue.size()
                  << " after " << sinceMinutes << " inactivity"
                  << " (normal if any mongos has restarted)"
                  << endl;

            _writebackQueues.erase( it );
            return true;
        }
        return false;
    }

    void WriteBackManager::Cleaner::taskDoWork() {
        for ( int i=0; i<1000; i++ ) {
            if ( ! writeBackManager.cleanupOldQueues() )
                break;
        }
    }

//.........这里部分代码省略.........
开发者ID:AshishThakur,项目名称:mongo,代码行数:101,代码来源:d_writeback.cpp


示例2:

 void WriteBackManager::Cleaner::taskDoWork() {
     for ( int i=0; i<1000; i++ ) {
         if ( ! writeBackManager.cleanupOldQueues() )
             break;
     }
 }
开发者ID:AshishThakur,项目名称:mongo,代码行数:6,代码来源:d_writeback.cpp


示例3: _writebackQueueLock

namespace mongo {

    // ---------- WriteBackManager class ----------

    // TODO init at mongod startup
    WriteBackManager writeBackManager;

    WriteBackManager::WriteBackManager() : _writebackQueueLock("sharding:writebackQueueLock") {
    }

    WriteBackManager::~WriteBackManager() {
    }

    void WriteBackManager::queueWriteBack( const string& remote , const BSONObj& o ) {
        getWritebackQueue( remote )->queue.push( o );
    }

    shared_ptr<WriteBackManager::QueueInfo> WriteBackManager::getWritebackQueue( const string& remote ) {
        scoped_lock lk ( _writebackQueueLock );
        shared_ptr<QueueInfo>& q = _writebackQueues[remote];
        if ( ! q )
            q.reset( new QueueInfo() );
        q->lastCall = Listener::getElapsedTimeMillis();
        return q;
    }

    bool WriteBackManager::queuesEmpty() const {
        scoped_lock lk( _writebackQueueLock );
        for ( WriteBackQueuesMap::const_iterator it = _writebackQueues.begin(); it != _writebackQueues.end(); ++it ) {
            const shared_ptr<QueueInfo> queue = it->second;
            if (! queue->queue.empty() ) {
                return false;
            }
        }
        return true;
    }

    void WriteBackManager::appendStats( BSONObjBuilder& b ) const {
        BSONObjBuilder sub;
        long long totalQueued = 0;
        long long now = Listener::getElapsedTimeMillis();
        {
            scoped_lock lk( _writebackQueueLock );
            for ( WriteBackQueuesMap::const_iterator it = _writebackQueues.begin(); it != _writebackQueues.end(); ++it ) {
                const shared_ptr<QueueInfo> queue = it->second;
                
                BSONObjBuilder t( sub.subobjStart( it->first ) );
                t.appendNumber( "n" , queue->queue.size() );
                t.appendNumber( "minutesSinceLastCall" , ( now - queue->lastCall ) / ( 1000 * 60 ) );
                t.done();

                totalQueued += queue->queue.size();
            }
        }
        
        b.appendBool( "hasOpsQueued" , totalQueued > 0 );
        b.appendNumber( "totalOpsQueued" , totalQueued );
        b.append( "queues" , sub.obj() );
    }

    bool WriteBackManager::cleanupOldQueues() {
        long long now = Listener::getElapsedTimeMillis();

        scoped_lock lk( _writebackQueueLock );
        for ( WriteBackQueuesMap::iterator it = _writebackQueues.begin(); it != _writebackQueues.end(); ++it ) {
            const shared_ptr<QueueInfo> queue = it->second;
            long long sinceMinutes = ( now - queue->lastCall ) / ( 1000 * 60 );

            if ( sinceMinutes < 60 ) // minutes of inactivity.  
                continue;
            
            log() << "deleting queue from: " << it->first 
                  << " of size: " << queue->queue.size() 
                  << " after " << sinceMinutes << " inactivity" 
                  << " (normal if any mongos has restarted)" 
                  << endl;

            _writebackQueues.erase( it );
            return true;
        }
        return false;
    }

    void WriteBackManager::Cleaner::taskDoWork() { 
        for ( int i=0; i<1000; i++ ) {
            if ( ! writeBackManager.cleanupOldQueues() )
                break;
        }
    }

    // ---------- admin commands ----------

    // Note, this command will block until there is something to WriteBack
    class WriteBackCommand : public Command {
    public:
        virtual LockType locktype() const { return NONE; }
        virtual bool slaveOk() const { return true; }
        virtual bool adminOnly() const { return true; }

        WriteBackCommand() : Command( "writebacklisten" ) {}
//.........这里部分代码省略.........
开发者ID:tanakh,项目名称:mongo,代码行数:101,代码来源:d_writeback.cpp


示例4: run

        bool run(const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {

            BSONElement e = cmdObj.firstElement();
            if ( e.type() != jstOID ) {
                errmsg = "need oid as first value";
                return 0;
            }

            // get the command issuer's (a mongos) serverID
            const OID id = e.__oid();

            // the command issuer is blocked awaiting a response
            // we want to do return at least at every 5 minutes so sockets don't timeout
            BSONObj z;
            if ( writeBackManager.getWritebackQueue(id.str())->queue.blockingPop( z, 5 * 60 /* 5 minutes */ ) ) {
                MONGO_LOG(1) << "WriteBackCommand got : " << z << endl;
                result.append( "data" , z );
            }
            else {
                result.appendBool( "noop" , true );
            }

#ifdef _DEBUG
            // Sleep a short amount of time usually
            int sleepFor = rand() % 10;
            sleepmillis( sleepFor );

            // Sleep a longer amount of time every once and awhile
            int sleepLong = rand() % 50;
            if( sleepLong == 0 ) sleepsecs( 2 );
#endif

            return true;
        }
开发者ID:tanakh,项目名称:mongo,代码行数:34,代码来源:d_writeback.cpp


示例5: run

        bool run(const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {

            cc().curop()->suppressFromCurop();
            cc().curop()->setExpectedLatencyMs( 30000 );

            BSONElement e = cmdObj.firstElement();
            if ( e.type() != jstOID ) {
                errmsg = "need oid as first value";
                return 0;
            }

            // get the command issuer's (a mongos) serverID
            const OID id = e.__oid();

            // the command issuer is blocked awaiting a response
            // we want to do return at least at every 5 minutes so sockets don't timeout
            BSONObj z;
            if ( writeBackManager.getWritebackQueue(id.str())->queue.blockingPop( z, 5 * 60 /* 5 minutes */ ) ) {
                LOG(1) << "WriteBackCommand got : " << z << endl;
                result.append( "data" , z );
            }
            else {
                result.appendBool( "noop" , true );
            }

#ifdef _DEBUG
            PseudoRandom r(static_cast<int64_t>(time(0)));
            // Sleep a short amount of time usually
            int sleepFor = r.nextInt32( 10 );
            sleepmillis( sleepFor );

            // Sleep a longer amount of time every once and awhile
            int sleepLong = r.nextInt32( 50 );
            if( sleepLong == 0 ) sleepsecs( 2 );
#endif

            return true;
        }
开发者ID:AshishThakur,项目名称:mongo,代码行数:38,代码来源:d_writeback.cpp


示例6: run

        bool run(const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {

            BSONElement e = cmdObj.firstElement();
            if ( e.type() != jstOID ) {
                errmsg = "need oid as first value";
                return 0;
            }

            // get the command issuer's (a mongos) serverID
            const OID id = e.__oid();

            // the command issuer is blocked awaiting a response
            // we want to do return at least at every 5 minutes so sockets don't timeout
            BSONObj z;
            if ( writeBackManager.getWritebackQueue(id.str())->queue.blockingPop( z, 5 * 60 /* 5 minutes */ ) ) {
                log(1) << "WriteBackCommand got : " << z << endl;
                result.append( "data" , z );
            }
            else {
                result.appendBool( "noop" , true );
            }

            return true;
        }
开发者ID:dgriffith,项目名称:mongo,代码行数:24,代码来源:d_writeback.cpp


示例7: appendAtLeaf

 virtual void appendAtLeaf( BSONObjBuilder& b ) const {
     b.appendBool( _leafName, ! writeBackManager.queuesEmpty() );
 }
开发者ID:AshishThakur,项目名称:mongo,代码行数:3,代码来源:d_writeback.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ WriteBuffer类代码示例发布时间:2022-05-31
下一篇:
C++ WritableROM类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap