Example #1
0
int rpc_cs_get(ObClientManager& cp,
               const ObServer& cs,
               const ObGetParam& get_param,
               ObScanner& scanner)
{
  int ret = OB_SUCCESS;
  int64_t start = 0, end = 0;
  const int32_t BUFFER_SIZE = 2*1024*1024;
  char* param_buffer = new char[BUFFER_SIZE];
  ObDataBuffer ob_inout_buffer;
  ObResultCode rc;
  int64_t return_start_pos = 0;

  if (NULL == param_buffer)
  {
    goto exit;
  }

  ob_inout_buffer.set_data(param_buffer, BUFFER_SIZE);
  ret = get_param.serialize(ob_inout_buffer.get_data(),
                            ob_inout_buffer.get_capacity(), ob_inout_buffer.get_position());
  if (OB_SUCCESS != ret)
  {
    fprintf(stderr,"serialize get_param into buffer failed\n");
    goto exit;
  }

  // send request;
  start = tbsys::CTimeUtil::getTime();
  ret = cp.send_request(cs, OB_GET_REQUEST, 1, 2000*2000, ob_inout_buffer);
  end = tbsys::CTimeUtil::getTime();
  fprintf(stderr,"time consume:%ld\n", end - start);
  if (OB_SUCCESS != ret)
  {
    fprintf(stderr,"rpc failed\n");
    goto exit;
  }

  ret = rc.deserialize(ob_inout_buffer.get_data(),
                       ob_inout_buffer.get_position(), return_start_pos);

  if (OB_SUCCESS != ret)
  {
    fprintf(stderr,"deserialize obscanner failed\n");
    goto exit;
  }

  fprintf(stderr,"return rc code:%d, msg:%s\n", rc.result_code_, rc.message_.ptr());

  if (OB_SUCCESS != rc.result_code_)
  {
    goto exit;
  }

  fprintf(stderr,"return_start_pos:%ld, %ld\n", return_start_pos, ob_inout_buffer.get_position());

  // deserialize output
  ret = scanner.deserialize(ob_inout_buffer.get_data(),
                            ob_inout_buffer.get_position(), return_start_pos);
  if (OB_SUCCESS != ret)
  {
    fprintf(stderr,"deserialize obscanner failed\n");
    goto exit;
  }
  fprintf(stderr,"return_start_pos:%ld, %ld\n", return_start_pos, ob_inout_buffer.get_position());

exit:
  if (param_buffer) delete []param_buffer;
  return ret;
}
Example #2
0
int ObClientServerStub::cs_get(const ObGetParam& get_param, ObScanner& scanner)
{
  int ret = OB_SUCCESS;
  const int64_t timeout = 1000000;  // send_request timeout millionseconds
  ObDataBuffer data_buff;
  ret = get_frame_buffer(data_buff);

  // step 1. serialize timestamp to data_buff
  if (OB_SUCCESS == ret)
  {
    ret = get_param.serialize(data_buff.get_data(), 
        data_buff.get_capacity(), data_buff.get_position());
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "serialize get_param failed:ret[%d].", ret);
    }
  }

  // step 2. send request for fetch new schema
  if (OB_SUCCESS == ret)
  {
    uint32_t pos = random() % merge_server_list_.size();
    ObServer &cur_server = merge_server_list_.at(pos);

    ret = rpc_frame_->send_request(cur_server, 
        OB_GET_REQUEST, DEFAULT_VERSION, timeout, data_buff);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "send request to remote server for get failed"
          " ret[%d].",  ret);
    }
  }


  // step 3. deserialize the response code
  int64_t pos = 0;
  if (OB_SUCCESS == ret)
  {
    ObResultCode result_code;
    ret = result_code.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "deserialize result_code failed:pos[%ld], ret[%d].", pos, ret);
    }
    else
    {
      ret = result_code.result_code_;
    }
  }
  // step 4. deserialize the table schema
  if (OB_SUCCESS == ret)
  {
    ret = scanner.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "deserialize scanner from buff failed"
          "pos[%ld], ret[%d].", pos, ret);
    }
  }

  return ret;
}
Example #3
0
    int ObServerRpc::get(const ObServer& remote_server,
                         const ObGetParam& get_param, 
                         ObScanner& scanner,
                         const int64_t timeout)
    {
      int ret     = OB_SUCCESS;
      int64_t pos = 0;
      ObResultCode result_code;
      ObDataBuffer data_buff;

      if (remote_server.get_ipv4() == 0 || remote_server.get_port() == 0
          || timeout <= 0)
      {
        TBSYS_LOG(WARN, "invalid param, ip=%d, port=%d, timeout=%ld",
                  remote_server.get_ipv4(), remote_server.get_port(),
                  timeout);
        ret = OB_ERROR;
      }
      else if (get_param.get_cell_size() <= 0 || get_param.get_row_size() <= 0)
      {
        TBSYS_LOG(WARN, "invalid param, cell_size=%ld, row_size=%ld", 
                  get_param.get_cell_size(), get_param.get_row_size());
        ret = OB_ERROR;
      }
      else if (NULL == rpc_frame_)
      {
        TBSYS_LOG(WARN, "server rpc doesn't init.");
        ret = OB_ERROR;
      }

      if (OB_SUCCESS == ret)
      {
        ret = get_frame_buffer(data_buff);
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(WARN, "get frame buffer failed, ret=%d.", ret);
        }
      }
      
      // step 1. serialize get param to data_buff
      if (OB_SUCCESS == ret)
      {
        ret = get_param.serialize(data_buff.get_data(), 
                                  data_buff.get_capacity(), 
                                  data_buff.get_position());
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(WARN, "serialize get_param failed, ret=%d.", ret);
        }
      }
    
      // step 2. send request for get
      if (OB_SUCCESS == ret)
      {
        ret = rpc_frame_->send_request(remote_server, 
                                       OB_GET_REQUEST, DEFAULT_VERSION, 
                                       timeout, data_buff);
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(WARN, "send request to remote server for get failed, "
                          "ret=%d.", ret);
        }
      }
    
      // step 3. deserialize the response code
      if (OB_SUCCESS == ret)
      {
        ret = result_code.deserialize(data_buff.get_data(), 
                                      data_buff.get_position(), pos);
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(WARN, "deserialize result_code failed,pos=%ld, ret=%d.", 
                    pos, ret);
        }
        else
        {
          ret = result_code.result_code_;
          if (OB_SUCCESS != ret && OB_DATA_NOT_SERVE != ret)
          {
            TBSYS_LOG(WARN, "get response from remote server failed, "
                            "timeout=%ld, ret=%d.", timeout, ret);
          }
        }
      }

      // step 4. deserialize the scanner
      if (OB_SUCCESS == ret)
      {
        ret = scanner.deserialize(data_buff.get_data(), 
                                  data_buff.get_position(), pos);
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(WARN, "deserialize scanner from buff failed, "
                          "pos=%ld, ret=%d.", pos, ret);
        }
      }
    
      return ret;
    }
Example #4
0
int ObMergerRpcStub::get(
    const int64_t timeout, const ObServer & server,
    const ObGetParam & get_param, ObScanner & scanner) const
{
    int ret = OB_SUCCESS;
    ObDataBuffer data_buff;
    int64_t start_time = tbsys::CTimeUtil::getTime();
    ret = get_rpc_buffer(data_buff);
    // step 1. serialize ObGetParam to the data_buff
    if (OB_SUCCESS == ret)
    {
        ret = get_param.serialize(data_buff.get_data(), data_buff.get_capacity(),
                                  data_buff.get_position());
        if (OB_SUCCESS != ret)
        {
            TBSYS_LOG(WARN, "serialize get_param failed:ret[%d]", ret);
        }
    }
    // step 2. send request for get data
    if (OB_SUCCESS == ret)
    {
        ret = rpc_frame_->send_request(server, OB_GET_REQUEST, DEFAULT_VERSION,
                                       timeout, data_buff);
        if (ret != OB_SUCCESS)
        {
            TBSYS_LOG(WARN, "send get request to server failed:ret[%d], timeout=%ld",
                      ret, timeout);
        }
    }
    // step 3. deserialize the response result
    int64_t pos = 0;
    if (OB_SUCCESS == ret)
    {
        ObResultCode result_code;
        ret = result_code.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
        if (OB_SUCCESS != ret)
        {
            TBSYS_LOG(WARN, "deserialize result failed:pos[%ld], ret[%d]", pos, ret);
        }
        else
        {
            ret = result_code.result_code_;
        }
    }
    // step 4. deserialize the scanner
    if (OB_SUCCESS == ret)
    {
        ret = scanner.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
        if (OB_SUCCESS != ret)
        {
            TBSYS_LOG(WARN, "deserialize scanner from buff failed:pos[%ld], ret[%d]", pos, ret);
        }
    }
    const int32_t MAX_SERVER_ADDR_SIZE = 128;
    char server_addr[MAX_SERVER_ADDR_SIZE];
    bool is_fullfilled = false;
    int64_t fullfilled_item_num = 0;
    scanner.get_is_req_fullfilled(is_fullfilled,fullfilled_item_num);
    server.to_string(server_addr, MAX_SERVER_ADDR_SIZE);
    // write debug log
    if (OB_SUCCESS == ret)
    {
        TBSYS_LOG(DEBUG, "get data succ from server:addr[%s]", server_addr);
    }
    else
    {
        TBSYS_LOG(WARN, "get data failed from server:addr[%s], ret[%d]", server_addr, ret);
    }

    int64_t consume_time = tbsys::CTimeUtil::getTime() - start_time;
    if ((double)consume_time > (double)timeout * 0.8)
    {
        TBSYS_LOG(WARN, "slow ups get, ups_addr=%s, timeout=%ld, consume=%ld",
                  server.to_cstring(), timeout, consume_time);
    }
    return ret;
}