Beispiel #1
0
int ObMergerRpcStub::fetch_update_server(
    const int64_t timeout, const ObServer & root_server,
    ObServer & update_server, bool for_merge) const
{
    int ret = OB_SUCCESS;
    ObDataBuffer data_buff;
    ret = get_rpc_buffer(data_buff);
    // step 1. send get update server info request
    if (OB_SUCCESS == ret)
    {
        ret = rpc_frame_->send_request(root_server,
                                       for_merge ? OB_GET_UPDATE_SERVER_INFO_FOR_MERGE : OB_GET_UPDATE_SERVER_INFO,
                                       DEFAULT_VERSION, timeout, data_buff);
        if (ret != OB_SUCCESS)
        {
            TBSYS_LOG(WARN, "send request to root server for find update server failed:ret[%d]", ret);
        }
    }

    // step 2. deserialize restult 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(WARN, "deserialize result_code failed:pos[%ld], ret[%d]", pos, ret);
        }
        else
        {
            ret = result_code.result_code_;
        }
    }

    // step 3. deserialize update server addr
    if (OB_SUCCESS == ret)
    {
        ret = update_server.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
        if (ret != OB_SUCCESS)
        {
            TBSYS_LOG(WARN, "deserialize server failed:pos[%ld], ret[%d]", pos, ret);
        }
        else
        {
            TBSYS_LOG(DEBUG, "find update server succ:addr[%d], port[%d]", update_server.get_ipv4(),
                      update_server.get_port());
        }
    }
    return ret;
}
Beispiel #2
0
int MockRootServer::handle_register_server(ObPacket * ob_packet)
{
  int ret = OB_SUCCESS;
  ObDataBuffer* data = ob_packet->get_buffer();
  if (NULL == data)
  {
    ret = OB_ERROR;
  }

  if (OB_SUCCESS == ret)
  {
    ObServer server;
    ret = server.deserialize(data->get_data(), data->get_capacity(), data->get_position());
  }

  if (OB_SUCCESS == ret)
  {
    bool is_merger = false;
    ret = serialization::decode_bool(data->get_data(), data->get_capacity(), data->get_position(), &is_merger);
    if ((ret == OB_SUCCESS) && is_merger)
    {
      TBSYS_LOG(INFO, "%s", "merge server registered");
    }
  }
  
  // response
  tbnet::Connection* connection = ob_packet->get_connection();
  ThreadSpecificBuffer::Buffer* thread_buffer = response_packet_buffer_.get_buffer();
  if (NULL == thread_buffer)
  {
    ret = OB_ERROR;
  }
  else
  {
    thread_buffer->reset();
    ObDataBuffer out_buffer(thread_buffer->current(), thread_buffer->remain());
    
    ObResultCode result_msg;
    result_msg.result_code_ = ret;
    result_msg.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());
    
    int32_t channel_id = ob_packet->getChannelId();
    ret = send_response(OB_REPORT_TABLETS_RESPONSE, 1, out_buffer, connection, channel_id);
  }
  TBSYS_LOG(INFO, "handle register server result:ret[%d]", ret);
  return ret;
}
Beispiel #3
0
int ObClientServerStub::get_update_server(ObServer &update_server)
{
  int ret = OB_SUCCESS;
  const int64_t timeout = 1000000;
  ObDataBuffer data_buff;
  ret = get_frame_buffer(data_buff);
  // step 1. send get update server info request
  if (OB_SUCCESS == ret)
  {
    ret = rpc_frame_->send_request(root_server_, OB_GET_UPDATE_SERVER_INFO, DEFAULT_VERSION,
        timeout, data_buff);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "send request to root server for register server failed:ret[%d]", ret);
    }
  }

  // step 2. deserialize restult 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 3. deserialize update server addr
  if (OB_SUCCESS == ret)
  {
    ret = update_server.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "deserialize server failed:pos[%ld], ret[%d]", pos, ret);
    }
  }
  return ret;
}
Beispiel #4
0
    int ObServerRpc::fetch_update_server(const ObServer& root_server,
                                         ObServer& update_server,
                                         const int64_t timeout)
    {
      int ret     = OB_SUCCESS;
      int64_t pos = 0;
      ObResultCode result_code;
      ObDataBuffer data_buff;

      if (root_server.get_ipv4() == 0 || root_server.get_port() == 0
          || timeout <= 0)
      {
        TBSYS_LOG(WARN, "invalid param, ip=%d, port=%d, timeout=%ld",
                  root_server.get_ipv4(), root_server.get_port(),
                  timeout);
        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);
      }

      // step 1. send get update server info request
      if (OB_SUCCESS == ret)
      {
        ret = rpc_frame_->send_request(root_server, 
                                       OB_GET_UPDATE_SERVER_INFO, 
                                       DEFAULT_VERSION,
                                       timeout, data_buff);
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(WARN, "send request to root server for "
                           "get update server failed, ret=%d", ret);
        }
      }
    
      // step 2. deserialize restult 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 root server failed, "
                            "timeout=%ld, ret=%d.", timeout, ret);
          }
        }
      }
    
      // step 3. deserialize update server addr
      if (OB_SUCCESS == ret)
      {
        ret = update_server.deserialize(data_buff.get_data(), 
                                        data_buff.get_position(), pos);
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(ERROR, "deserialize update server failed, pos=%ld, ret=%d", 
                    pos, ret);
        }
      }

      return ret;
    }