INT32 _pmdController::active () { INT32 rc = SDB_OK ; pmdEDUParam *pProtocolData = NULL ; pmdEDUMgr *pEDUMgr = pmdGetKRCB()->getEDUMgr() ; EDUID eduID = PMD_INVALID_EDUID ; rc = _restAdptor.init( _fixBufSize, _maxRestBodySize, _restTimeout ) ; PD_RC_CHECK( rc, PDERROR, "Failed to init rest adaptor, rc: %d", rc ) ; rc = pEDUMgr->startEDU( EDU_TYPE_SYNCCLOCK, NULL, &eduID ) ; pEDUMgr->regSystemEDU( EDU_TYPE_SYNCCLOCK, eduID ) ; rc = pEDUMgr->startEDU( EDU_TYPE_TCPLISTENER, (void*)_pTcpListener, &eduID ) ; PD_RC_CHECK( rc, PDERROR, "Failed to start tcp listerner, rc: %d", rc ) ; pEDUMgr->regSystemEDU( EDU_TYPE_TCPLISTENER, eduID ) ; rc = pEDUMgr->waitUntil ( eduID, PMD_EDU_RUNNING ) ; PD_RC_CHECK( rc, PDERROR, "Wait Tcp Listerner active failed, rc: %d", rc ) ; rc = pEDUMgr->startEDU( EDU_TYPE_RESTLISTENER, (void*)_pHttpListener, &eduID ) ; PD_RC_CHECK( rc, PDERROR, "Failed to start rest listerner, rc: %d", rc ) ; pEDUMgr->regSystemEDU( EDU_TYPE_RESTLISTENER, eduID ) ; rc = pEDUMgr->waitUntil ( eduID, PMD_EDU_RUNNING ) ; PD_RC_CHECK( rc, PDERROR, "Wait rest Listener active failed, rc: %d", rc ) ; if ( SDB_ROLE_COORD != pmdGetDBRole() ) { UINT32 pageTaskNum = pmdGetOptionCB()->getPageCleanNum() ; UINT32 pageIntervel = pmdGetOptionCB()->getPageCleanInterval() ; for ( UINT32 i = 0; i < pageTaskNum ; ++i ) { startPageCleanerJob( NULL, (INT32)pageIntervel ) ; } rtnStartLoadJob() ; } done: return rc ; error: goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__SDB_DMSCB_DISPATCHPAGECLEANSU, "_SDB_DMSCB::dispatchPageCleanSU" ) _dmsStorageUnit *_SDB_DMSCB::dispatchPageCleanSU ( dmsStorageUnitID *suID ) { PD_TRACE_ENTRY ( SDB__SDB_DMSCB_DISPATCHPAGECLEANSU ) ; *suID = DMS_INVALID_SUID ; pmdOptionsCB *optCB = pmdGetOptionCB() ; _dmsStorageUnit *su = NULL ; SDB_ASSERT ( suID, "suID can't be NULL" ) ; _pageCleanHistory firstSU ; ossTickDelta deltaTime ; ossScopedLock _lock(&_mutex, EXCLUSIVE) ; if ( _pageCleanHistoryList.size() == 0 ) goto done ; firstSU = _pageCleanHistoryList.front() ; deltaTime = pmdGetKRCB()->getCurTime () - firstSU.first ; if ( deltaTime.toUINT64() / 1000 > (UINT64)optCB->getPageCleanInterval() ) { PD_TRACE1 ( SDB__SDB_DMSCB_DISPATCHPAGECLEANSU, PD_PACK_ULONG ( firstSU.second ) ) ; if ( NULL != _cscbVec[firstSU.second] ) { *suID = firstSU.second ; _latchVec[*suID]->lock_r() ; su = _cscbVec[*suID]->_su ; } _pageCleanHistorySet.erase ( firstSU.second ) ; _pageCleanHistoryList.pop_front () ; } done : PD_TRACE_EXIT ( SDB__SDB_DMSCB_DISPATCHPAGECLEANSU ) ; return su ; }
void _CoordCB::updateCatGroupInfo( CoordGroupInfoPtr &groupInfo ) { ossScopedLock _lock(&_mutex, EXCLUSIVE) ; if ( _catGroupInfo->getGroupItem()->groupVersion() != groupInfo->getGroupItem()->groupVersion() ) { string oldCfg, newCfg ; pmdOptionsCB *optCB = pmdGetOptionCB() ; optCB->toString( oldCfg ) ; optCB->clearCatAddr() ; clearCatNodeAddrList() ; UINT32 pos = 0 ; MsgRouteID id ; string hostName ; string svcName ; while ( SDB_OK == groupInfo->getGroupItem()->getNodeInfo( pos, id, hostName, svcName, MSG_ROUTE_CAT_SERVICE ) ) { addCatNodeAddr( id, hostName.c_str(), svcName.c_str() ) ; optCB->setCatAddr( hostName.c_str(), svcName.c_str() ) ; ++pos ; } optCB->toString( newCfg ) ; if ( oldCfg != newCfg ) { optCB->reflush2File() ; } } _catGroupInfo = groupInfo ; }
dpsLockBucket::dpsLockBucket() { if ( 0 == _lockTimeout ) { ossScopedLock _lock( &_initMutex ); _lockTimeout = pmdGetOptionCB()->transTimeout() * 1000 ; } }
// PD_TRACE_DECLARE_FUNCTION ( SDB__CLSREPSET_INIT, "_clsReplicateSet::initialize" ) INT32 _clsReplicateSet::initialize () { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB__CLSREPSET_INIT ) ; if ( !_agent ) { rc = SDB_INVALIDARG ; goto error ; } g_startShiftTime = (INT32)pmdGetOptionCB()->startShiftTime() ; _logger = pmdGetKRCB()->getDPSCB() ; _clsCB = pmdGetKRCB()->getClsCB() ; SDB_ASSERT( NULL != _logger, "logger should not be NULL" ) ; _logger->regEventHandler( this ) ; rc = _replBucket.init() ; PD_RC_CHECK( rc, PDERROR, "Init repl bucket failed, rc: %d", rc ) ; _totalLogSize = (UINT64)pmdGetOptionCB()->getReplLogFileSz()* (UINT64)pmdGetOptionCB()->getReplLogFileNum() ; { UINT32 rate = 2 ; UINT32 timeBase = CLS_SYNCCTRL_BASE_TIME ; for ( UINT32 idx = 0 ; idx < CLS_SYNCCTRL_THRESHOLD_SIZE ; ++idx ) { rate = 2 << idx ; _sizethreshold[ idx ] = _totalLogSize * ( rate - 1 ) / rate ; _timeThreshold[ idx ] = timeBase << idx ; } } done: PD_TRACE_EXITRC ( SDB__CLSREPSET_INIT, rc ); return rc ; error: goto done ; }
INT32 _CoordCB::init () { INT32 rc = SDB_OK ; CoordGroupInfo *pGroupInfo = NULL ; UINT32 catGID = CATALOG_GROUPID ; UINT16 catNID = SYS_NODE_ID_BEGIN + CLS_REPLSET_MAX_NODE_SIZE ; MsgRouteID id ; pmdOptionsCB *optCB = pmdGetOptionCB() ; vector< _pmdAddrPair > catAddrs = optCB->catAddrs() ; _pNetWork = SDB_OSS_NEW _netRouteAgent( &_multiRouteAgent ) ; if ( !_pNetWork ) { PD_LOG( PDERROR, "Failed to alloc memory for net agent" ) ; rc = SDB_OOM ; goto error ; } _multiRouteAgent.setNetWork( _pNetWork ) ; pGroupInfo = SDB_OSS_NEW CoordGroupInfo( CAT_CATALOG_GROUPID ) ; if ( !pGroupInfo ) { PD_LOG( PDERROR, "Failed to alloc memory for group info" ) ; rc = SDB_OOM ; goto error ; } _catGroupInfo = CoordGroupInfoPtr( pGroupInfo ) ; for ( UINT32 i = 0 ; i < catAddrs.size() ; ++i ) { if ( 0 == catAddrs[i]._host[ 0 ] ) { break ; } id.columns.groupID = catGID ; id.columns.nodeID = catNID++ ; id.columns.serviceID = MSG_ROUTE_CAT_SERVICE ; addCatNodeAddr( id, catAddrs[i]._host, catAddrs[i]._service ) ; } pmdGetStartup().ok( TRUE ) ; pmdGetKRCB()->setGroupName( COORD_GROUPNAME ) ; { MsgRouteID id ; id.value = MSG_INVALID_ROUTEID ; id.columns.groupID = COORD_GROUPID ; pmdSetNodeID( id ) ; } done: return rc ; error: goto done ; }
INT32 pmdSignalTestEntryPoint( pmdEDUCB *cb, void *arg ) { pmdEDUCB *mainCB = ( pmdEDUCB* )arg ; INT32 interval = pmdGetOptionCB()->getSignalInterval() ; UINT32 timeCounter = 0 ; while( !cb->isDisconnected() ) { ossSleep( OSS_ONE_SEC ) ; ++timeCounter ; interval = pmdGetOptionCB()->getSignalInterval() ; if ( interval > 0 && timeCounter > (UINT32)interval ) { ossPThreadKill( mainCB->getThreadID(), OSS_TEST_SIGNAL ) ; timeCounter = 0 ; } } return SDB_OK ; }
INT32 _SDB_DMSCB::init () { INT32 rc = SDB_OK ; if ( SDB_ROLE_COORD != pmdGetDBRole() ) { rc = rtnLoadCollectionSpaces ( pmdGetOptionCB()->getDbPath(), pmdGetOptionCB()->getIndexPath(), pmdGetOptionCB()->getLobPath(), this ) ; PD_RC_CHECK( rc, PDERROR, "Failed to load collectionspaces, rc: %d", rc ) ; } rc = _tempCB.init() ; PD_RC_CHECK( rc, PDERROR, "Failed to init temp cb, rc: %d", rc ) ; done: return rc ; error: goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__CLSVSSL_HDTMOUT, "_clsVSSilence::handleTimeout" ) void _clsVSSilence::handleTimeout( const UINT32 &millisec, INT32 &next ) { PD_TRACE_ENTRY ( SDB__CLSVSSL_HDTMOUT ) ; _timeout() += millisec ; if ( pmdGetOptionCB()->sharingBreakTime() + 1000 <= _timeout() ) { next = CLS_ELECTION_STATUS_SEC ; goto done ; } next = id() ; done: PD_TRACE_EXIT ( SDB__CLSVSSL_HDTMOUT ) ; return ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__CLSSYNCMAG_GETARBITLSN, "_clsSyncManager::getSyncCtrlArbitLSN" ) DPS_LSN_OFFSET _clsSyncManager::getSyncCtrlArbitLSN() { DPS_LSN_OFFSET offset = DPS_INVALID_LSN_OFFSET ; INT32 syncSty = pmdGetOptionCB()->syncStrategy() ; PD_TRACE_ENTRY ( SDB__CLSSYNCMAG_GETARBITLSN ) ; if ( 0 == _validSync || CLS_SYNC_NONE == syncSty ) { goto done ; } else { _info->mtx.lock_r() ; for ( UINT32 i = 0 ; i < _validSync ; ++i ) { if ( DPS_INVALID_LSN_OFFSET == _notifyList[i].offset ) { continue ; } if ( CLS_SYNC_KEEPNORMAL == syncSty && FALSE == _notifyList[i].isValid() ) { continue ; } if ( DPS_INVALID_LSN_OFFSET == offset || _notifyList[i].offset < offset ) { offset = _notifyList[i].offset ; } } _info->mtx.release_r() ; } done: PD_TRACE_EXIT ( SDB__CLSSYNCMAG_GETARBITLSN ) ; return offset ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_CATALOGCB_INIT, "sdbCatalogueCB::init" ) INT32 sdbCatalogueCB::init() { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB_CATALOGCB_INIT ) ; _routeID.columns.serviceID = MSG_ROUTE_CAT_SERVICE ; _strHostName = pmdGetKRCB()->getHostName() ; _strCatServiceName = pmdGetOptionCB()->catService() ; IControlBlock *pClsCB = pmdGetKRCB()->getCBByType( SDB_CB_CLS ) ; IEventHolder *pHolder = NULL ; if ( pClsCB && pClsCB->queryInterface( SDB_IF_EVT_HOLDER ) ) { pHolder = (IEventHolder*)pClsCB->queryInterface( SDB_IF_EVT_HOLDER ) ; pHolder->regEventHandler( this ) ; } _pNetWork = SDB_OSS_NEW _netRouteAgent( &_catMainCtrl ) ; if ( !_pNetWork ) { PD_LOG ( PDERROR, "Failed to allocate memory for netRouteAgent" ) ; rc = SDB_OOM ; goto error ; } rc = _catMainCtrl.init() ; PD_RC_CHECK( rc, PDERROR, "Init main controller failed, rc: %d", rc ) ; rc = _catlogueMgr.init() ; PD_RC_CHECK( rc, PDERROR, "Init catlogue manager failed, rc: %d", rc ) ; rc = _catNodeMgr.init() ; PD_RC_CHECK( rc, PDERROR, "Init cat node manager failed, rc: %d", rc ) ; PD_TRACE1 ( SDB_CATALOGCB_INIT, PD_PACK_ULONG ( _routeID.value ) ) ; _pNetWork->setLocalID( _routeID ); rc = _pNetWork->updateRoute( _routeID, _strHostName.c_str(), _strCatServiceName.c_str() ); if ( rc != SDB_OK ) { PD_LOG ( PDERROR, "Failed to update route(routeID=%lld, host=%s, " "service=%s, rc=%d)", _routeID.value, _strHostName.c_str(), _strCatServiceName.c_str(), rc); goto error ; } rc = _pNetWork->listen( _routeID ); if ( rc != SDB_OK ) { PD_LOG ( PDERROR, "Failed to open listen-port(host=%s, service=%s, " "rc=%d)", _strHostName.c_str(), _strCatServiceName.c_str(), rc ); goto error ; } done: PD_TRACE_EXITRC ( SDB_CATALOGCB_INIT, rc ) ; return rc ; error: goto done ; }
INT32 _pmdController::active () { INT32 rc = SDB_OK ; pmdEDUMgr *pEDUMgr = pmdGetKRCB()->getEDUMgr() ; EDUID eduID = PMD_INVALID_EDUID ; rc = _restAdptor.init( _fixBufSize, _maxRestBodySize, _restTimeout ) ; PD_RC_CHECK( rc, PDERROR, "Failed to init rest adaptor, rc: %d", rc ) ; // start time sync edu rc = pEDUMgr->startEDU( EDU_TYPE_SYNCCLOCK, NULL, &eduID ) ; PD_RC_CHECK( rc, PDERROR, "Start sync clock edu failed, rc: %d", rc ) ; pEDUMgr->regSystemEDU( EDU_TYPE_SYNCCLOCK, eduID ) ; // start db monitor edu rc = pEDUMgr->startEDU( EDU_TYPE_DBMONITOR, NULL, &eduID ) ; PD_RC_CHECK( rc, PDERROR, "Start db monitor edu failed, rc: %d", rc ) ; pEDUMgr->regSystemEDU( EDU_TYPE_DBMONITOR, eduID ) ; #if defined ( _LINUX ) // start signal test if ( pmdGetOptionCB()->getSignalInterval() > 0 ) { pmdEDUCB *mainCB = pmdGetThreadEDUCB() ; rc = pEDUMgr->startEDU( EDU_TYPE_SIGNALTEST, (void*)mainCB, &eduID ) ; PD_RC_CHECK( rc, PDERROR, "Start signal test edu failed, rc: %d", rc ) ; pEDUMgr->regSystemEDU( EDU_TYPE_SIGNALTEST, eduID ) ; } #endif // _LINUX // start tcp listern edu and http listerner edu rc = pEDUMgr->startEDU( EDU_TYPE_TCPLISTENER, (void*)_pTcpListener, &eduID ) ; PD_RC_CHECK( rc, PDERROR, "Failed to start tcp listerner, rc: %d", rc ) ; pEDUMgr->regSystemEDU( EDU_TYPE_TCPLISTENER, eduID ) ; // wait until tcp listener starts rc = pEDUMgr->waitUntil ( eduID, PMD_EDU_RUNNING ) ; PD_RC_CHECK( rc, PDERROR, "Wait Tcp Listerner active failed, rc: %d", rc ) ; rc = pEDUMgr->startEDU( EDU_TYPE_RESTLISTENER, (void*)_pHttpListener, &eduID ) ; PD_RC_CHECK( rc, PDERROR, "Failed to start rest listerner, rc: %d", rc ) ; pEDUMgr->regSystemEDU( EDU_TYPE_RESTLISTENER, eduID ) ; // wait until http listener starts rc = pEDUMgr->waitUntil ( eduID, PMD_EDU_RUNNING ) ; PD_RC_CHECK( rc, PDERROR, "Wait rest Listener active failed, rc: %d", rc ) ; rc = activeForeignModule() ; PD_RC_CHECK( rc, PDERROR, "active Foreign module failed, rc: %d", rc ) ; // For non-coord nodes, we need to start page cleaners if ( SDB_ROLE_COORD != pmdGetDBRole() ) { UINT32 pageTaskNum = pmdGetOptionCB()->getPageCleanNum() ; UINT32 pageIntervel = pmdGetOptionCB()->getPageCleanInterval() ; // start page flush background task for ( UINT32 i = 0; i < pageTaskNum ; ++i ) { startPageCleanerJob( NULL, (INT32)pageIntervel ) ; } // start load job rtnStartLoadJob() ; } // For data nodes(both primary and slavery nodes), we need to start // dictionary creating threads. if ( SDB_ROLE_DATA == pmdGetDBRole() || SDB_ROLE_STANDALONE == pmdGetDBRole() ) { rc = startDictCreatorJob( NULL ) ; PD_RC_CHECK( rc, PDERROR, "Start dictionary creating job thread failed, " "rc: %d", rc ) ; } done: return rc ; error: goto done ; }
INT32 _pmdController::init () { INT32 rc = SDB_OK ; pmdOptionsCB *pOptCB = pmdGetOptionCB() ; UINT16 port = 0 ; UINT16 protocolPort = 0 ; port = pOptCB->getServicePort() ; _pTcpListener = SDB_OSS_NEW ossSocket( port ) ; if ( !_pTcpListener ) { PD_LOG( PDERROR, "Failed to alloc socket" ) ; rc = SDB_OOM ; goto error ; } rc = _pTcpListener->initSocket() ; PD_RC_CHECK( rc, PDERROR, "Failed to init tcp listener socket[%d], " "rc: %d", port, rc ) ; rc = _pTcpListener->bind_listen() ; PD_RC_CHECK( rc, PDERROR, "Failed to bind tcp listener socket[%d], " "rc: %d", port, rc ) ; PD_LOG( PDEVENT, "Listerning on port[%d]", port ) ; rc = ossGetPort( pOptCB->getRestService(), port ) ; PD_RC_CHECK( rc, PDERROR, "Failed to get port by service name: %s, " "rc: %d", pOptCB->getRestService(), rc ) ; _pHttpListener = SDB_OSS_NEW ossSocket( port ) ; if ( !_pHttpListener ) { PD_LOG( PDERROR, "Failed to alloc socket" ) ; rc = SDB_OOM ; goto error ; } rc = _pHttpListener->initSocket() ; PD_RC_CHECK( rc, PDERROR, "Failed to init http listener socket[%d], " "rc: %d", port, rc ) ; rc = _pHttpListener->bind_listen() ; PD_RC_CHECK( rc, PDERROR, "Failed to bind http listerner socket[%d], " "rc: %d", port, rc ) ; PD_LOG( PDEVENT, "Http Listerning on port[%d]", port ) ; if ( FALSE ) { protocolPort = ossAtoi( _protocol->getServiceName() ) ; _pMongoListener = SDB_OSS_NEW ossSocket( protocolPort ) ; if ( !_pMongoListener ) { PD_LOG( PDERROR, "Failed to alloc socket" ) ; rc = SDB_OOM ; goto error ; } rc = _pMongoListener->initSocket() ; PD_RC_CHECK( rc, PDERROR, "Failed to init FAP listener socket[%d], " "rc: %d", protocolPort, rc ) ; rc = _pMongoListener->bind_listen() ; PD_RC_CHECK( rc, PDERROR, "Failed to bind FAP listener socket[%d], " "rc: %d", protocolPort, rc ) ; PD_LOG( PDEVENT, "Listerning on port[%d]", protocolPort ) ; } done: return rc ; error: goto done ; }
INT32 _pmdController::init () { INT32 rc = SDB_OK ; pmdOptionsCB *pOptCB = pmdGetOptionCB() ; UINT16 port = 0 ; CHAR fapModuleName[ FAP_MODULE_NAME_SIZE + 1 ] = { 0 } ; if ( pOptCB->hasField( FAP_OPTION_NAME ) ) { pOptCB->getFieldStr( FAP_OPTION_NAME, fapModuleName, FAP_MODULE_NAME_SIZE, "" ) ; rc = initForeignModule( fapModuleName ) ; PD_RC_CHECK( rc, PDERROR, "Failed to init fap module, rc: %d", rc ) ; } // 1. create tcp listerner port = pOptCB->getServicePort() ; // memory will be freed in fini _pTcpListener = SDB_OSS_NEW ossSocket( port ) ; if ( !_pTcpListener ) { PD_LOG( PDERROR, "Failed to alloc socket" ) ; rc = SDB_OOM ; goto error ; } rc = _pTcpListener->initSocket() ; PD_RC_CHECK( rc, PDERROR, "Failed to init tcp listener socket[%d], " "rc: %d", port, rc ) ; rc = _pTcpListener->bind_listen() ; PD_RC_CHECK( rc, PDERROR, "Failed to bind tcp listener socket[%d], " "rc: %d", port, rc ) ; PD_LOG( PDEVENT, "Listerning on port[%d]", port ) ; // 2. create http listerner rc = ossGetPort( pOptCB->getRestService(), port ) ; PD_RC_CHECK( rc, PDERROR, "Failed to get port by service name: %s, " "rc: %d", pOptCB->getRestService(), rc ) ; _pHttpListener = SDB_OSS_NEW ossSocket( port ) ; if ( !_pHttpListener ) { PD_LOG( PDERROR, "Failed to alloc socket" ) ; rc = SDB_OOM ; goto error ; } rc = _pHttpListener->initSocket() ; PD_RC_CHECK( rc, PDERROR, "Failed to init http listener socket[%d], " "rc: %d", port, rc ) ; rc = _pHttpListener->bind_listen() ; PD_RC_CHECK( rc, PDERROR, "Failed to bind http listerner socket[%d], " "rc: %d", port, rc ) ; PD_LOG( PDEVENT, "Http Listerning on port[%d]", port ) ; done: return rc ; error: if ( SDB_NETWORK == rc ) { rc = SDB_NET_CANNOT_LISTEN ; } goto done ; }
INT32 rtnDumpBackups( const BSONObj &hint, rtnContextDump *context ) { INT32 rc = SDB_OK ; pmdKRCB *krcb = pmdGetKRCB () ; const CHAR *pPath = NULL ; const CHAR *backupName = NULL ; BOOLEAN isSubDir = FALSE ; const CHAR *prefix = NULL ; string bkpath ; BOOLEAN detail = FALSE ; barBackupMgr bkMgr( krcb->getGroupName() ) ; vector < BSONObj > vecBackup ; UINT32 index = 0 ; rc = rtnGetStringElement( hint, FIELD_NAME_PATH, &pPath ) ; if ( SDB_FIELD_NOT_EXIST == rc ) { rc = SDB_OK ; } PD_RC_CHECK( rc, PDWARNING, "Failed to get field[%s], rc: %d", FIELD_NAME_PATH, rc ) ; rc = rtnGetStringElement( hint, FIELD_NAME_NAME, &backupName ) ; if ( SDB_FIELD_NOT_EXIST == rc ) { rc = SDB_OK ; } PD_RC_CHECK( rc, PDWARNING, "Failed to get field[%s], rc: %d", FIELD_NAME_NAME, rc ) ; rc = rtnGetBooleanElement( hint, FIELD_NAME_DETAIL, detail ) ; if ( SDB_FIELD_NOT_EXIST == rc ) { rc = SDB_OK ; } PD_RC_CHECK( rc, PDWARNING, "Failed to get field[%s], rc: %d", FIELD_NAME_DETAIL, rc ) ; rc = rtnGetBooleanElement( hint, FIELD_NAME_ISSUBDIR, isSubDir ) ; if ( SDB_FIELD_NOT_EXIST == rc ) { rc = SDB_OK ; } PD_RC_CHECK( rc, PDWARNING, "Failed to get field[%s], rc: %d", FIELD_NAME_ISSUBDIR, rc ) ; rc = rtnGetStringElement( hint, FIELD_NAME_PREFIX, &prefix ) ; if ( SDB_FIELD_NOT_EXIST == rc ) { rc = SDB_OK ; } PD_RC_CHECK( rc, PDWARNING, "Failed to get field[%s], rc: %d", FIELD_NAME_PREFIX, rc ) ; if ( isSubDir && pPath ) { bkpath = rtnFullPathName( pmdGetOptionCB()->getBkupPath(), pPath ) ; } else if ( pPath && 0 != pPath[0] ) { bkpath = pPath ; } else { bkpath = pmdGetOptionCB()->getBkupPath() ; } rc = bkMgr.init( bkpath.c_str(), backupName, prefix ) ; PD_RC_CHECK( rc, PDWARNING, "Init backup manager failed, rc: %d", rc ) ; rc = bkMgr.list( vecBackup, detail ) ; PD_RC_CHECK( rc, PDWARNING, "List backup failed, rc: %d", rc ) ; while ( index < vecBackup.size() ) { rc = context->monAppend( vecBackup[index] ) ; PD_RC_CHECK( rc, PDERROR, "Add to obj[%s] to context failed, " "rc: %d", vecBackup[index].toString().c_str(), rc ) ; ++index ; } done: return rc ; error: goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_RTNBACKUP, "rtnBackup" ) INT32 rtnBackup( pmdEDUCB *cb, const CHAR *path, const CHAR *backupName, BOOLEAN ensureInc, BOOLEAN rewrite, const CHAR *desp, const BSONObj &option ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB_RTNBACKUP ) ; string bkpath ; INT32 maxDataFileSize = 0 ; barBKOfflineLogger logger ; BOOLEAN isSubDir = FALSE ; BOOLEAN enableDateDir = FALSE ; BOOLEAN backupLog = FALSE ; const CHAR *prefix = NULL ; BOOLEAN compressed = TRUE ; const CHAR *pCompType = VALUE_NAME_SNAPPY ; UTIL_COMPRESSOR_TYPE compType = UTIL_COMPRESSOR_INVALID ; rc = rtnGetBooleanElement( option, FIELD_NAME_ISSUBDIR, isSubDir ) ; if ( SDB_FIELD_NOT_EXIST == rc ) { rc = SDB_OK ; } PD_RC_CHECK( rc, PDWARNING, "Failed to get field[%s], rc: %d", FIELD_NAME_ISSUBDIR, rc ) ; rc = rtnGetIntElement( option, FIELD_NAME_MAX_DATAFILE_SIZE, maxDataFileSize ) ; if ( SDB_FIELD_NOT_EXIST == rc ) { rc = SDB_OK ; } PD_RC_CHECK( rc, PDWARNING, "Failed to get field[%s], rc: %d", FIELD_NAME_MAX_DATAFILE_SIZE, rc ) ; rc = rtnGetBooleanElement( option, FIELD_NAME_ENABLE_DATEDIR, enableDateDir ) ; if ( SDB_FIELD_NOT_EXIST == rc ) { rc = SDB_OK ; } PD_RC_CHECK( rc, PDWARNING, "Failed to get field[%s], rc: %d", FIELD_NAME_ENABLE_DATEDIR, rc ) ; rc = rtnGetStringElement( option, FIELD_NAME_PREFIX, &prefix ) ; if ( SDB_FIELD_NOT_EXIST == rc ) { rc = SDB_OK ; } PD_RC_CHECK( rc, PDWARNING, "Failed to get field[%s], rc: %d", FIELD_NAME_PREFIX, rc ) ; rc = rtnGetBooleanElement( option, FIELD_NAME_BACKUP_LOG, backupLog ) ; if ( SDB_FIELD_NOT_EXIST == rc ) { rc = SDB_OK ; } PD_RC_CHECK( rc, PDWARNING, "Failed to get field[%s], rc: %d", FIELD_NAME_BACKUP_LOG, rc ) ; rc = rtnGetBooleanElement( option, FIELD_NAME_COMPRESSED, compressed ) ; if ( SDB_FIELD_NOT_EXIST == rc ) { rc = SDB_OK ; } PD_RC_CHECK( rc, PDWARNING, "Failed to get field[%s], rc: %d", FIELD_NAME_COMPRESSED, rc ) ; rc = rtnGetStringElement( option, FIELD_NAME_COMPRESSIONTYPE, &pCompType ) ; if ( SDB_FIELD_NOT_EXIST == rc ) { rc = SDB_OK ; } PD_RC_CHECK( rc, PDWARNING, "Failed to get field[%s], rc: %d", FIELD_NAME_COMPRESSIONTYPE, rc ) ; compType = utilString2CompressType( pCompType ) ; if ( UTIL_COMPRESSOR_INVALID == compType || UTIL_COMPRESSOR_LZW == compType ) { PD_LOG( PDERROR, "Field[%s]'s value[%s] is invalid, only support: %s", FIELD_NAME_COMPRESSIONTYPE, pCompType, "snappy/lz4/zlib" ) ; rc = SDB_INVALIDARG ; goto error ; } if ( maxDataFileSize < BAR_MIN_DATAFILE_SIZE || maxDataFileSize > BAR_MAX_DATAFILE_SIZE ) { maxDataFileSize = BAR_DFT_DATAFILE_SIZE ; } if ( isSubDir && path ) { bkpath = rtnFullPathName( pmdGetOptionCB()->getBkupPath(), path ) ; } else if ( path && 0 != path[0] ) { bkpath = path ; } else { bkpath = pmdGetOptionCB()->getBkupPath() ; } if ( enableDateDir ) { bkpath = rtnFullPathName( bkpath, _rtnMakeDateDirName() ) ; } rc = logger.init( bkpath.c_str(), backupName, maxDataFileSize, prefix, ensureInc ? BAR_BACKUP_OP_TYPE_INC : BAR_BACKUP_OP_TYPE_FULL, rewrite, desp ) ; PD_RC_CHECK( rc, PDERROR, "Init off line backup logger failed, rc: %d", rc ) ; logger.setBackupLog( backupLog ) ; logger.enableCompress( compressed, compType ) ; rc = logger.backup( cb ) ; PD_RC_CHECK( rc, PDERROR, "Off line backup failed, rc: %d", rc ) ; done: PD_TRACE_EXITRC ( SDB_RTNBACKUP, rc ) ; return rc ; error: goto done ; }
INT32 rtnRemoveBackup( pmdEDUCB *cb, const CHAR *path, const CHAR *backupName, const BSONObj &option ) { INT32 rc = SDB_OK ; pmdKRCB *krcb = pmdGetKRCB () ; BOOLEAN isSubDir = FALSE ; const CHAR *prefix = NULL ; string bkpath ; INT32 incID = -1 ; barBackupMgr bkMgr( krcb->getGroupName() ) ; rc = rtnGetBooleanElement( option, FIELD_NAME_ISSUBDIR, isSubDir ) ; if ( SDB_FIELD_NOT_EXIST == rc ) { rc = SDB_OK ; } PD_RC_CHECK( rc, PDWARNING, "Failed to get field[%s], rc: %d", FIELD_NAME_ISSUBDIR, rc ) ; rc = rtnGetStringElement( option, FIELD_NAME_PREFIX, &prefix ) ; if ( SDB_FIELD_NOT_EXIST == rc ) { rc = SDB_OK ; } PD_RC_CHECK( rc, PDWARNING, "Failed to get field[%s], rc: %d", FIELD_NAME_PREFIX, rc ) ; rc = rtnGetIntElement( option, FIELD_NAME_ID, incID ) ; if ( SDB_FIELD_NOT_EXIST == rc ) { rc = SDB_OK ; } PD_RC_CHECK( rc, PDWARNING, "Failed to get field[%s], rc: %d", FIELD_NAME_ID, rc ) ; if ( isSubDir && path ) { bkpath = rtnFullPathName( pmdGetOptionCB()->getBkupPath(), path ) ; } else if ( path && 0 != path[0] ) { bkpath = path ; } else { bkpath = pmdGetOptionCB()->getBkupPath() ; } rc = bkMgr.init( bkpath.c_str(), backupName, prefix ) ; PD_RC_CHECK( rc, PDERROR, "Failed to init backup manager, rc: %d", rc ) ; rc = bkMgr.drop( incID ) ; PD_RC_CHECK( rc, PDERROR, "Failed to drop backup[%s], ID:%d, rc: %d", bkMgr.backupName(), incID, rc ) ; done: return rc ; error: goto done ; }