Exemplo n.º 1
0
int check_all_block_in_disk(const char* ns_addr, const char* ns_slave_addr, const uint64_t ds_id,
    const VUINT64& blocks, VUINT64& need_sync_block_list, VUINT64& lost_block_list)
{
  int ret = TFS_SUCCESS;
  uint64_t ns_id = Func::get_host_ip(ns_addr);
  uint64_t slave_ns_id = Func::get_host_ip(ns_slave_addr);
  need_sync_block_list.clear();
  lost_block_list.clear();

  // check current cluster's block in blocks array
  ret = get_and_check_all_blocks_copy(ns_id, blocks, need_sync_block_list, ds_id);
  if (TFS_SUCCESS == ret && need_sync_block_list.size() > 0)
  {
    // check slave cluster's block in need_sync_block_list array
    VUINT64 raw_lost_blocks;
    ret = get_and_check_all_blocks_copy(slave_ns_id, need_sync_block_list, raw_lost_blocks);

    // raw_lost_blocks need unique, then remove all blocks which not in need_sync_block_list
    set<uint64_t> need_sync_block_set, lost_block_set;
    need_sync_block_set.insert(need_sync_block_list.begin(), need_sync_block_list.end()); // to sort
    lost_block_set.insert(raw_lost_blocks.begin(), raw_lost_blocks.end()); // to sort & unique

    lost_block_list.resize(raw_lost_blocks.size());
    VUINT64::iterator it = set_intersection(raw_lost_blocks.begin(), raw_lost_blocks.end(),
        need_sync_block_list.begin(), need_sync_block_list.end(), lost_block_list.begin());
    lost_block_list.resize(it - lost_block_list.begin());// set real size
  }
  return ret;
}
Exemplo n.º 2
0
void print_result(const VUINT64& need_sync_block_list, const VUINT64& lost_block_list)
{
  if (lost_block_list.size() > 0)
  {
    fprintf(stdout, "BOTH LOST BLOCK COUNT: %zd\n", lost_block_list.size());
    for (uint32_t i = 0; i < lost_block_list.size(); i++)
    {
      fprintf(stdout, "%" PRI64_PREFIX "u\n", lost_block_list.at(i));
    }
  }

  int32_t real_need_sync_block_size = need_sync_block_list.size() - lost_block_list.size();
  if (real_need_sync_block_size > 0)
  {
    fprintf(stdout, "NEED SYNC BLOCK COUNT: %d\n", real_need_sync_block_size);
    set<uint64_t> lost_block_set;
    lost_block_set.insert(lost_block_list.begin(), lost_block_list.end());
    for (uint32_t i = 0; i < need_sync_block_list.size(); i++)
    {
      uint64_t block_id = need_sync_block_list.at(i);
      if (lost_block_set.find(block_id) == lost_block_set.end())
      {
        fprintf(stdout, "%" PRI64_PREFIX "u\n", block_id);// can sync from slave cluster
      }
    }
  }
}
Exemplo n.º 3
0
   /*
    * get file info from every replica
    * return value don't needed, we just need finfos
    */
   int read_file_info(const VUINT64& replicas,
       const uint64_t block_id, const uint64_t file_id, map<uint64_t, FileInfo>& finfos)
   {
     finfos.clear();
     int ret = TFS_SUCCESS;
     VUINT64::const_iterator iter = replicas.begin();
     for ( ; iter != replicas.end(); iter++)
     {
       int32_t retry = 2;
       while (retry--)
       {
         FileInfo info;
         ret = ToolUtil::read_file_info(*iter, block_id, file_id, FORCE_STAT, info);
         if (TFS_SUCCESS == ret)
         {
           finfos.insert(make_pair(*iter, info));
           break;
         }
         else if (EXIT_META_NOT_FOUND_ERROR == ret) // file not exist, just ignore
         {
           break;
         }
       }
     }

     return (finfos.size() > 0) ? TFS_SUCCESS : TFS_ERROR;
   }
void recover_block_from_slave_cluster(const char* ns_addr, const char* ns_slave_addr,
    const VUINT64& tmp_fail_block_list, VUINT64& success_block_list,
    VUINT64& fail_block_list, multimap<uint64_t, uint64_t>& fail_block_file_list)
{
  int ret = TFS_SUCCESS;
  VUINT64::const_iterator vit = tmp_fail_block_list.begin();
  multimap<uint64_t, uint64_t> tmp_fail_block_file_list;
  vector<FileInfoV2> finfos;
  for (; vit != tmp_fail_block_list.end(); vit++)
  {
    uint64_t block_id = (*vit);
    finfos.clear();
    ret = ToolUtil::read_file_infos_v2(Func::get_host_ip(ns_slave_addr), block_id, finfos);
    if (ret == TFS_SUCCESS)
    {
      bool all_success = true;
      int32_t copy_file_succ_count = 0;
      tmp_fail_block_file_list.clear();
      vector<FileInfoV2>::const_iterator v_file_iter = finfos.begin();
      for (; v_file_iter != finfos.end(); v_file_iter++)
      {
        if ((v_file_iter->status_ & FILE_STATUS_DELETE) != 0)
          continue;

        uint64_t file_id = v_file_iter->id_;
        ret = copy_file_from_slave_cluster(ns_slave_addr, ns_addr, block_id, (*v_file_iter));
        if (TFS_SUCCESS == ret)
        {
          ++copy_file_succ_count;
          TBSYS_LOG(DEBUG, "recover block_id: %" PRI64_PREFIX "u, file_id: %" PRI64_PREFIX "u successful from slave cluster!", block_id, file_id);
        }
        else
        {
          TBSYS_LOG(WARN, "recover block_id: %" PRI64_PREFIX "u, file_id: %" PRI64_PREFIX "u failed from slave cluster, ret: %d", block_id, file_id, ret);
          all_success = false;
          tmp_fail_block_file_list.insert(pair<uint64_t, uint64_t>(block_id, file_id));
        }
      }

      if (all_success)
      {
        success_block_list.push_back(block_id);
      }
      else if (0 == copy_file_succ_count)
      {
        fail_block_list.push_back(block_id);
      }
      else
      {
        fail_block_file_list.insert(tmp_fail_block_file_list.begin(), tmp_fail_block_file_list.end());
      }
    }
    else
    {
      fail_block_list.push_back(block_id);
    }
  }
}