Example #1
0
int family_process(const uint64_t ns_id, map<uint64_t, int32_t>& family_map)
{
  const int32_t num = 1000;
  ShowServerInformationMessage msg;
  SSMScanParameter& param = msg.get_param();
  param.type_ = SSM_TYPE_FAMILY;

  param.should_actual_count_ = (num << 16);
  param.end_flag_ = SSM_SCAN_CUTOVER_FLAG_YES;
  //其余,如param.start_next_position_ 等都初始化为0

  while (!((param.end_flag_ >> 4) & SSM_SCAN_END_FLAG_YES))
  {
    param.data_.clear();
    tbnet::Packet*ret_msg = NULL;
    NewClient* client = NewClientManager::get_instance().create_client();
    int ret = send_msg_to_server(ns_id, client, &msg, ret_msg, DEFAULT_NETWORK_CALL_TIMEOUT, true);
    if (TFS_SUCCESS != ret || ret_msg == NULL)
    {
      TBSYS_LOG(ERROR, "get block info error, ret: %d", ret);
      NewClientManager::get_instance().destroy_client(client);
      return EXIT_TFS_ERROR;
    }
    if(ret_msg->getPCode() != SHOW_SERVER_INFORMATION_MESSAGE)
    {
      if (ret_msg->getPCode() == STATUS_MESSAGE)
      {
        StatusMessage* msg = dynamic_cast<StatusMessage*>(ret_msg);
        TBSYS_LOG(ERROR, "get invalid message type: error: %s", msg->get_error());
      }
      TBSYS_LOG(ERROR, "get invalid message type, pcode: %d", ret_msg->getPCode());
      NewClientManager::get_instance().destroy_client(client);
      return EXIT_TFS_ERROR;
    }
    ShowServerInformationMessage* message = dynamic_cast<ShowServerInformationMessage*>(ret_msg);
    SSMScanParameter& ret_param = message->get_param();

    int32_t data_len = ret_param.data_.getDataLen();
    int32_t offset = 0;
    while (data_len > offset)
    {
      FamilyShow family;
      if (TFS_SUCCESS == family.deserialize(ret_param.data_, data_len, offset))
      {
        family_map.insert(make_pair(family.family_id_, family.family_aid_info_));
      }
    }
    param.start_next_position_ = (ret_param.start_next_position_ << 16) & 0xffff0000;
    param.end_flag_ = ret_param.end_flag_;
    if (param.end_flag_ & SSM_SCAN_CUTOVER_FLAG_NO)
    {
      param.addition_param1_ = ret_param.addition_param2_;//next start family_id to scan
    }
    NewClientManager::get_instance().destroy_client(client);
  }
  return TFS_SUCCESS;
}
Example #2
0
    int OpManager::update_block_info(const BlockInfoV2& block_info, const common::UpdateBlockInfoType type)
    {
      int ret = TFS_SUCCESS;
      DsRuntimeGlobalInformation& ds_info = DsRuntimeGlobalInformation::instance();
      create_msg_ref(UpdateBlockInfoMessageV2, req_msg);
      req_msg.set_block_info(block_info);
      req_msg.set_type(type);
      req_msg.set_server_id(ds_info.information_.id_);

      NewClient* client = NewClientManager::get_instance().create_client();
      if (NULL == client)
      {
        ret = EXIT_CLIENT_MANAGER_CREATE_CLIENT_ERROR;
      }
      else
      {
        tbnet::Packet* ret_msg = NULL;
        ret = send_msg_to_server(ds_info.ns_vip_port_, client, &req_msg, ret_msg);
        if (TFS_SUCCESS == ret)
        {
          if (STATUS_MESSAGE == ret_msg->getPCode())
          {
            StatusMessage* smsg = dynamic_cast<StatusMessage*>(ret_msg);
            ret = smsg->get_status();
            TBSYS_LOG(DEBUG, "update block info. blockid: %"PRI64_PREFIX"u, status: %d %s",
                block_info.block_id_, smsg->get_status(), smsg->get_error());
          }
          else
          {
            ret = EXIT_COMMIT_BLOCK_UPDATE_ERROR;
          }
        }
        NewClientManager::get_instance().destroy_client(client);
      }

      return ret;
    }
Example #3
0
int get_crc_from_block_list(const string& old_tfs_client, const string& new_tfs_client,
    const string& modify_time, int64_t index, int64_t len)
{
  int ret = TFS_ERROR;
  uint32_t block_id = 0;
  int64_t i = 0;

  for (i = 0; i < len; i++)
  {
    block_id = atol(g_input_lines[index+i].c_str());
    VUINT64 ds_list;
    ToolUtil::get_block_ds_list(Func::get_host_ip(old_tfs_client.c_str()), block_id, ds_list);
    if(ds_list.size() > 0)
    {
      uint64_t ds_id = ds_list[0];

      FILE_INFO_LIST file_list;
      GetServerStatusMessage gss_message;
      gss_message.set_status_type(GSS_BLOCK_FILE_INFO);
      gss_message.set_return_row(block_id);

      NewClient* client = NewClientManager::get_instance().create_client();
      tbnet::Packet* ret_message = NULL;
      if (NULL != client)
      {
        if ((ret = send_msg_to_server(ds_id, client, &gss_message, ret_message)) == TFS_SUCCESS)
        {
          if (ret_message->getPCode() == BLOCK_FILE_INFO_MESSAGE)
          {
            BlockFileInfoMessage *bfi_message = (BlockFileInfoMessage*)ret_message;
            FILE_INFO_LIST* file_info_list = bfi_message->get_fileinfo_list();
            FILE_INFO_LIST::iterator vit = file_info_list->begin();
            for ( ; vit != file_info_list->end(); ++vit)
            {
              file_list.push_back(*vit);
            }
          }
          else if (ret_message->getPCode() == STATUS_MESSAGE)
          {
            StatusMessage* sm = reinterpret_cast<StatusMessage*> (ret_message);
            if (sm->get_error() != NULL)
            {
              TBSYS_LOG(ERROR, "%s", sm->get_error());
              ret = TFS_ERROR;
            }
          }
        }
        else
        {
          TBSYS_LOG(ERROR, "send message to server failed. ds_addr: %s, pcode: %d, ret: %d",
              tbsys::CNetUtil::addrToString(ds_id).c_str(), gss_message.getPCode(), ret);
        }
        NewClientManager::get_instance().destroy_client(client);
      }
      else
      {
        TBSYS_LOG(ERROR,"create client error");
      }

      if (ret == TFS_SUCCESS)
      {
        FILE_INFO_LIST::iterator vit = file_list.begin();
        int i = 0;
        for ( ; vit != file_list.end(); ++vit)
        {
          ++i;
          FSName fsname(block_id, vit->id_, g_tfs_client->get_cluster_id(old_tfs_client.c_str()));
          TBSYS_LOG(DEBUG, "gene file i: %d, blockid: %u, fileid: %"PRI64_PREFIX"u, %s",
              i, block_id, (vit)->id_, fsname.get_name());
          get_crc_from_filename(old_tfs_client, new_tfs_client, fsname.get_name(), modify_time);
        }

        file_list.clear();
      }
    }
    else
    {
      TBSYS_LOG(ERROR,"get block info for blockid: %u failure.",block_id);
    }
 }
 return ret;
}
Example #4
0
    int ShowInfo::show_family(const int8_t type, const int32_t num, const int64_t family_id, int32_t count, const int32_t interval, const string& filename)
    {
      interrupt_ = false;
      is_loop_ = (count == 0);//count表示循环重复拉取的次数,默认是1,0表示一直按照间间隔循环
      FILE* fp = NULL;
      if (TFS_SUCCESS != get_file_handle(filename, &fp))
      {
        return EXIT_TFS_ERROR;
      }

      while ((count > 0 || is_loop_) && !interrupt_)
      {
        ShowServerInformationMessage msg;
        SSMScanParameter& param = msg.get_param();
        param.type_ = SSM_TYPE_FAMILY;

        uint64_t family_count = 0;
        bool once = false;
        if (family_id > 0)
        {
          param.should_actual_count_ = 0x10000;
          param.end_flag_ = SSM_SCAN_CUTOVER_FLAG_NO;
          param.start_next_position_ = ((family_id % nameserver::MAX_FAMILY_CHUNK_NUM) << 16);
          param.addition_param1_ = family_id;
          once = true;
        }
        else if (family_id == 0)
        {
          if (type & BLOCK_TYPE_SERVER_LIST)
          {
            fprintf(fp, "para error, -s must be used with -d\n");
            put_file_handle(fp);
            return EXIT_PARAMETER_ERROR;
          }
          param.should_actual_count_ = (num << 16);
          param.end_flag_ = SSM_SCAN_CUTOVER_FLAG_YES;
          //其余,如param.start_next_position_ 等都初始化为0
        }
        else
        {
          TBSYS_LOG(ERROR, "get invalid family_id: %"PRI64_PREFIX"d < 0", family_id);
          put_file_handle(fp);
          return EXIT_PARAMETER_ERROR;
        }

        while ((!((param.end_flag_ >> 4) & SSM_SCAN_END_FLAG_YES)) && !interrupt_)
        {
          param.data_.clear();
          tbnet::Packet*ret_msg = NULL;
          NewClient* client = NewClientManager::get_instance().create_client();
          int ret = send_msg_to_server(ns_ip_, client, &msg, ret_msg);
          if (TFS_SUCCESS != ret || ret_msg == NULL)
          {
            TBSYS_LOG(ERROR, "get block info error, ret: %d", ret);
            NewClientManager::get_instance().destroy_client(client);
            put_file_handle(fp);
            return EXIT_TFS_ERROR;
          }
          if(ret_msg->getPCode() != SHOW_SERVER_INFORMATION_MESSAGE)
          {
            if (ret_msg->getPCode() == STATUS_MESSAGE)
            {
              StatusMessage* msg = dynamic_cast<StatusMessage*>(ret_msg);
              TBSYS_LOG(ERROR, "get invalid message type: error: %s", msg->get_error());
            }
            TBSYS_LOG(ERROR, "get invalid message type, pcode: %d", ret_msg->getPCode());
            NewClientManager::get_instance().destroy_client(client);
            put_file_handle(fp);
            return EXIT_TFS_ERROR;
          }
          ShowServerInformationMessage* message = dynamic_cast<ShowServerInformationMessage*>(ret_msg);
          SSMScanParameter& ret_param = message->get_param();

          int32_t data_len = ret_param.data_.getDataLen();
          int32_t offset = 0;
          if (data_len > 0)
          {
            print_header(FAMILY_TYPE, type, fp);
          }
          while ((data_len > offset) && !interrupt_)
          {
            FamilyShow family;
            if (TFS_SUCCESS == family.deserialize(ret_param.data_, data_len, offset))
            {
              if (once && (family.family_id_ != family_id))
              {
                //TBSYS_LOG(ERROR, "only get family: %"PRI64_PREFIX"u, but %"PRI64_PREFIX"u not exists", family.family_id_, family_id);
                break;
              }
              if (once && (type & BLOCK_TYPE_SERVER_LIST))
              {
                ret = family.get_members_ds_list(ns_ip_);
                if (TFS_SUCCESS != ret)
                {
                  put_file_handle(fp);
                  return ret;
                }
              }
              family.dump(type, fp);
              ++family_count;
            }
          }
          param.start_next_position_ = (ret_param.start_next_position_ << 16) & 0xffff0000;
          param.end_flag_ = ret_param.end_flag_;
          if (param.end_flag_ & SSM_SCAN_CUTOVER_FLAG_NO)
          {
            param.addition_param1_ = ret_param.addition_param2_;//next start family_id to scan
          }
          NewClientManager::get_instance().destroy_client(client);
          if (once)
          {
            break;
          }
        }
        if (!once)
        {
          fprintf(fp, "Total Count: %"PRI64_PREFIX"u\n", family_count);
        }
        if (--count)
        {
          sleep(interval);
        }
      }
      put_file_handle(fp);
      return TFS_SUCCESS;
    }
Example #5
0
    int ShowInfo::show_block_common(const int32_t num, const uint64_t block_id, int32_t count,
        const int32_t interval, const string& filename, BaseBlockWorker* worker)
    {
      FILE* fp = NULL;
      if (TFS_SUCCESS != get_file_handle(filename, &fp))
      {
        return EXIT_TFS_ERROR;
      }
      interrupt_ = false;
      is_loop_ = (count == 0);

      while ((count > 0 || is_loop_) && !interrupt_)
      {
        if(TFS_SUCCESS != worker->begin())
        {
          put_file_handle(fp);
          return EXIT_TFS_ERROR;
        }
        ShowServerInformationMessage msg;
        SSMScanParameter& param = msg.get_param();
        param.type_ = SSM_TYPE_BLOCK;//遍历ns上的block数据的类型
        param.child_type_ = SSM_CHILD_BLOCK_TYPE_INFO | SSM_CHILD_BLOCK_TYPE_SERVER;//TYPE_INFO只为取block_id, TYPE_SERVER为ds_list

        bool once = false;
        if (block_id > 0)
        {
          param.should_actual_count_ = 0x10000;
          param.end_flag_ = SSM_SCAN_CUTOVER_FLAG_NO;
          param.start_next_position_ = ((block_id % nameserver::MAX_BLOCK_CHUNK_NUMS) << 16);//start是本次在ns上开始扫描blocks的桶的位置
          param.addition_param1_ = block_id;
          once = true;
        }
        else
        {
          param.should_actual_count_ = (num << 16);
          param.end_flag_ = SSM_SCAN_CUTOVER_FLAG_YES;
        }

        print_header(worker->block_type_, worker->sub_type_, fp);
        while ((!((param.end_flag_ >> 4) & SSM_SCAN_END_FLAG_YES)) && !interrupt_)
        {
          param.data_.clear();
          tbnet::Packet*ret_msg = NULL;
          NewClient* client = NewClientManager::get_instance().create_client();
          int ret = send_msg_to_server(ns_ip_, client, &msg, ret_msg);
          if (TFS_SUCCESS != ret || ret_msg == NULL)
          {
            TBSYS_LOG(ERROR, "get block info error, ret: %d", ret);
            NewClientManager::get_instance().destroy_client(client);
            put_file_handle(fp);
            return EXIT_TFS_ERROR;
          }
          if(ret_msg->getPCode() != SHOW_SERVER_INFORMATION_MESSAGE)
          {
            if (ret_msg->getPCode() == STATUS_MESSAGE)
            {
              StatusMessage* msg = dynamic_cast<StatusMessage*>(ret_msg);
              TBSYS_LOG(ERROR, "get invalid message type: error: %s", msg->get_error());
            }
            TBSYS_LOG(ERROR, "get invalid message type, pcode: %d", ret_msg->getPCode());
            NewClientManager::get_instance().destroy_client(client);
            put_file_handle(fp);
            return EXIT_TFS_ERROR;
          }
          ShowServerInformationMessage* message = dynamic_cast<ShowServerInformationMessage*>(ret_msg);
          SSMScanParameter& ret_param = message->get_param();

          int32_t data_len = ret_param.data_.getDataLen();
          int32_t offset = 0;
          //如果指定的blockid不存在,且block表中[start_next_position_, +00)这些桶内没有block,则拉取block个数为0
          while ((data_len > offset) && !interrupt_)
          {
            BlockBase* base_block = worker->create_block();
            ret = base_block->deserialize(ret_param.data_, data_len, offset, param.child_type_);
            if (TFS_SUCCESS == ret)
            {
              base_block->BlockBase::dump();// log info of each block info
              if (once && (base_block->info_.block_id_ != block_id))
              {
                //TBSYS_LOG(ERROR, "block: %"PRI64_PREFIX"u,%"PRI64_PREFIX"u not exists", base_block->info_.block_id_, block_id);
                break;
              }
              worker->process(base_block, fp);// not sort by block
            }
            else
            {
              TBSYS_LOG(ERROR, "Block deserialize error, ret: %d", ret);
              NewClientManager::get_instance().destroy_client(client);
              put_file_handle(fp);
              return ret;
            }
            tbsys::gDelete(base_block);
          }
          param.start_next_position_ = (ret_param.start_next_position_ << 16) & 0xffff0000;
          param.end_flag_ = ret_param.end_flag_;
          if (param.end_flag_ & SSM_SCAN_CUTOVER_FLAG_NO)
          {
            param.addition_param1_ = ret_param.addition_param2_;
          }
          NewClientManager::get_instance().destroy_client(client);
          if (once)
          {
            break;
          }
        }
        if (!once)
        {
          worker->end(fp);
        }
        if (--count)
        {
          sleep(interval);
        }
      }
      put_file_handle(fp);
      return TFS_SUCCESS;
    }
Example #6
0
File: show.cpp Project: 0huah0/tfs
    int ShowInfo::show_block(const int8_t type, const int32_t num, const uint32_t block_id, const int32_t block_chunk_num, int32_t count, const int32_t interval, const string& filename)
    {
      interrupt_ = false;
      is_loop_ = (count == 0);
      FILE* fp = NULL;
      if (TFS_ERROR == get_file_handle(filename, &fp))
      {
        return TFS_ERROR;
      }

      while ((count > 0 || is_loop_) && !interrupt_)
      {
        StatStruct stat;

        ShowServerInformationMessage msg;
        SSMScanParameter& param = msg.get_param();
        param.type_ = SSM_TYPE_BLOCK;
        param.child_type_ = SSM_CHILD_BLOCK_TYPE_INFO | SSM_CHILD_BLOCK_TYPE_SERVER;

        bool once = false;
        if (block_id > 0)
        {
          param.should_actual_count_ = 0x10000;
          param.end_flag_ = SSM_SCAN_CUTOVER_FLAG_NO;
          param.should_actual_count_ = 0x10000;
          param.start_next_position_ = ((block_id % block_chunk_num) << 16);
          param.addition_param1_ = block_id;
          once = true;
        }
        else
        {
          param.should_actual_count_ = (num << 16);
          param.end_flag_ = SSM_SCAN_CUTOVER_FLAG_YES;
        }

        while ((!((param.end_flag_ >> 4) & SSM_SCAN_END_FLAG_YES)) && !interrupt_)
        {
          param.data_.clear();
          block_set_.clear();
          tbnet::Packet*ret_msg = NULL;
          NewClient* client = NewClientManager::get_instance().create_client();
          int ret = send_msg_to_server(ns_ip_, client, &msg, ret_msg);
          if (TFS_SUCCESS != ret || ret_msg == NULL)
          {
            TBSYS_LOG(ERROR, "get block info error, ret: %d", ret);
            NewClientManager::get_instance().destroy_client(client);
            return TFS_ERROR;
          }
          //TBSYS_LOG(DEBUG, "pCode: %d", ret_msg->get_message_type());
          if(ret_msg->getPCode() != SHOW_SERVER_INFORMATION_MESSAGE)
          {
            if (ret_msg->getPCode() == STATUS_MESSAGE)
            {
              StatusMessage* msg = dynamic_cast<StatusMessage*>(ret_msg);
              TBSYS_LOG(ERROR, "get invalid message type: error: %s", msg->get_error());
            }
            TBSYS_LOG(ERROR, "get invalid message type, pcode: %d", ret_msg->getPCode());
            NewClientManager::get_instance().destroy_client(client);
            return TFS_ERROR;
          }
          ShowServerInformationMessage* message = dynamic_cast<ShowServerInformationMessage*>(ret_msg);
          SSMScanParameter& ret_param = message->get_param();

          int32_t data_len = ret_param.data_.getDataLen();
          int32_t offset = 0;
          if (data_len > 0)
          {
            print_header(BLOCK_TYPE, type, fp);
          }
          while ((data_len > offset) && !interrupt_)
          {
            BlockShow block;
            if (TFS_SUCCESS == block.deserialize(ret_param.data_, data_len, offset, param.child_type_))
            {
              //block.BlockBase::dump();
              if (once && (block.info_.block_id_ != block_id))
              {
                TBSYS_LOG(ERROR, "block(%u)(%u) not exists", block.info_.block_id_, block_id);
                break;
              }
              stat.add(block);
              block_set_.insert(block);
            }
          }
          std::set<BlockShow>::iterator iter = block_set_.begin();
          for (; iter != block_set_.end(); iter++)
          {
             (*iter).dump(type, fp);
          }
          param.start_next_position_ = (ret_param.start_next_position_ << 16) & 0xffff0000;
          param.end_flag_ = ret_param.end_flag_;
          if (param.end_flag_ & SSM_SCAN_CUTOVER_FLAG_NO)
          {
            param.addition_param1_ = ret_param.addition_param2_;
          }
          NewClientManager::get_instance().destroy_client(client);
          if (once)
          {
            break;
          }
        }
        if (!once)
        {
          stat.dump(BLOCK_TYPE, type, fp);
        }
        if (--count)
        {
          sleep(interval);
        }
      }
      if (fp != stdout) fclose(fp);
      return TFS_SUCCESS;
    }
Example #7
0
int block_process(const uint64_t ns_id, const map<uint64_t, int32_t>& family_map, StatInfo& file_stat_info,
    V_BLOCK_SIZE_RANGE& v_block_size_range, V_DEL_BLOCK_RANGE& v_del_block_range, BLOCK_SIZE_SET& s_big_block, const int32_t top_num, BLOCK_SIZE_SET& s_topn_block)
{
  const int32_t num = 1000;
  int32_t ret  = TFS_ERROR;
  file_stat_info.set_family_count(family_map.size());

  ShowServerInformationMessage msg;
  SSMScanParameter& param = msg.get_param();
  param.type_ = SSM_TYPE_BLOCK;
  param.child_type_ = SSM_CHILD_BLOCK_TYPE_INFO | SSM_CHILD_BLOCK_TYPE_SERVER;
  param.should_actual_count_ = (num << 16);
  param.end_flag_ = SSM_SCAN_CUTOVER_FLAG_YES;

  while (!((param.end_flag_ >> 4) & SSM_SCAN_END_FLAG_YES))
  {
    param.data_.clear();
    tbnet::Packet*ret_msg = NULL;
    NewClient* client = NewClientManager::get_instance().create_client();
    ret = send_msg_to_server(ns_id, client, &msg, ret_msg, DEFAULT_NETWORK_CALL_TIMEOUT, true);
    if (TFS_SUCCESS != ret || ret_msg == NULL)
    {
      TBSYS_LOG(ERROR, "get block info error, ret: %d", ret);
      NewClientManager::get_instance().destroy_client(client);
      return TFS_ERROR;
    }
    //TBSYS_LOG(DEBUG, "pCode: %d", ret_msg->get_message_type());
    if(ret_msg->getPCode() != SHOW_SERVER_INFORMATION_MESSAGE)
    {
      if (ret_msg->getPCode() == STATUS_MESSAGE)
      {
        StatusMessage* msg = dynamic_cast<StatusMessage*>(ret_msg);
        TBSYS_LOG(ERROR, "get invalid message type: error: %s", msg->get_error());
      }
      TBSYS_LOG(ERROR, "get invalid message type, pcode: %d", ret_msg->getPCode());
      NewClientManager::get_instance().destroy_client(client);
      return TFS_ERROR;
    }
    ShowServerInformationMessage* message = dynamic_cast<ShowServerInformationMessage*>(ret_msg);
    SSMScanParameter& ret_param = message->get_param();

    int32_t data_len = ret_param.data_.getDataLen();
    int32_t offset = 0;
    while (data_len > offset)
    {
      BlockBase block;
      if (TFS_SUCCESS == block.deserialize(ret_param.data_, data_len, offset, param.child_type_))
      {
        //block.dump();
        // add to file stat
        float ratio = static_cast<float>(block.server_list_.size());
        map<uint64_t, int32_t>::const_iterator iter;
        if (INVALID_FAMILY_ID != block.info_.family_id_ &&
            (iter = family_map.find(block.info_.family_id_)) != family_map.end())
        {
          int data_member_num = GET_DATA_MEMBER_NUM(iter->second);
          int check_member_num = GET_CHECK_MEMBER_NUM(iter->second);
          ratio = StatInfo::div((data_member_num + check_member_num), data_member_num);
        }
        file_stat_info.add(block, ratio);
        // check block size is invalid
        if (IS_VERFIFY_BLOCK(block.info_.block_id_))
          continue;

        // do range stat
        ret = do_stat(block.info_.size_ / M_UNITS, v_block_size_range);
        if (ret != TFS_SUCCESS)
        {
          TBSYS_LOG(ERROR, "some error occurs, blockid: %"PRI64_PREFIX"u, size: %d", block.info_.block_id_, block.info_.size_);
        }

        // get big block info
        if (top_num > 0 && block.info_.size_ >= THRESHOLD)
        {
          s_big_block.insert(BlockSize(block.info_.block_id_, block.info_.size_));
        }

        // count del block range
        if (block.info_.del_size_ < 0)
        {
          TBSYS_LOG(ERROR, "some error occurs, blockid: %"PRI64_PREFIX"u, del size: %d, size: %d", block.info_.block_id_, block.info_.del_size_, block.info_.size_);
        }
        else
        {
          int32_t percent = block.info_.size_ > 0 ? static_cast<int32_t>(static_cast<int64_t>(block.info_.del_size_) * 100 / block.info_.size_) : 0;
          ret = do_stat(percent, v_del_block_range);
          if (ret != TFS_SUCCESS)
          {
            TBSYS_LOG(ERROR, "some error occurs, blockid: %"PRI64_PREFIX"u, del size: %d, size: %d", block.info_.block_id_, block.info_.del_size_, block.info_.size_);
          }
        }

        if (top_num > 0 && static_cast<int32_t>(s_topn_block.size()) >= top_num)
        {
          if (block.info_.size_ > s_topn_block.begin()->file_size_)
          {
            s_topn_block.erase(s_topn_block.begin());
            s_topn_block.insert(BlockSize(block.info_.block_id_, block.info_.size_));
          }
        }
        else
        {
          s_topn_block.insert(BlockSize(block.info_.block_id_, block.info_.size_));
        }
      }
    }
    param.start_next_position_ = (ret_param.start_next_position_ << 16) & 0xffff0000;
    param.end_flag_ = ret_param.end_flag_;
    if (param.end_flag_ & SSM_SCAN_CUTOVER_FLAG_NO)
    {
      param.addition_param1_ = ret_param.addition_param2_;
    }
    NewClientManager::get_instance().destroy_client(client);
  }
  return TFS_SUCCESS;
}
Example #8
0
File: show.cpp Project: keoyeop/tfs
    int ShowInfo::show_rack_block(const int8_t type, string& rack_ip_mask, string& rack_ip_group, const int32_t num, int32_t count, const int32_t interval, const string& filename)
    {
      interrupt_ = false;
      is_loop_ = (count == 0);
      FILE* fp = NULL;
      if (TFS_ERROR == get_file_handle(filename, &fp))
      {
        return TFS_ERROR;
      }

      while ((count > 0 || is_loop_) && !interrupt_)
      {
        RackBlockShow rack_block;
        ShowServerInformationMessage msg;
        SSMScanParameter& param = msg.get_param();//参数初始化为0
        param.type_ = SSM_TYPE_BLOCK;
        param.child_type_ = SSM_CHILD_BLOCK_TYPE_INFO | SSM_CHILD_BLOCK_TYPE_SERVER;//可以去掉INFO

        param.should_actual_count_ = (num << 16);//每发一次消息读取的block数取最大值
        param.end_flag_ = SSM_SCAN_CUTOVER_FLAG_YES;

        print_header(RACK_BLOCK_TYPE, type, fp);
        while ((!((param.end_flag_ >> 4) & SSM_SCAN_END_FLAG_YES)) && !interrupt_)
        {
          param.data_.clear();
          tbnet::Packet*ret_msg = NULL;
          NewClient* client = NewClientManager::get_instance().create_client();
          int ret = send_msg_to_server(ns_ip_, client, &msg, ret_msg);
          if (TFS_SUCCESS != ret || ret_msg == NULL)
          {
            TBSYS_LOG(ERROR, "get block info error, ret: %d", ret);
            NewClientManager::get_instance().destroy_client(client);
            return TFS_ERROR;
          }

          if(ret_msg->getPCode() != SHOW_SERVER_INFORMATION_MESSAGE)
          {
            if (ret_msg->getPCode() == STATUS_MESSAGE)
            {
              StatusMessage* msg = dynamic_cast<StatusMessage*>(ret_msg);
              TBSYS_LOG(ERROR, "get invalid message type: error: %s", msg->get_error());
            }
            TBSYS_LOG(ERROR, "get invalid message type, pcode: %d", ret_msg->getPCode());
            NewClientManager::get_instance().destroy_client(client);
            return TFS_ERROR;
          }
          ShowServerInformationMessage* message = dynamic_cast<ShowServerInformationMessage*>(ret_msg);
          SSMScanParameter& ret_param = message->get_param();

          int32_t data_len = ret_param.data_.getDataLen();
          int32_t offset = 0;
          if (data_len > 0)
          {
          //  print_header(RACK_BLOCK_TYPE, type, fp);
          }
          while ((data_len > offset) && !interrupt_)
          {
            BlockShow block;
            if (TFS_SUCCESS == block.deserialize(ret_param.data_, data_len, offset, param.child_type_))
            {
              rack_block.add(block, rack_ip_mask);
            }
          }
          param.start_next_position_ = (ret_param.start_next_position_ << 16) & 0xffff0000;
          param.end_flag_ = ret_param.end_flag_;
          if (param.end_flag_ & SSM_SCAN_CUTOVER_FLAG_NO)
          {
            param.addition_param1_ = ret_param.addition_param2_;
          }
          NewClientManager::get_instance().destroy_client(client);
        }
        //把所有的block都拉取下来才输出
        rack_block.dump(type, rack_ip_group, fp);

        if (--count)
        {
          sleep(interval);
        }
      }
      if (fp != stdout) fclose(fp);
      return TFS_SUCCESS;
    }
Example #9
0
File: show.cpp Project: keoyeop/tfs
    int ShowInfo::show_block_distribution(const int8_t type,  string& rack_ip_mask, const int32_t num, const uint64_t block_id, int32_t count, const int32_t interval, const string& filename)
    {
      const int32_t block_chunk_num = nameserver::MAX_BLOCK_CHUNK_NUMS;
      interrupt_ = false;
      is_loop_ = (count == 0);
      FILE* fp = NULL;
      if (TFS_ERROR == get_file_handle(filename, &fp))
      {
        return TFS_ERROR;
      }

      while ((count > 0 || is_loop_) && !interrupt_)
      {
        BlockDistributionStruct stat;

        ShowServerInformationMessage msg;
        SSMScanParameter& param = msg.get_param();
        param.type_ = SSM_TYPE_BLOCK;//遍历ns上的block,这里设置的才是找ns取数据的类型
        param.child_type_ = SSM_CHILD_BLOCK_TYPE_SERVER | SSM_CHILD_BLOCK_TYPE_INFO;//TODO:其实只取每个block的server list,但是BlockBase 反序列化接口不一致

        bool once = false;
        if (block_id > 0)
        {
          param.should_actual_count_ = 0x10000;
          param.end_flag_ = SSM_SCAN_CUTOVER_FLAG_NO;
          param.start_next_position_ = ((block_id % block_chunk_num) << 16);
          param.addition_param1_ = block_id;
          once = true;
        }
        else
        {
          param.should_actual_count_ = (num << 16);//每次should从ns读取的最大block数
          param.end_flag_ = SSM_SCAN_CUTOVER_FLAG_YES;
        }

        print_header(BLOCK_DISTRIBUTION_TYPE, type, fp);
        while ((!((param.end_flag_ >> 4) & SSM_SCAN_END_FLAG_YES)) && !interrupt_)//一直把ns上的所有block读取完成(除非终端中断)
        {
          param.data_.clear();
          tbnet::Packet*ret_msg = NULL;
          NewClient* client = NewClientManager::get_instance().create_client();
          int ret = send_msg_to_server(ns_ip_, client, &msg, ret_msg);
          if (TFS_SUCCESS != ret || ret_msg == NULL)
          {
            TBSYS_LOG(ERROR, "get block info error, ret: %d", ret);
            NewClientManager::get_instance().destroy_client(client);
            return TFS_ERROR;
          }

          if(ret_msg->getPCode() != SHOW_SERVER_INFORMATION_MESSAGE)
          {
            if (ret_msg->getPCode() == STATUS_MESSAGE)
            {
              StatusMessage* msg = dynamic_cast<StatusMessage*>(ret_msg);
              TBSYS_LOG(ERROR, "get invalid message type: error: %s", msg->get_error());
            }
            TBSYS_LOG(ERROR, "get invalid message type, pcode: %d", ret_msg->getPCode());
            NewClientManager::get_instance().destroy_client(client);
            return TFS_ERROR;
          }
          ShowServerInformationMessage* message = dynamic_cast<ShowServerInformationMessage*>(ret_msg);
          SSMScanParameter& ret_param = message->get_param();

          int32_t data_len = ret_param.data_.getDataLen();
          int32_t offset = 0;
         // if (data_len > 0)
         // {
         //   print_header(BLOCK_DISTRIBUTION_TYPE, type, fp);
         // }
        //如果指定的blockid都不存在,且block表中>=start_next_position_桶后没有blockid,则拉取block个数为0
          if(type & BLOCK_IP_DISTRIBUTION_TYPE)
          {
            while ((data_len > offset) && !interrupt_)
            {
              BlockDistributionShow block;
              if (TFS_SUCCESS == block.deserialize(ret_param.data_, data_len, offset, param.child_type_))
              {
                if (once && (block.info_.block_id_ != block_id))
                {
                  TBSYS_LOG(ERROR, "block: %"PRI64_PREFIX"u,%"PRI64_PREFIX"u not exists", block.info_.block_id_, block_id);
                  break;
                }
                if(block.check_block_ip_distribution())
                {
                  block.dump_ip(fp);
                  stat.add(block);
                }
              }
            }
          }
          else
          {
            assert( (type & BLOCK_RACK_DISTRIBUTION_TYPE) );
            while ((data_len > offset) && !interrupt_)
            {
              BlockDistributionShow block;
              if (TFS_SUCCESS == block.deserialize(ret_param.data_, data_len, offset, param.child_type_))
              {
                if (once && (block.info_.block_id_ != block_id))
                {
                  TBSYS_LOG(ERROR, "block: %"PRI64_PREFIX"u,%"PRI64_PREFIX"u not exists", block.info_.block_id_, block_id);
                  break;
                }
                if(block.check_block_rack_distribution(rack_ip_mask))
                {
                  block.dump_rack(fp);
                  stat.add(block);
                }
              }
            }
          }

          param.start_next_position_ = (ret_param.start_next_position_ << 16) & 0xffff0000;
          param.end_flag_ = ret_param.end_flag_;
          if (param.end_flag_ & SSM_SCAN_CUTOVER_FLAG_NO)
          {
            param.addition_param1_ = ret_param.addition_param2_;
          }
          NewClientManager::get_instance().destroy_client(client);
          if (once)
          {
            break;
          }
        }
        if (!once)
        {
          stat.dump(type, fp);
        }
        if (--count)
        {
          sleep(interval);
        }
      }
      if (fp != stdout) fclose(fp);
      return TFS_SUCCESS;
    }
Example #10
0
    int Requester::req_update_block_info(const uint32_t block_id, const UpdateBlockType repair)
    {
      UpdateBlockType tmp_repair = repair; 
      BlockInfo* blk = NULL;
      if (UPDATE_BLOCK_MISSING != tmp_repair)
      {
        int32_t visit_count = 0;
        int ret = data_management_->get_block_info(block_id, blk, visit_count);
        if (EXIT_NO_LOGICBLOCK_ERROR == ret)
        {
          tmp_repair = UPDATE_BLOCK_MISSING;
        }
        else
        {
          if (NULL == blk)
          {
            TBSYS_LOG(ERROR, "blockid: %u can not find block info.", block_id);
            tmp_repair = UPDATE_BLOCK_REPAIR;
          }
          else
          {
            TBSYS_LOG(
                INFO,
                "req update block info, blockid: %u, version: %d, file count: %d, size: %d, delfile count: %d, del_size: %d, seqno: %d\n",
                blk->block_id_, blk->version_, blk->file_count_, blk->size_, blk->del_file_count_, blk->del_size_, blk->seq_no_);
          }
        }
      }

      int ret = TFS_ERROR;
      UpdateBlockInfoMessage ub_msg;
      ub_msg.set_block_id(block_id);
      ub_msg.set_block(blk);
      ub_msg.set_server_id(dataserver_id_);
      ub_msg.set_repair(tmp_repair);
      NewClient* client = NewClientManager::get_instance().create_client();
      tbnet::Packet* return_msg = NULL;
      ret = send_msg_to_server(ns_ip_port_, client, &ub_msg, return_msg);
      if (TFS_SUCCESS != ret)
      {
        NewClientManager::get_instance().destroy_client(client);
        return ret;
      }
      int need_expire = 0;
      if (STATUS_MESSAGE == return_msg->getPCode())
      {
        StatusMessage* sm = dynamic_cast<StatusMessage*>(return_msg);
        if (STATUS_MESSAGE_OK == sm->get_status())
        {
          ret = TFS_SUCCESS;
        }
        else if (STATUS_MESSAGE_REMOVE == sm->get_status())
        {
          need_expire = 1;
          ret = TFS_SUCCESS;
        }
        else
        {
          TBSYS_LOG(ERROR, "req update block info: %s, id: %u, tmp_repair: %d\n", sm->get_error(), block_id, tmp_repair);
        }
      }
      else
      {
        TBSYS_LOG(ERROR,"unknow packet pcode: %d", return_msg->getPCode());
      }
      NewClientManager::get_instance().destroy_client(client);

      if (need_expire)
      {
        data_management_->del_single_block(block_id);
      }

      return ret;
    }
Example #11
0
    int Requester::req_block_write_complete(const uint32_t block_id,
        const int32_t lease_id, const int32_t success, const UnlinkFlag unlink_flag)
    {
      TBSYS_LOG(DEBUG, "req block write complete begin id: %u, lease_id: %u\n", block_id, lease_id);

      BlockInfo* blk = NULL;
      int visit_count = 0;
      int ret = data_management_->get_block_info(block_id, blk, visit_count);
      if (TFS_SUCCESS != ret)
      {
        TBSYS_LOG(ERROR, "req block write complete: can not find block, id: %u, ret: %d\n", block_id, ret);
        return TFS_ERROR;
      }

      BlockInfo tmpblk;
      memcpy(&tmpblk, blk, sizeof(BlockInfo));
      ret = data_management_->get_block_curr_size(block_id, tmpblk.size_);
      if (TFS_SUCCESS != ret)
      {
        TBSYS_LOG(ERROR, "req block write complete: can not find block, id: %u, ret: %d\n", block_id, ret);
        return TFS_ERROR;
      }

      BlockWriteCompleteMessage bwc_msg;
      bwc_msg.set_block(&tmpblk);
      bwc_msg.set_server_id(dataserver_id_);
      bwc_msg.set_lease_id(lease_id);
      WriteCompleteStatus wc_status = WRITE_COMPLETE_STATUS_YES;
      if (TFS_SUCCESS != success)
      {
        wc_status = WRITE_COMPLETE_STATUS_NO;
      }
      bwc_msg.set_success(wc_status);
      bwc_msg.set_unlink_flag(unlink_flag);

      NewClient* client = NewClientManager::get_instance().create_client();
      tbnet::Packet* return_msg = NULL;
      ret = send_msg_to_server(ns_ip_port_, client, &bwc_msg, return_msg);


      if (TFS_SUCCESS != ret)
      {
        NewClientManager::get_instance().destroy_client(client);
        return ret;
      }

      if (STATUS_MESSAGE == return_msg->getPCode())
      {
        StatusMessage* sm = dynamic_cast<StatusMessage*>(return_msg);
        if (STATUS_MESSAGE_OK == sm->get_status())
        {
          ret = TFS_SUCCESS;
        }
        else
        {
          ret = TFS_ERROR;
          TBSYS_LOG(ERROR, "rep block write complete, nsip: %s, error desc: %s, id: %u\n",
              tbsys::CNetUtil::addrToString(ns_ip_port_).c_str(), sm->get_error(), block_id);
        }
      }
      else
      {
        TBSYS_LOG(ERROR, "rep block write complete, blockid: %u, msg type: %d error.\n", block_id,
            return_msg->getPCode());
        ret = TFS_ERROR;
      }
      NewClientManager::get_instance().destroy_client(client);
      return ret;
    }
Example #12
0
int do_monitor(const VSTRING& param, int32_t type)
{
  int ret = TFS_SUCCESS;
  string server = param[0];

  uint64_t ip_port = 0;
  {
    char ip[MAX_CMD_SIZE+1];     // to support mutiple port in the same server, must copy
    ip[MAX_CMD_SIZE] = '\0';
    int32_t port = get_port(strncpy(ip, server.c_str(), MAX_CMD_SIZE));
    ip_port = Func::str_to_addr(ip, port);
  }

  AdminCmdMessage* admin_msg = new AdminCmdMessage(type);
  for (size_t i = 1; i < param.size(); i++)
  {
    admin_msg->set_index(param[i]);
  }

  NewClient* client = NewClientManager::get_instance().create_client();
  if (NULL != client)
  {
    tbnet::Packet* message = NULL;
    if (TFS_SUCCESS == (ret = send_msg_to_server(ip_port, client, admin_msg, message)))
    {
      if (STATUS_MESSAGE == message->getPCode())
      {
        StatusMessage* msg = dynamic_cast<StatusMessage*>(message);
        ret = msg->get_status();
        fprintf(stderr, "%s %s \033[0m\n", ret != TFS_SUCCESS ? FAIL_COLOR : SUC_COLOR, msg->get_error());
      }
      else if (ADMIN_CMD_MESSAGE == message->getPCode() &&
          ADMIN_CMD_RESP == dynamic_cast<AdminCmdMessage*>(message)->get_cmd_type())
      {
        vector<MonitorStatus>* m_status =  dynamic_cast<AdminCmdMessage*>(message)->get_status();
        int32_t size = m_status->size();
        fprintf(stderr, "\033[36m       ================== %s count: %d ===================\033[0m\n",
            server.c_str(), size);

        // update server ==> index
        VSTRING& index = g_server_map[server];
        index.clear();

        for (int32_t i = 0; i < size; i++)
        {
          (*m_status)[i].dump();
          index.push_back((*m_status)[i].index_);
        }
        fprintf(stderr, "\033[36m-----------------------------------------------------------------------------------\033[0m\n\n");
      }
      else
      {
        fprintf(stderr, "%s unknown message recieved, op cmd fail\n \033[0m", FAIL_COLOR);
      }
    }
    else
    {
      fprintf(stderr, "send message error");
    }
    NewClientManager::get_instance().destroy_client(client);

  }
  else
  {
    fprintf(stderr, "create client error");
    ret = TFS_ERROR;
  }

  return ret;
}