Exemplo n.º 1
0
int rpc_cs_drop(ObClientManager& cp,
                const ObServer& cs,
                int64_t memtable_frozen_version)
{
  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 = encode_i64(ob_inout_buffer.get_data(),
                   ob_inout_buffer.get_capacity(), ob_inout_buffer.get_position(),memtable_frozen_version);
  if (OB_SUCCESS != ret)
  {
    fprintf(stderr,"serialize memtable_frozen_version into buffer failed\n");
    goto exit;
  }

  // send request;
  start = tbsys::CTimeUtil::getTime();
  ret = cp.send_request(cs, OB_DROP_OLD_TABLETS, 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 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());


exit:
  if (param_buffer) delete []param_buffer;
  return ret;
}
int ObMsSqlRpcEvent::deserialize_packet(ObPacket & packet, ObNewScanner & result)
{
  ObDataBuffer * data_buff = NULL;
  int ret = packet.deserialize();
  if (ret != OB_SUCCESS)
  {
    TBSYS_LOG(WARN, "deserialize the packet failed:ret[%d]", ret);
  }
  else
  {
    data_buff = packet.get_buffer();
    if (NULL == data_buff)
    {
      ret = OB_INNER_STAT_ERROR;
      TBSYS_LOG(WARN, "check packet data buff failed:buff[%p]", data_buff);
    }
    if (packet.get_packet_code() == OB_SESSION_END)
    {
      /// when session end, set session id to 0
      set_session_end();
    }
    else
    {
      set_session_id(packet.get_session_id());
    }
  }

  ObResultCode code;
  if (OB_SUCCESS == ret)
  {
    ret = code.deserialize(data_buff->get_data(), data_buff->get_capacity(),
        data_buff->get_position());
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "deserialize result failed:pos[%ld], ret[%d]",
          data_buff->get_position(), ret);
    }
    else
    {
      ObCommonSqlRpcEvent::set_result_code(code.result_code_);
    }
  }
  ///
  result.clear();
  if ((OB_SUCCESS == ret) && (OB_SUCCESS == code.result_code_))
  {
    ret = result.deserialize(data_buff->get_data(), data_buff->get_capacity(),
        data_buff->get_position());
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(WARN, "deserialize scanner failed:pos[%ld], ret[%d]",
          data_buff->get_position(), ret);
    }
  }
  return ret;
}
Exemplo n.º 3
0
 int deserialize_result_0(const ObDataBuffer & data_buffer, int64_t & pos, ObResultCode & rc)
 {
   int ret = OB_SUCCESS;
   if (OB_SUCCESS != (ret = rc.deserialize(data_buffer.get_data(), data_buffer.get_position(), pos)))
   {
     TBSYS_LOG(WARN, "deserialize result code failed. ret:%d, buffer length:%ld, pos:%ld",
         ret, data_buffer.get_position(), pos);
   }
   else
   {
     ret = rc.result_code_;
   }
   return ret;
 }
Exemplo n.º 4
0
int ObRootRpcStub::migrate_tablet(const common::ObServer& src_cs, const common::ObServer& dest_cs, const common::ObRange& range, bool keey_src, const int64_t timeout_us)
{
  int ret = OB_SUCCESS;
  ObDataBuffer msgbuf;

  if (NULL == client_mgr_)
  {
    TBSYS_LOG(ERROR, "client_mgr_=NULL");
    ret = OB_ERROR;
  }
  else if (OB_SUCCESS != (ret = get_thread_buffer_(msgbuf)))
  {
    TBSYS_LOG(ERROR, "failed to get thread buffer, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = range.serialize(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position())))
  {
    TBSYS_LOG(ERROR, "failed to serialize rage, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = dest_cs.serialize(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position())))
  {
    TBSYS_LOG(ERROR, "failed to serialize dest_cs, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = common::serialization::encode_bool(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position(), keey_src)))
  {
    TBSYS_LOG(ERROR, "failed to serialize keey_src, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = client_mgr_->send_request(src_cs, OB_CS_MIGRATE, DEFAULT_VERSION, timeout_us, msgbuf)))
  {
    TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
  }
  else
  {
    ObResultCode result;
    int64_t pos = 0;
    if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
    {
      TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret);
    }
    else if (OB_SUCCESS != result.result_code_)
    {
      TBSYS_LOG(WARN, "failed to migrate tablet, err=%d", result.result_code_);
      ret = result.result_code_;
    }
    else
    {
    }
  }
  return ret;
}
Exemplo n.º 5
0
 int ObRootRpcStub::import_tablets(const common::ObServer& cs, const uint64_t table_id, const int64_t version, const int64_t timeout_us)
 {
   int ret = OB_SUCCESS;
   ObDataBuffer msgbuf;
   
   if (NULL == client_mgr_)
   {
     TBSYS_LOG(ERROR, "client_mgr_=NULL");
     ret = OB_ERROR;
   }
   else if (OB_SUCCESS != (ret = get_thread_buffer_(msgbuf)))
   {
     TBSYS_LOG(ERROR, "failed to get thread buffer, err=%d", ret);
   }
   else if (OB_SUCCESS != (ret = common::serialization::encode_vi64(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position(), table_id)))
   {
     TBSYS_LOG(ERROR, "failed to serialize keey_src, err=%d", ret);
   }
   else if (OB_SUCCESS != (ret = common::serialization::encode_vi64(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position(), version)))
   {
     TBSYS_LOG(ERROR, "failed to serialize keey_src, err=%d", ret);
   }
   else if (OB_SUCCESS != (ret = client_mgr_->send_request(cs, OB_CS_IMPORT_TABLETS, DEFAULT_VERSION, timeout_us, msgbuf)))
   {
     TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
   }
   else
   {
     ObResultCode result;
     int64_t pos = 0;
     if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
     {
       TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret);
     }
     else if (OB_SUCCESS != result.result_code_)
     {
       TBSYS_LOG(WARN, "failed to create tablet, err=%d", result.result_code_);
       ret = result.result_code_;
     }
     else
     {
     }
   }
   return ret;
 }
Exemplo n.º 6
0
 int ObRootRpcStub::revoke_ups_lease(const common::ObServer& ups, const int64_t lease, const common::ObServer& master, const int64_t timeout_us)
 {
   int ret = OB_SUCCESS;
   ObDataBuffer msgbuf;
   ObMsgRevokeLease msg;
   msg.lease_ = lease;
   msg.ups_master_ = master;
   
   if (NULL == client_mgr_)
   {
     TBSYS_LOG(ERROR, "client_mgr_=NULL");
     ret = OB_ERROR;
   }
   else if (OB_SUCCESS != (ret = get_thread_buffer_(msgbuf)))
   {
     TBSYS_LOG(ERROR, "failed to get thread buffer, err=%d", ret);
   }
   else if (OB_SUCCESS != (ret = msg.serialize(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position())))
   {
     TBSYS_LOG(ERROR, "failed to serialize, err=%d", ret);
   }
   else if (OB_SUCCESS != (ret = client_mgr_->send_request(ups, OB_RS_UPS_REVOKE_LEASE, msg.MY_VERSION, timeout_us, msgbuf)))
   {
     TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
   }
   else
   {
     // success
     ObResultCode result;
     int64_t pos = 0;
     if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
     {
       TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret);
     }
     else if (OB_SUCCESS != result.result_code_)
     {
       TBSYS_LOG(WARN, "failed to revoke lease, err=%d", result.result_code_);
       ret = result.result_code_;
     }
     else
     {
     }
   }
   return ret;
 }
Exemplo n.º 7
0
int ObRootRpcStub::get_ups_max_log_seq(const common::ObServer& ups, uint64_t &max_log_seq, const int64_t timeout_us)
{
  int ret = OB_SUCCESS;
  ObDataBuffer msgbuf;      
  if (NULL == client_mgr_)
  {
    TBSYS_LOG(ERROR, "client_mgr_=NULL");
    ret = OB_ERROR;
  }
  else if (OB_SUCCESS != (ret = get_thread_buffer_(msgbuf)))
  {
    TBSYS_LOG(ERROR, "failed to get thread buffer, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = client_mgr_->send_request(ups, OB_RS_GET_MAX_LOG_SEQ, DEFAULT_VERSION, timeout_us, msgbuf)))
  {
    TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
  }
  else
  {
    // success
    ObResultCode result;
    int64_t pos = 0;
    if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
    {
      TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret);
    }
    else if (OB_SUCCESS != result.result_code_)
    {
      TBSYS_LOG(WARN, "failed to revoke lease, err=%d", result.result_code_);
      ret = result.result_code_;
    }
    else if (OB_SUCCESS != (ret = serialization::decode_vi64(msgbuf.get_data(), msgbuf.get_position(), 
                                                             pos, (int64_t*)&max_log_seq)))
    {
      TBSYS_LOG(WARN, "failed to deserialize, err=%d", ret);
    }
    else
    {
      TBSYS_LOG(INFO, "get ups max log seq, ups=%s seq=%lu", ups.to_cstring(), max_log_seq);
    }
  }
  return ret;

}
Exemplo n.º 8
0
int ObRootRpcStub::get_last_frozen_version(const common::ObServer& ups, const int64_t timeout_us, int64_t &frozen_version)
{
  int ret = OB_SUCCESS;
  ObDataBuffer msgbuf;
  frozen_version = -1;

  if (NULL == client_mgr_)
  {
    TBSYS_LOG(ERROR, "client_mgr_=NULL");
    ret = OB_ERROR;
  }
  else if (OB_SUCCESS != (ret = get_thread_buffer_(msgbuf)))
  {
    TBSYS_LOG(ERROR, "failed to get thread buffer, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = client_mgr_->send_request(ups, OB_UPS_GET_LAST_FROZEN_VERSION, DEFAULT_VERSION, timeout_us, msgbuf)))
  {
    TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
  }
  else
  {
    ObResultCode result;
    int64_t pos = 0;
    if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
    {
      TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret);
    }
    else if (OB_SUCCESS != result.result_code_)
    {
      TBSYS_LOG(WARN, "failed to create tablet, err=%d", result.result_code_);
      ret = result.result_code_;
    }
    else if (OB_SUCCESS != (ret = serialization::decode_vi64(msgbuf.get_data(), msgbuf.get_position(), pos, &frozen_version)))
    {
      TBSYS_LOG(WARN, "failed to deserialize frozen version ,err=%d", ret);
      frozen_version = -1;
    }
    else
    {
      TBSYS_LOG(INFO, "last_frozen_version=%ld", frozen_version);
    }
  }
  return ret;
}
Exemplo n.º 9
0
int ObRootRpcStub::create_tablet(const common::ObServer& cs, const common::ObRange& range, const int64_t mem_version, const int64_t timeout_us)
{
  int ret = OB_SUCCESS;
  ObDataBuffer msgbuf;
  static char buff[OB_MAX_PACKET_LENGTH];
  msgbuf.set_data(buff, OB_MAX_PACKET_LENGTH);
  if (NULL == client_mgr_)
  {
    TBSYS_LOG(ERROR, "client_mgr_=NULL");
    ret = OB_ERROR;
  }
  else if (OB_SUCCESS != (ret = range.serialize(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position())))
  {
    TBSYS_LOG(ERROR, "failed to serialize range, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = common::serialization::encode_vi64(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position(), mem_version)))
  {
    TBSYS_LOG(ERROR, "failed to serialize key_src, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = client_mgr_->send_request(cs, OB_CS_CREATE_TABLE, DEFAULT_VERSION, timeout_us, msgbuf)))
  {
    TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
  }
  else
  {
    ObResultCode result;
    int64_t pos = 0;
    static char range_buff[OB_MAX_ROW_KEY_LENGTH * 2];
    if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
    {
      TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret);
    }
    else if (OB_SUCCESS != result.result_code_)
    {
      range.to_string(range_buff, OB_MAX_ROW_KEY_LENGTH * 2);
      TBSYS_LOG(WARN, "failed to create tablet, err=%d, cs=%s, range=%s", result.result_code_, cs.to_cstring(), range_buff);
      ret = result.result_code_;
    }
    else
    {
    }
  }
  return ret;
}
Exemplo n.º 10
0
int ObRootRpcStub::switch_schema(const common::ObServer& ups, const common::ObSchemaManagerV2& schema_manager, const int64_t timeout_us)
{
  int ret = OB_SUCCESS;
  ObDataBuffer msgbuf;

  if (NULL == client_mgr_)
  {
    TBSYS_LOG(ERROR, "client_mgr_=NULL");
    ret = OB_ERROR;
  }
  else if (OB_SUCCESS != (ret = get_thread_buffer_(msgbuf)))
  {
    TBSYS_LOG(ERROR, "failed to get thread buffer, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = schema_manager.serialize(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position())))
  {
    TBSYS_LOG(ERROR, "failed to serialize schema, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = client_mgr_->send_request(ups, OB_SWITCH_SCHEMA, DEFAULT_VERSION, timeout_us, msgbuf)))
  {
    TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
  }
  else
  {
    ObResultCode result;
    int64_t pos = 0;
    if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
    {
      TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret);
    }
    else if (OB_SUCCESS != result.result_code_)
    {
      TBSYS_LOG(WARN, "failed to switch schema, err=%d", result.result_code_);
      ret = result.result_code_;
    }
    else
    {
      char server_buf[OB_IP_STR_BUFF];
      ups.to_string(server_buf, OB_IP_STR_BUFF);
      TBSYS_LOG(INFO, "send up_switch_schema, ups=%s schema_version=%ld", server_buf, schema_manager.get_version());
    }
  }
  return ret;
}
Exemplo n.º 11
0
    int ObRootRpcStub::get_obi_role(const common::ObServer& master, const int64_t timeout_us, common::ObiRole &obi_role)
    {
      int ret = OB_SUCCESS;
      ObDataBuffer msgbuf;

      if (NULL == client_mgr_)
      {
        TBSYS_LOG(ERROR, "client_mgr_=NULL");
        ret = OB_ERROR;
      }
      else if (OB_SUCCESS != (ret = get_thread_buffer_(msgbuf)))
      {
        TBSYS_LOG(ERROR, "failed to get thread buffer, err=%d", ret);
      }
      else if (OB_SUCCESS != (ret = client_mgr_->send_request(master, OB_GET_OBI_ROLE, DEFAULT_VERSION, timeout_us, msgbuf)))
      {
        TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
      }
      else
      {
        ObResultCode result;
        int64_t pos = 0;
        if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
        {
          TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret);
        }
        else if (OB_SUCCESS != result.result_code_)
        {
          TBSYS_LOG(WARN, "failed to get obi_role, err=%d", result.result_code_);
          ret = result.result_code_;
        }
        else if (OB_SUCCESS != (ret = obi_role.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
        {
          TBSYS_LOG(WARN, "failed to deserialize frozen version ,err=%d", ret);
        }
        else
        {
          TBSYS_LOG(INFO, "get obi_role from master, obi_role=%s", obi_role.get_role_str());
        }
      }
      return ret;      
    }
Exemplo n.º 12
0
int ObRootRpcStub::shutdown_cs(const common::ObServer& cs, bool is_restart, const int64_t timeout_us)
{
  int ret = OB_SUCCESS;
  ObDataBuffer msgbuf;      
  if (NULL == client_mgr_)
  {
    TBSYS_LOG(ERROR, "client_mgr_=NULL");
    ret = OB_ERROR;
  }
  else if (OB_SUCCESS != (ret = get_thread_buffer_(msgbuf)))
  {
    TBSYS_LOG(ERROR, "failed to get thread buffer, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = serialization::encode_i32(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position(), is_restart ? 1 : 0)))
  {
    TBSYS_LOG(ERROR, "encode is_restart fail:ret[%d], is_restart[%d]", ret, is_restart ? 1 : 0);
  }
  else if (OB_SUCCESS != (ret = client_mgr_->send_request(cs, OB_STOP_SERVER, DEFAULT_VERSION, timeout_us, msgbuf)))
  {
    TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
  }
  else
  {
    // success
    ObResultCode result;
    int64_t pos = 0;
    if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
    {
      TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret);
    }
    else if (OB_SUCCESS != result.result_code_)
    {
      TBSYS_LOG(WARN, "failed to restart, err=%d server=%s", result.result_code_, cs.to_cstring());
      ret = result.result_code_;
    }
  }
  return ret;
}
Exemplo n.º 13
0
int ObRootRpcStub::delete_tablets(const common::ObServer& cs, const common::ObTabletReportInfoList &tablets, const int64_t timeout_us)
{
  int ret = OB_SUCCESS;
  ObDataBuffer msgbuf;

  if (NULL == client_mgr_)
  {
    TBSYS_LOG(ERROR, "client_mgr_=NULL");
    ret = OB_ERROR;
  }
  else if (OB_SUCCESS != (ret = get_thread_buffer_(msgbuf)))
  {
    TBSYS_LOG(ERROR, "failed to get thread buffer, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = tablets.serialize(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position())))
  {
    TBSYS_LOG(ERROR, "failed to serializ, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = client_mgr_->send_request(cs, OB_CS_DELETE_TABLETS, DEFAULT_VERSION, timeout_us, msgbuf)))
  {
    TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
  }
  else
  {
    ObResultCode result;
    int64_t pos = 0;
    if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
    {
      TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret);
    }
    else if (OB_SUCCESS != result.result_code_)
    {
      TBSYS_LOG(WARN, "failed to delete tablets, err=%d", result.result_code_);
      ret = result.result_code_;
    }
  }
  return ret;
}
Exemplo n.º 14
0
int ObRootRpcStub::table_exist_in_cs(const ObServer &cs, const int64_t timeout_us,
    const uint64_t table_id, bool &is_exist_in_cs)
{
  int ret = OB_SUCCESS;
  ObDataBuffer msgbuf;
  if (NULL == client_mgr_)
  {
    TBSYS_LOG(ERROR, "client_mgr_=NULL");
    ret = OB_ERROR;
  }
  if (OB_SUCCESS == ret)
  {
    if (OB_SUCCESS != (ret = get_thread_buffer_(msgbuf)))
    {
      TBSYS_LOG(ERROR, "failed to get thread buffer, err=%d", ret);
    }
  }
  if (OB_SUCCESS == ret)
  {
    if (OB_SUCCESS != (ret = serialization::encode_vi64(msgbuf.get_data(), msgbuf.get_capacity(),
            msgbuf.get_position(), table_id)))
    {
      TBSYS_LOG(WARN, "fail to encode table_id, table_id=%ld, ret=%d", table_id, ret);
    }
  }
  if (OB_SUCCESS == ret)
  {
    if (OB_SUCCESS != (ret = client_mgr_->send_request(cs, OB_CS_CHECK_TABLET, DEFAULT_VERSION, timeout_us, msgbuf)))
    {
      TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
    }
  }
  ObResultCode result;
  int64_t pos = 0;
  if (OB_SUCCESS == ret)
  {
    if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
    {
      TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret);
    }
  }
  if (OB_SUCCESS == ret)
  {
    if (OB_CS_TABLET_NOT_EXIST == result.result_code_)
    {
      ret = OB_SUCCESS;
      is_exist_in_cs = false;
    }
    else if (OB_SUCCESS == result.result_code_)
    {
      is_exist_in_cs = true;
    }
    else
    {
      ret = result.result_code_;
      TBSYS_LOG(WARN, "fail to check cs tablet. table_id=%lu, cs_addr=%s, err=%d",
          table_id, cs.to_cstring(), ret);
    }
  }
  return ret;
}
Exemplo n.º 15
0
int ObRootRpcStub::get_split_range(const common::ObServer& ups, const int64_t timeout_us,
    const uint64_t table_id, const int64_t forzen_version, ObTabletInfoList &tablets)
{
  int ret = OB_SUCCESS;
  ObDataBuffer msgbuf;
  if (NULL == client_mgr_)
  {
    TBSYS_LOG(ERROR, "client_mgr_=NULL");
    ret = OB_ERROR;
  }
  if (OB_SUCCESS == ret)
  {
    if (OB_SUCCESS != (ret = get_thread_buffer_(msgbuf)))
    {
      TBSYS_LOG(ERROR, "failed to get thread buffer, err=%d", ret);
    }
  }
  if (OB_SUCCESS == ret)
  {
    if (OB_SUCCESS != (ret = serialization::encode_vi64(msgbuf.get_data(), msgbuf.get_capacity(),
            msgbuf.get_position(), forzen_version)))
    {
      TBSYS_LOG(WARN, "fail to encode forzen_version. forzen_version=%ld, ret=%d", forzen_version, ret);
    }
  }
  if (OB_SUCCESS == ret)
  {
    if (OB_SUCCESS != (ret = serialization::encode_vi64(msgbuf.get_data(), msgbuf.get_capacity(),
            msgbuf.get_position(), table_id)))
    {
      TBSYS_LOG(WARN, "fail to encode table_id. table_id=%lu, ret=%d", table_id, ret);
    }
  }
  if (OB_SUCCESS == ret)
  {
    if (OB_SUCCESS != (ret = client_mgr_->send_request(ups, OB_RS_FETCH_SPLIT_RANGE, DEFAULT_VERSION, timeout_us, msgbuf)))
    {
      TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
    }
  }
  ObResultCode result;
  int64_t pos = 0;
  if (OB_SUCCESS == ret)
  {
    if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
    {
      TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret);
    }
    else if (OB_SUCCESS != result.result_code_)
    {
      TBSYS_LOG(WARN, "failed to fetch split range, err=%d", result.result_code_);
      ret = result.result_code_;
    }
  }
  if (OB_SUCCESS == ret)
  {
    if (OB_SUCCESS != (ret = tablets.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
    {
      TBSYS_LOG(WARN, "failed to deserialize tablets, err=%d", ret);
    }
  }
  if (OB_SUCCESS == ret)
  {
    TBSYS_LOG(INFO, "fetch split range from ups succ.");
  }
  else
  {
    TBSYS_LOG(WARN, "fetch split range from ups fail, ups_addr=%s, version=%ld", ups.to_cstring(), forzen_version);
  }
  return ret;
}
Exemplo n.º 16
0
int rpc_cs_migrate(ObClientManager& cp,
                   const ObServer& src,
                   const ObServer& dest,
                   const ObRange& range,
                   bool keep_src)
{
  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 = range.serialize(ob_inout_buffer.get_data(),
                        ob_inout_buffer.get_capacity(), ob_inout_buffer.get_position());
  if (OB_SUCCESS != ret)
  {
    fprintf(stderr,"serialize migrate range into buffer failed\n");
    goto exit;
  }

  ret = dest.serialize(ob_inout_buffer.get_data(),
                       ob_inout_buffer.get_capacity(), ob_inout_buffer.get_position());
  if (OB_SUCCESS != ret)
  {
    fprintf(stderr,"serialize dest_server into buffer failed\n");
    goto exit;
  }
  ret = encode_bool(ob_inout_buffer.get_data(),ob_inout_buffer.get_capacity(),ob_inout_buffer.get_position(),keep_src);
  if (OB_SUCCESS != ret)
  {
    fprintf(stderr,"serialize keep_src  into buffer failed\n");
    goto exit;
  }

  // send request;
  start = tbsys::CTimeUtil::getTime();
  ret = cp.send_request(src, OB_CS_MIGRATE, 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 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());


exit:
  if (param_buffer) delete []param_buffer;
  return ret;
}
Exemplo n.º 17
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;
}
Exemplo n.º 18
0
int ObFileService::receive_file_loop(ObString& file_path, ObString& tmp_file_path,
                                     const int64_t file_size, ObFileAppender& file_appender,
                                     easy_request_t* request, ObDataBuffer& out_buffer,
                                     int32_t& response_cid, const int64_t session_id)
{
    int ret = OB_SUCCESS;
    ObResultCode rc;
    ObPacket *next_request = NULL;

    if (!file_appender.is_opened())
    {
        ret = OB_ERR_UNEXPECTED;
        TBSYS_LOG(WARN, "File appender is not opened yet in receive_file_loop");
    }

    //generate block_buf
    char *block_buf = NULL;
    if (OB_SUCCESS == ret)
    {
        block_buf = reinterpret_cast<char *>(ob_malloc(block_size_, ObModIds::OB_FILE_CLIENT));
        if(NULL == block_buf)
        {
            ret = OB_ALLOCATE_MEMORY_FAILED;
            TBSYS_LOG(WARN, "Allocate memory for block buffer in receive_file_loop"
                      " failed:err[%d]", ret);
        }
    }
    // do receive file loop
    ObDataBuffer *in_buffer = NULL;
    while(OB_SUCCESS == ret)
    {
        ret = queue_thread_->wait_for_next_request(session_id, next_request,
                network_timeout_);
        if (OB_SUCCESS != ret)
        {
            TBSYS_LOG(WARN, "wait for next request fail:ret[%d] "
                      "network_timeout_[%ld]", ret, network_timeout_);
        }

        if (OB_SUCCESS == ret)
        {
            response_cid = next_request->get_channel_id();
            request = next_request->get_request();
            ret = next_request->deserialize();
            if (OB_SUCCESS != ret)
            {
                TBSYS_LOG(WARN, "Deserialize next request failed:ret[%d]", ret);
            }
        }

        if (OB_SUCCESS == ret)
        {
            in_buffer = next_request->get_buffer();
            if (NULL == in_buffer)
            {
                ret = OB_INNER_STAT_ERROR;
                TBSYS_LOG(WARN, "Get buffer for next request failed");
            }
        }

        if (OB_SUCCESS == ret)
        {
            ret = rc.deserialize(in_buffer->get_data(), in_buffer->get_capacity(),
                                 in_buffer->get_position());
            if (OB_SUCCESS != ret)
            {
                TBSYS_LOG(WARN, "Decode result code failed: ret=[%d]", ret);
            }
        }

        if (OB_SUCCESS == ret)
        {
            if (OB_SUCCESS == rc.result_code_) // receive file block
            {
                ret = receive_file_block(file_appender, block_buf, request,
                                         *in_buffer, out_buffer, response_cid, session_id);
                if (OB_SUCCESS != ret)
                {
                    TBSYS_LOG(ERROR, "failed to receive_file_block");
                }
                //FILL_TRACE_LOG("receive_file_block ");
            }
            else if (OB_ITER_END == rc.result_code_) // the whole file is received
            {
                if (file_appender.is_opened())
                {
                    file_appender.close();
                }
                //FILL_TRACE_LOG("receive_file_end");
                ret = receive_file_end(file_path, tmp_file_path, file_size,
                                       request, out_buffer, response_cid, session_id);
                if (OB_SUCCESS != ret)
                {
                    TBSYS_LOG(ERROR, "failed to send receive_file_end");
                }
                break;// end the receive loop
            }
        }
    }
    if (NULL != block_buf)
    {
        ob_free(block_buf);
    }
    if (file_appender.is_opened())
    {
        file_appender.close();
    }
    return ret;
}