示例#1
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB__DPSRPCMGR_INIT, "_dpsReplicaLogMgr::init" )
   INT32 _dpsReplicaLogMgr::init ( const CHAR *path, UINT32 pageNum )
   {
      INT32 rc = SDB_OK;
      PD_TRACE_ENTRY ( SDB__DPSRPCMGR_INIT );
      SDB_ASSERT ( path, "path can't be NULL" ) ;

      _transCB = sdbGetTransCB() ;

      _pages = SDB_OSS_NEW _dpsLogPage[pageNum];
      if ( NULL == _pages )
      {
         rc = SDB_OOM;
         PD_LOG (PDERROR, "new _dpsLogPage[pageNum] failed!" );
         goto error;
      }
      for ( UINT32 i = 0; i < pageNum; i++ )
      {
         _pages[i].setNumber( i );
      }
      _totalSize = DPS_DEFAULT_PAGE_SIZE * pageNum;
      _idleSize.init( _totalSize );
      _pageNum = pageNum ;
      if ( ossIsPowerOf2( pageNum ) )
      {
         DPS_SUB_BIT = ~pageNum ;
      }

      rc = _logger.init( path );
      if ( rc )
      {
         PD_LOG ( PDERROR, "Failed to initial log files, rc = %d", rc ) ;
         goto error;
      }

      if ( !_logger.getStartLSN( FALSE ).invalid() )
      {
         rc = _restore () ;
         if ( SDB_OK == rc )
         {
            PD_LOG ( PDEVENT, "Dps restore succeed, file lsn[%lld], buff "
                     "lsn[%lld], current lsn[%lld], expect lsn[%lld]",
                     _logger.getStartLSN().offset, _getStartLsn().offset,
                     _currentLsn.offset, _lsn.offset ) ;
         }
         else
         {
            PD_LOG ( PDERROR, "Dps restore failed[rc:%d]", rc ) ;
            goto error ;
         }
      }
   done:
      PD_TRACE_EXITRC ( SDB__DPSRPCMGR_INIT, rc );
      return rc;
   error:
      goto done;
   }
示例#2
0
/**
 *
 * 恢复到历史 #id,并将恢复后的文件列表存入 file_list
 * 如果恢复发生错误,则返回空字符串,否则返回恢复的目录路径
 *
 */
std::string begin_restore(const std::string &prj, size_t id, std::list<file_info> *file_list)
{
    std::string base = prj + "/tmp";
    size_t count;
    size_t index;
    size_t full_id; //最近一次完整备份的 ID

    file_list->clear();
    rm_recursive(base);
    if(mkdir(base.c_str(), 0775) < 0)
        return std::string();
    count = get_history_qty(prj);
    if(id >= count)
        return std::string();
    if(count > 0 && id == count - 1) //如果是最近一次的历史,则直接返回 current 目录中的文件
    {
        scan(prj.c_str(), file_list);
        return prj + "/current";
    }

    index = 0;
    //寻找最近一次完整备份
    if(find_prev_full_bak(prj, id, &full_id))
    {
        if(id == full_id)
        {
            //要恢复的历史刚好是完整备份,直接返回
            std::string path;

            path = prj + "/history/" + size2string(id) + "/full";
            _scan_dir(path + "/", std::string(), file_list);
            return path;
        }
        else
        {
            //先将完整备份复制到 tmp 目录下
            bool ok;

            ok = link_or_copy_recursive(prj + "/history/" + size2string(full_id) + "/full",
                                        base);
            if(ok)
                index = full_id + 1;
            else
                return std::string();
        }
    }

    for(; index <= id; ++index)
    {
        if(!_restore(prj, base, prj + "/history/" + size2string(index)))
            return std::string();
    }
    _scan_dir(base + "/", std::string(), file_list);
    return base;
}
示例#3
0
 void qt_dbtableview_impl :: _init() {
   _xml = new(std::nothrow) xmldoc(_xmlfile.c_str());
   _model = new(std::nothrow) qt_dbtablemodel(_xml, _xpathprefix.c_str(), _dbconn);
   
   if (!(_model && _parent && _xml)) return;
   
   _model->select();
   _parent->setModel(_model);
   _parent->sortByColumn(0, Qt::AscendingOrder);
   _parent->setSortingEnabled(true);
   //_parent->setSelectionBehavior(QAbstractItemView::SelectRows);
   //_parent->setSelectionMode(QAbstractItemView::NoSelection);
   _restore();
 }
示例#4
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB__DPSRPCMGR_MOVE, "_dpsReplicaLogMgr::move" )
   INT32 _dpsReplicaLogMgr::move( const DPS_LSN_OFFSET &offset,
                                  const DPS_LSN_VER &version )
   {
      INT32 rc = SDB_OK ;
      PD_TRACE_ENTRY ( SDB__DPSRPCMGR_MOVE );
      UINT32 tmpWork = 0 ;
      DPS_LSN_OFFSET tmpLsnOffset = 0 ;
      DPS_LSN_OFFSET tmpBeginOffset = 0 ;
      DPS_LSN tmpCurLsn ;

      ossScopedLock lock( &_mtx ) ;
      if ( DPS_INVALID_LSN_OFFSET == offset )
      {
         rc = SDB_DPS_MOVE_FAILED ;
         PD_LOG( PDERROR, "can not move to a invalid lsn" ) ;
         goto error ;
      }

      while ( !_queSize.compare( 0 ) )
      {
         ossSleep ( 100 ) ;
      }

      tmpWork = _work ;
      tmpCurLsn = _currentLsn ;
      tmpLsnOffset = _lsn.offset ;
      tmpBeginOffset = _getStartLsn().offset ;

      _idleSize.add ( (&_pages[_work])->getLength() ) ;
      (&_pages[_work])->clear() ;

      rc = _movePages ( offset, version ) ;

      if ( SDB_OK != rc )
      {
         goto error ;
      }

      if ( offset >= tmpBeginOffset && offset <= tmpLsnOffset
         && tmpWork == _work && !tmpCurLsn.invalid() )
      {
         goto done ;
      }

      rc = _logger.move( offset, version ) ;

      if ( SDB_OK != rc )
      {
         goto error ;
      }

      if ( !_logger.getStartLSN().invalid() && offset < tmpBeginOffset )
      {
         rc = _restore () ;
      }
      else //reset file idle size
      {
         _dpsLogFile *file = _logger.getWorkLogFile() ;
         UINT32 fileIdleSize = file->getIdleSize() +
                               (&_pages[_work])->getLength() ;
         if ( fileIdleSize % DPS_DEFAULT_PAGE_SIZE != 0 )
         {
            PD_LOG( PDERROR, "File[%s] idle size[%u] is not multi-times of "
                    "page size, cur page info[%u, %s]",
                    file->toString().c_str(), fileIdleSize,
                    _work, (&_pages[_work])->toString().c_str() ) ;
            rc = SDB_SYS ;
            SDB_ASSERT( FALSE, "Idle size error" ) ;
            goto error ;
         }
         file->idleSize ( fileIdleSize ) ;
      }

   done:
      PD_TRACE_EXITRC ( SDB__DPSRPCMGR_MOVE, rc );
      return rc ;
   error:
      goto done ;
   }
示例#5
0
   // initialize a log file, file size max 4GB
   // PD_TRACE_DECLARE_FUNCTION ( SDB__DPSLOGFILE_INIT, "_dpsLogFile::init" )
   INT32 _dpsLogFile::init( const CHAR *path, UINT32 size, UINT32 fileNum )
   {
      INT32 rc = SDB_OK ;
      PD_TRACE_ENTRY ( SDB__DPSLOGFILE_INIT ) ;
      BOOLEAN created = FALSE ;

      SDB_ASSERT ( 0 == ( _fileSize % DPS_DEFAULT_PAGE_SIZE ),
                   "Size must be multiple of DPS_DEFAULT_PAGE_SIZE bytes" ) ;

      _fileSize = size ;
      _fileNum  = fileNum ;
      _idleSize = _fileSize ;

      // allocate OSS_FILE, free in destructor
      _file = SDB_OSS_NEW _OSS_FILE();
      if ( !_file )
      {
         rc = SDB_OOM;
         PD_LOG ( PDERROR, "new _OSS_FILE failed!" );
         goto error;
      }

      // if the file exist, restore
      if ( SDB_OK == ossAccess( path ) )
      {
         rc = ossOpen ( path, OSS_READWRITE|OSS_SHAREWRITE, OSS_RWXU, *_file ) ;
         if ( rc == SDB_OK )
         {
            rc = _restore () ;
            if ( rc == SDB_OK )
            {
               UINT32 startOffset = 0 ;
               if ( DPS_INVALID_LSN_OFFSET != _logHeader._firstLSN.offset )
               {
                  startOffset = (UINT32)( _logHeader._firstLSN.offset %
                                          _fileSize ) ;
               }
               PD_LOG ( PDEVENT, "Restore dps log file[%s] succeed, "
                        "firstLsn[%lld], idle space: %u, start offset: %d",
                        path, getFirstLSN().offset, getIdleSize(),
                        startOffset ) ;
               goto done ;
            }
            else
            {
               close () ;
               PD_LOG ( PDEVENT, "Restore dps log file[%s] failed[rc:%d]",
                        path, rc ) ;
               goto error ;
            }
         }
      }

      if ( SDB_OK == ossAccess( path ) )
      {
         rc = ossDelete ( path );
         if ( SDB_IO == rc )
         {
            PD_LOG ( PDERROR, "Failed to delete file at %s", path ) ;
            goto error;
         }
      }

      // open the file with "create only" and "read write" mode, for rx-r-----
      rc = ossOpen( path, OSS_CREATEONLY |OSS_READWRITE | OSS_SHAREWRITE,
                    OSS_RWXU, *_file );

      if ( rc )
      {
         PD_LOG ( PDERROR, "Failed to open log file %s, rc = %d", path, rc ) ;
         goto error;
      }

      created = TRUE ;

      // increase the file size to the given size plus log file header
      rc = ossExtendFile( _file, (SINT64)_fileSize + DPS_LOG_HEAD_LEN );
      if ( rc )
      {
         close() ;
         PD_LOG ( PDERROR, "Failed to extend log file size to %d, rc = %d",
                 size + DPS_LOG_HEAD_LEN, rc ) ;
         goto error;
      }

      _initHead ( DPS_INVALID_LOG_FILE_ID ) ;
      rc = _flushHeader () ;
      if ( rc )
      {
         close () ;
         PD_LOG ( PDERROR, "Failed to flush header, rc = %d", rc ) ;
         goto error ;
      }
      // Currently let's just skip head
      rc = ossSeek ( _file, DPS_LOG_HEAD_LEN, OSS_SEEK_SET ) ;
      if ( rc )
      {
         close() ;
         PD_LOG ( PDERROR, "Failed to seek to %d offset in log file, rc = %d",
                 DPS_LOG_HEAD_LEN, rc ) ;
         goto error ;
      }

   done:
      PD_TRACE_EXITRC ( SDB__DPSLOGFILE_INIT, rc );
      return rc;
   error:
      if ( NULL != _file )
      {
         SDB_OSS_DEL _file;
         _file = NULL ;
      }
      if ( created )
      {
         INT32 rcTmp = SDB_OK ;
         rcTmp = ossDelete( path ) ;
         if ( SDB_OK != rcTmp )
         {
            PD_LOG( PDERROR, "failed to remove new file[%s], rc:%d",
                    path, rc ) ;
         }
      }
      goto done;
   }
示例#6
0
void HoldemPoker::unmakeAction(int action_id)
{
    _restore();
}