Exemplo n.º 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;
}
Exemplo n.º 2
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;
    }