Beispiel #1
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB__CLSSYNCMAG_GETSYNCSRC, "_clsSyncManager::getSyncSrc" )
   MsgRouteID _clsSyncManager::getSyncSrc( const set<UINT64> &blacklist )
   {
      PD_TRACE_ENTRY ( SDB__CLSSYNCMAG_GETSYNCSRC ) ;
      MsgRouteID res ;
      res.value = MSG_INVALID_ROUTEID ;

      _info->mtx.lock_r() ;
      map<UINT64, _clsSharingStatus *>::iterator itr =
                      _info->alives.find( _info->primary.value ) ;
      if ( _info->alives.end() != itr &&
           CLS_SYNC_STATUS_PEER ==
           itr->second->beat.syncStatus )
      {
         res.value = itr->first ;
         goto done ;
      }
      else
      {
         MsgRouteID ids[CLS_SYNC_SET_NUM] ;
         UINT32 validNum = 0 ;
         itr = _info->alives.begin() ;
         for ( ; itr != _info->alives.end(); itr++ )
         {
            if ( CLS_SYNC_STATUS_PEER == itr->second->beat.syncStatus &&
                 0 == blacklist.count( itr->first ) )
            {
               ids[validNum++].value = itr->first ;
            }
         }
         if ( 0 == validNum )
         {
            itr = _info->alives.begin() ;
            for ( ; itr != _info->alives.end(); itr++ )
            {
               if ( CLS_SYNC_STATUS_RC == itr->second->beat.syncStatus &&
                    itr->first != _info->primary.value &&
                    0 == blacklist.count( itr->first ))
               {
                  ids[validNum++].value = itr->first ;
               }
            }
            if ( 0 != validNum )
            {
               res.value = ids[ossRand() % validNum].value ;
            }
            else
            {
               res.value = _info->primary.value ;
            }
         }
         else
         {
            res.value = ids[ossRand() % validNum].value ;
         }
      }
   done:
      _info->mtx.release_r() ;
      PD_TRACE_EXIT ( SDB__CLSSYNCMAG_GETSYNCSRC ) ;
      return res ;
   }
Beispiel #2
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB__DMSSU, "_dmsStorageUnit::_dmsStorageUnit" )
   _dmsStorageUnit::_dmsStorageUnit ( const CHAR *pSUName, UINT32 sequence,
                                      INT32 pageSize, INT32 lobPageSize )
   :_apm(this),
    _pDataSu( NULL ),
    _pIndexSu( NULL ),
    _pLobSu( NULL )
   {
      PD_TRACE_ENTRY ( SDB__DMSSU ) ;
      SDB_ASSERT ( pSUName, "name can't be null" ) ;

      if ( 0 == pageSize )
      {
         pageSize = DMS_PAGE_SIZE_DFT ;
      }

      if ( 0 == lobPageSize )
      {
         lobPageSize = DMS_DEFAULT_LOB_PAGE_SZ ;
      }

      CHAR dataFileName[DMS_SU_FILENAME_SZ + 1] = {0} ;
      CHAR idxFileName[DMS_SU_FILENAME_SZ + 1] = {0} ;

      _storageInfo._pageSize = pageSize ;
      _storageInfo._lobdPageSize = lobPageSize ;
      ossStrncpy( _storageInfo._suName, pSUName, DMS_SU_NAME_SZ ) ;
      _storageInfo._suName[DMS_SU_NAME_SZ] = 0 ;
      _storageInfo._sequence = sequence ;
      _storageInfo._secretValue = ossPack32To64( (UINT32)time(NULL),
                                                 (UINT32)(ossRand()*239641) ) ;

      ossSnprintf( dataFileName, DMS_SU_FILENAME_SZ, "%s.%d.%s",
                   _storageInfo._suName, sequence, DMS_DATA_SU_EXT_NAME ) ;
      ossSnprintf( idxFileName, DMS_SU_FILENAME_SZ, "%s.%d.%s",
                   _storageInfo._suName, sequence, DMS_INDEX_SU_EXT_NAME ) ;

      _pDataSu = SDB_OSS_NEW dmsStorageData( dataFileName, &_storageInfo ) ;
      if ( _pDataSu )
      {
         _pIndexSu = SDB_OSS_NEW dmsStorageIndex( idxFileName, &_storageInfo,
                                                  _pDataSu ) ;
      }

      if ( NULL != _pDataSu && NULL != _pIndexSu )
      {
         ossMemset( dataFileName, 0, sizeof( dataFileName ) ) ;
         ossMemset( idxFileName, 0 , sizeof( idxFileName ) ) ;
         ossSnprintf( dataFileName, DMS_SU_FILENAME_SZ, "%s.%d.%s",
                      _storageInfo._suName, _storageInfo._sequence,
                      DMS_LOB_META_SU_EXT_NAME ) ;
         ossSnprintf( idxFileName, DMS_SU_FILENAME_SZ, "%s.%d.%s",
                      _storageInfo._suName, _storageInfo._sequence,
                      DMS_LOB_DATA_SU_EXT_NAME ) ;

         _pLobSu = SDB_OSS_NEW dmsStorageLob( dataFileName, idxFileName,
                                              &_storageInfo, _pDataSu ) ;
      }

      PD_TRACE_EXIT ( SDB__DMSSU ) ;
   }
Beispiel #3
0
 // PD_TRACE_DECLARE_FUNCTION ( SDB_CATALOGCB_GETAGROUPRAND, "sdbCatalogueCB::getAGroupRand" )
 INT32 sdbCatalogueCB::getAGroupRand( INT32 &groupID )
 {
    INT32 rc = SDB_CAT_NO_NODEGROUP_INFO ;
    PD_TRACE_ENTRY ( SDB_CATALOGCB_GETAGROUPRAND ) ;
    ossScopedLock _lock( &_GrpIDMutex, EXCLUSIVE ) ;
    UINT32 mapSize = _grpIdMap.size();
    PD_TRACE1 ( SDB_CATALOGCB_GETAGROUPRAND,
                PD_PACK_UINT ( mapSize ) ) ;
    if ( mapSize > 0 )
    {
       UINT32 randNum = ossRand() % mapSize;
       UINT32 i = 0;
       GRP_ID_MAP::iterator iterMap = _grpIdMap.begin();
       for ( ; i < randNum && iterMap!=_grpIdMap.end(); i++ )
       {
          ++iterMap;
       }
       if ( iterMap != _grpIdMap.end() )
       {
          groupID = iterMap->first;
          rc = SDB_OK ;
       }
    }
    PD_TRACE_EXITRC ( SDB_CATALOGCB_GETAGROUPRAND, rc ) ;
    return rc;
 }