Ejemplo n.º 1
0
Index::Index(std::string Name, std::string tableName, index_t indextype,tindex_t tindextype)
{
this->IndexName=Name;
this->TableName=tableName;
this->IndexType=indextype;
this->tIndexType=tindextype;
this->IndexPrimario="=";
this->typeIndexPrimario=FNULL;
ifstream file(GetFileName(this->IndexName,this->TableName).c_str());
  if (file.is_open())
  {
     file.close();
     LoadIndex();
  }  
  else 
  {
      SaveIndex();
  }
                   
}
Ejemplo n.º 2
0
int HDRecordFileReader::DoReadRecordFile()
{
    unsigned char buf[RECORD_BUF_LEN] = "";
    long filesize = 0;
    /*
    FILE* fp;
    if((fp = ACE_OS::fdopen(_file_handler,"rb")) == NULL)
    {
    	ACE_DEBUG((LM_ERROR,"打开文件流失败!"));
    	return -1;
    }
    */
    //if((filesize = ACE_OS::fseek(fp,0L,SEEK_END)) == -1 )
    if((filesize = ACE_OS::lseek(_file_handler,0L,SEEK_END)) == -1 )
    {
        ACE_DEBUG((LM_ERROR,"取得文件大小失败"));
        return -1;
    }
    // 大小为空的文件,要删除
    if(filesize == 0)
    {
        ACE_DEBUG((LM_DEBUG,"空记录文件,自动删除.."));
        return 0;
    }

    // 文件大小不对
    if(filesize % RECORD_BUF_LEN != 0)
    {
        ACE_DEBUG((LM_ERROR,"流水记录文件大小不正确!"));
        return -2;
    }
    size_t reccnt = filesize / sizeof(buf);
    size_t index = LoadIndex();
    // 认为读取完
    if(index >= reccnt)
        return 0;
#if 1
    if(index > 0)
        ACE_DEBUG((LM_DEBUG,"重新分析记录文件index[%d]",index));
#endif
    //if(ACE_OS::fseek(fp,sizeof(buf)*index,SEEK_SET) == -1)
    if(ACE_OS::lseek(_file_handler,sizeof(buf)*index,SEEK_SET) == -1)
    {
        ACE_DEBUG((LM_ERROR,"定位记录失败!"));
        return -1;
    }
    size_t readbytes = 0;
    size_t bufsize = 0;
    do
    {
        //readbytes = ACE_OS::fread(buf+bufsize,sizeof(buf) - bufsize,1,fp);
        readbytes = ACE_OS::read(_file_handler,buf+bufsize,sizeof(buf) - bufsize);
        if(readbytes == 0)
        {
            if(bufsize == sizeof buf)
            {
                // 一条流水
                ACE_DEBUG((LM_DEBUG,"正在处理最后一条记录[%d]...",index));
                if(SavePosRecord(buf))
                    return -1;
                SaveIndex(++index);
            }
            return 0;
        }
        bufsize += readbytes;
        if(bufsize == sizeof buf)
        {
            // 一条流水
            ACE_DEBUG((LM_DEBUG,"正在处理记录[%d]...",index));
            if(SavePosRecord(buf))
                return -1;
            SaveIndex(++index);
            bufsize = 0;
        }
        //KSGThreadUtil::Sleep(1000);
    } while(1);
    return 0;
}