示例#1
0
int BalanceTestRpc::push_migrate_msg(const common::ObServer& src_cs, const common::ObServer& dest_cs, const common::ObRange& range, bool keep_src)
{
  int ret = OB_SUCCESS;
  MigrateMsg* msg = new_migrate_msg(src_cs, dest_cs, range, keep_src);
  assert(msg);
  assert(msg->next_ == NULL);
  char addr_buf1[OB_IP_STR_BUFF];
  char addr_buf2[OB_IP_STR_BUFF];
  static char range_buf[OB_MAX_ROW_KEY_LENGTH * 2];
  src_cs.to_string(addr_buf1, OB_IP_STR_BUFF);
  dest_cs.to_string(addr_buf2, OB_IP_STR_BUFF);

  tbsys::CThreadGuard guard(&migrate_msg_mutex_);
  if (NULL == msg_head_)
  {
    msg_head_ = msg;
  }
  else
  {
    msg->next_ = msg_head_;
    msg_head_ = msg;
  }
  msg_count_++;
  msg->range_.to_string(range_buf, OB_MAX_ROW_KEY_LENGTH*2);
  TBSYS_LOG(DEBUG, "push migrate msg, src=%s dest=%s range=%s",
            addr_buf1, addr_buf2, range_buf);
  return ret;
}
示例#2
0
    int ObUpsRpcStub :: report_freeze(const common::ObServer &root_server,
        const common::ObServer &ups_master, const int64_t frozen_version, const int64_t timeout_us)
    {
      int err = OB_SUCCESS;
      ObDataBuffer data_buff;
      ObServer update_server;

      if (NULL == client_mgr_)
      {
        TBSYS_LOG(WARN, "invalid status, client_mgr_[%p]", client_mgr_);
        err = OB_ERROR;
      }
      else
      {
        err = get_thread_buffer_(data_buff);
      }

      // serialize ups_master
      if (OB_SUCCESS == err)
      {
        err = ups_master.serialize(data_buff.get_data(), data_buff.get_capacity(),
            data_buff.get_position());
      }

      // serialize timestamp
      if (OB_SUCCESS == err)
      {
        err = common::serialization::encode_vi64(data_buff.get_data(), 
            data_buff.get_capacity(), data_buff.get_position(), frozen_version);
      }

      // step 1. send freeze memtable resp
      if (OB_SUCCESS == err)
      {
        err = client_mgr_->send_request(root_server, 
            OB_UPDATE_SERVER_REPORT_FREEZE, DEFAULT_VERSION, timeout_us, data_buff);
        if (err != OB_SUCCESS)
        {
          TBSYS_LOG(ERROR, "send freeze memtable failed, err[%d].", err);
        }
      }

      // step 2. deserialize the response code
      int64_t pos = 0;
      if (OB_SUCCESS == err)
      {
        ObResultCode result_code;
        err = result_code.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
        if (OB_SUCCESS != err)
        {
          TBSYS_LOG(ERROR, "deserialize result_code failed:pos[%ld], err[%d].", pos, err);
        }
        else
        {
          err = result_code.result_code_;
        }
      }

      return err;
    }
示例#3
0
 void ObUpsBlackList::fail(const int32_t server_index, const common::ObServer & server)
 {
   if ((server_index < server_count_) && (fail_counter_[server_index].server_ == server))
   {
     // no need thread safe
     if (0 == fail_counter_[server_index].fail_count_)
     {
       fail_counter_[server_index].fail_timestamp_ = tbsys::CTimeUtil::getTime();
     }
     ++fail_counter_[server_index].fail_count_;
   }
   else
   {
     TBSYS_LOG(WARN, "check param failed:index[%d], count[%d], server[%u], port[%d]",
         server_index, server_count_, server.get_ipv4(), server.get_port());
   }
 }
示例#4
0
int ObUpsLeaseTask::init(common::ObRoleMgr *role_mgr, ObUpsRpcStub * rpc_stub, common::ObServer &root_server, ObUpsLogMgr *log_mgr, const int64_t inner_port, common::ObServer &self_server, const int64_t timeout_us)
{
  int err = OB_SUCCESS;
  self_lease_ = 0;
  if (NULL == role_mgr || NULL == rpc_stub || NULL == log_mgr)
  {
    err = OB_INVALID_ARGUMENT;
    TBSYS_LOG(WARN, "invalid argument. role_mgr=%p", role_mgr);
  }
  else
  {
    role_mgr_ = role_mgr;
    rpc_stub_ = rpc_stub;
    log_mgr_ = log_mgr;
    root_server_.set_ipv4_addr(root_server.get_ipv4(), root_server.get_port());
    inner_port_ = inner_port;
    self_addr_.set_ipv4_addr(self_server.get_ipv4(), self_server.get_port());
    timeout_us_ = timeout_us;
  }
  return err;
}
示例#5
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;
}
示例#6
0
int ObRootServerRpcStub::get_update_server(common::ObServer& update_server,bool for_merge /*=false*/)
{
  int ret = OB_SUCCESS;
  const int64_t timeout = ObChunkServerMain::get_instance()->
    get_chunk_server().get_param().get_network_time_out() ;  // send_request timeout us
  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_, 
                                  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(ERROR, "send request to root server for get update server addr 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;
}
示例#7
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;
}
示例#8
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;

}
示例#9
0
int ObRootTableService::remove_replicas(ObScanHelper &scan_helper, const common::ObServer &cs)
{
    int ret = OB_SUCCESS;
    if (0 == cs.get_port())
    {
        TBSYS_LOG(WARN, "invalid cs port");
        ret = OB_INVALID_ARGUMENT;
    }
    else if (OB_SUCCESS != (ret = check_integrity()))
    {
        TBSYS_LOG(ERROR, "integrity error");
    }
    else
    {
        // @todo for each table
        remove_replicas_in_table(scan_helper, cs, 0);
    }
    return ret;
}
示例#10
0
int ObRootTableService::report_tablets(ObScanHelper &scan_helper, const common::ObServer& cs, const common::ObTabletReportInfoList& rtablets)
{
    int ret = OB_SUCCESS;
    if (OB_SUCCESS != (ret = check_integrity()))
    {
        TBSYS_LOG(ERROR, "integrity error");
    }
    else
    {
        TBSYS_LOG(INFO, "cs report tablets, cs=%s tablets_num=%ld", cs.to_cstring(), rtablets.get_tablet_size());
        const ObTabletReportInfo* tablets = rtablets.get_tablet();
        for (int64_t i = 0; i < rtablets.get_tablet_size(); ++i)
        {
            const ObTabletReportInfo &tablet = tablets[i];
            if (OB_SUCCESS != (ret = report_tablet(scan_helper, tablet)))
            {
                TBSYS_LOG(WARN, "failed to report");
            }
        }
    }
    return ret;
}
示例#11
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;
}
示例#12
0
int ObRootServerRpcStub::register_server(const common::ObServer & server, 
    const bool is_merge_server, int32_t& status)
{
  const int64_t register_timeout = ObChunkServerMain::get_instance()->
    get_chunk_server().get_param().get_network_time_out() ;  // send_request timeout us
  int ret = OB_SUCCESS;
  ObDataBuffer data_buff;
  ret = get_frame_buffer(data_buff);

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

  if (OB_SUCCESS == ret)
  {
    ret = serialization::encode_bool(data_buff.get_data(), data_buff.get_capacity(),
        data_buff.get_position(), is_merge_server);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "serialize is_merge_server failed=[%d]", ret);
    }
  }

  // step 2. send request for fetch new schema
  if (OB_SUCCESS == ret)
  {
    ret = rpc_frame_->send_request(root_server_, 
        OB_SERVER_REGISTER, DEFAULT_VERSION, register_timeout, data_buff);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "send request to root server for register 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 status field
  if (OB_SUCCESS == ret)
  {
    ret = serialization::decode_vi32(data_buff.get_data(), data_buff.get_position(), pos, &status);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "deserialize status from buff failed,"
          "pos[%ld], ret[%d].", pos, ret);
    }
  }

  return ret;
}
示例#13
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;
}
示例#14
0
int ObRootRpcStub::request_report_tablet(const common::ObServer& chunkserver)
{
  int ret = OB_SUCCESS;
  ObDataBuffer msgbuf;
  if (NULL == client_mgr_)
  {
    TBSYS_LOG(ERROR, "client_mgr_=NULL");
    ret = OB_ERROR;
  }
  if (OB_SUCCESS == ret)
  {
    ret = get_thread_buffer_(msgbuf);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(WARN, "fail to get thread buffer. err=%d", ret);
    }
  }
  if (OB_SUCCESS == ret)
  {
    ret = client_mgr_->post_request(chunkserver, OB_RS_REQUEST_REPORT_TABLET, DEFAULT_VERSION, msgbuf);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(WARN, "fail to post request to chunkserver. err=%d, chunkserver_addr=%s", ret, chunkserver.to_cstring());
    }
  }
  return ret;
}
示例#15
0
    int ObRootRpcStub::slave_register(const common::ObServer& master, const common::ObServer& slave_addr, common::ObFetchParam& fetch_param, const int64_t timeout)
    {
      int err = OB_SUCCESS;
      ObDataBuffer data_buff;

      if (NULL == client_mgr_)
      {
        TBSYS_LOG(WARN, "invalid status, client_mgr_[%p]", client_mgr_);
        err = OB_ERROR;
      }
      else
      {
        err = get_thread_buffer_(data_buff);
      }

      // step 1. serialize slave addr
      if (OB_SUCCESS == err)
      {
        err = slave_addr.serialize(data_buff.get_data(), data_buff.get_capacity(),
            data_buff.get_position());
      }

      // step 2. send request to register
      if (OB_SUCCESS == err)
      {
        err = client_mgr_->send_request(master, 
            OB_SLAVE_REG, DEFAULT_VERSION, timeout, data_buff);
        if (err != OB_SUCCESS)
        {
          TBSYS_LOG(ERROR, "send request to register failed"
              "err[%d].", err);
        }
      }

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

      // step 3. deserialize fetch param
      if (OB_SUCCESS == err)
      {
        err = fetch_param.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
        if (OB_SUCCESS != err)
        {
          TBSYS_LOG(WARN, "deserialize fetch param failed, err[%d]", err);
        }
      }

      return err;
    }
示例#16
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;
}
示例#17
0
int ObRootServerRpcStub::migrate_over(
    const common::ObRange &range, 
    const common::ObServer &src_server,
    const common::ObServer &dest_server, 
    const bool keep_src,
    const int64_t tablet_version)
{
  const int64_t timeout = ObChunkServerMain::get_instance()->
    get_chunk_server().get_param().get_network_time_out() ;  // send_request timeout us
  int ret = OB_SUCCESS;
  ObDataBuffer data_buff;
  ret = get_frame_buffer(data_buff);

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

  if (OB_SUCCESS == ret)
  {
    ret = src_server.serialize(data_buff.get_data(), data_buff.get_capacity(),
        data_buff.get_position());
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "serialize src_server failed[%d]", ret);
    }
  }

  if (OB_SUCCESS == ret)
  {
    ret = dest_server.serialize(data_buff.get_data(), data_buff.get_capacity(),
        data_buff.get_position());
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "serialize dest_server failed=[%d]", ret);
    }
  }

  if (OB_SUCCESS == ret)
  {
    ret = serialization::encode_bool(data_buff.get_data(), data_buff.get_capacity(),
        data_buff.get_position(), keep_src);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "serialize keep_src failed=[%d]", ret);
    }
  }

  if (OB_SUCCESS == ret)
  {
    ret = serialization::encode_vi64(data_buff.get_data(), data_buff.get_capacity(),
        data_buff.get_position(), tablet_version);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "serialize tablet_version failed=[%d]", ret);
    }
  }

  // step 2. send request for report tablet migrate over.
  if (OB_SUCCESS == ret)
  {
    ret = rpc_frame_->send_request(root_server_, 
        OB_MIGRATE_OVER, DEFAULT_VERSION, timeout, data_buff);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "send request to root server for register 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_;
    }
  }

  return ret;
}
 int get_rs(common::ObServer &server, const bool change)
 {
   UNUSED(change);
   server.set_ipv4_addr("10.235.152.32", 41814);
   return OB_SUCCESS;
 };
示例#19
0
int ObRootServerRpcStub::report_capacity_info(const common::ObServer &server, 
    const int64_t capacity, const int64_t used)
{
  const int64_t report_timeout = ObChunkServerMain::get_instance()->
    get_chunk_server().get_param().get_network_time_out() ;  // send_request timeout us
  int ret = OB_SUCCESS;
  ObDataBuffer data_buff;
  ret = get_frame_buffer(data_buff);

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

  if (OB_SUCCESS == ret)
  {
    ret = serialization::encode_vi64(data_buff.get_data(), data_buff.get_capacity(),
        data_buff.get_position(), capacity);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "serialize capacity failed=[%d]", ret);
    }
  }

  if (OB_SUCCESS == ret)
  {
    ret = serialization::encode_vi64(data_buff.get_data(), data_buff.get_capacity(),
        data_buff.get_position(), used);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "serialize used failed=[%d]", ret);
    }
  }

  // step 2. send request for fetch new schema
  if (OB_SUCCESS == ret)
  {
    ret = rpc_frame_->send_request(root_server_, 
        OB_REPORT_CAPACITY_INFO, DEFAULT_VERSION, report_timeout, data_buff);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "send request to root server for report capacity 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_;
    }
  }

  return ret;
}
示例#20
0
int ObRootTableService::migrate_replica(ObScanHelper &scan_helper, const ObNewRange &range, const int64_t version,
                                        const common::ObServer &from, const common::ObServer &to, bool keep_src)
{
    int ret = OB_SUCCESS;
    ObRootTable3::ConstIterator *first;
    ObRootTable3 *root_table = NULL;
    const ObRootTable3::Value* crow = NULL;

    if (NULL == range.start_key_.ptr()
            || NULL == range.end_key_.ptr()
            || 0 >= version
            || 0 == from.get_port()
            || 0 == to.get_port())
    {
        TBSYS_LOG(WARN, "invalid tablet");
        ret = OB_INVALID_ARGUMENT;
    }
    else if (OB_SUCCESS != (ret = check_integrity()))
    {
        TBSYS_LOG(ERROR, "integrity error");
    }
    else if (OB_SUCCESS != (ret = aquire_root_table(scan_helper, root_table)))
    {
        TBSYS_LOG(ERROR, "failed to aquire root table, err=%d", ret);
    }
    else if (OB_SUCCESS != (ret = root_table->search(range, first)))
    {
        TBSYS_LOG(WARN, "failed to search tablet, err=%d", ret);
    }
    else if (OB_SUCCESS != (ret = first->next(crow)))
    {
        TBSYS_LOG(WARN, "tablet not exist, err=%d range=%s", ret, to_cstring(range));
        ret = OB_ENTRY_NOT_EXIST;
    }
    else if (!is_same_range(*crow, range))
    {
        ret = OB_ENTRY_NOT_EXIST;
        TBSYS_LOG(WARN, "tablet not exist, range=%s", to_cstring(range));
    }
    else
    {
        for (int32_t i = 0; i < crow->get_max_replica_count(); ++i)
        {
            const ObTabletReplica& replica = crow->get_replica(i);
            if (from == replica.cs_)
            {
                if (replica.version_ != version)
                {
                    TBSYS_LOG(WARN, "migrate tablet with wrong version, old_v=%ld new_v=%ld cs=%s range=%s",
                              replica.version_, version, from.to_cstring(), to_cstring(range));
                    ret = OB_CONFLICT_VALUE;
                }
                else
                {
                    ObTabletMetaTable::Value new_row = *crow; // copy
                    ObTabletReplica replica2(replica);
                    replica2.cs_ = to;
                    if (keep_src)
                    {
                        if (OB_SUCCESS != (ret = new_row.add_replica(replica2)))
                        {
                            TBSYS_LOG(WARN, "failed to add replica, err=%d", ret);
                        }
                    }
                    else
                    {
                        new_row.set_replica(i, replica2);
                    }
                    if (OB_SUCCESS == ret)
                    {
                        if (OB_SUCCESS != (ret = root_table->update(new_row)))
                        {
                            TBSYS_LOG(ERROR, "failed to update root table, err=%d", ret);
                        }
                        else if (OB_SUCCESS != (ret = root_table->commit()))
                        {
                            TBSYS_LOG(ERROR, "failed to commit change, err=%d", ret);
                        }
                    }
                }
                break;
            }
        } // end for
    }
    release_root_table(root_table);
    return ret;
}
示例#21
0
int ObRootTableService::remove_replicas_in_table(ObScanHelper &scan_helper, const common::ObServer &cs, const uint64_t tid)
{
    int ret = OB_SUCCESS;
    ObRootTable3 *root_table = NULL;
    ObNewRange range_min_max;
    range_min_max.table_id_ = tid;
    range_min_max.set_whole_range();
    ObRootTable3::ConstIterator* it = NULL;
    const ObRootTable3::Value* crow = NULL;
    if (OB_SUCCESS != (ret = aquire_root_table(scan_helper, root_table)))
    {
        TBSYS_LOG(ERROR, "failed to aquire root table, err=%d", ret);
    }
    else if (OB_SUCCESS != (ret = root_table->search(range_min_max, it)))
    {
        TBSYS_LOG(WARN, "failed to search tablet, err=%d tid=%lu", ret, tid);
    }
    else
    {
        int32_t deleted_replicas = 0;
        int32_t updated_count = 0;
        const int32_t batch_count = 512;
        while(OB_SUCCESS == ret && OB_SUCCESS == (ret = it->next(crow)))
        {
            for (int32_t i = 0; i < crow->get_max_replica_count(); ++i)
            {
                const ObTabletReplica& replica = crow->get_replica(i);
                if (replica.cs_ == cs)
                {
                    ObTabletReplica replica2; // remove the replica
                    ObRootTable3::Value mrow = *crow;
                    mrow.set_replica(i, replica2);
                    if (OB_SUCCESS != (ret = root_table->update(mrow)))
                    {
                        TBSYS_LOG(ERROR, "failed to update root table, err=%d", ret);
                    }
                    else
                    {
                        updated_count++;
                        if (updated_count % batch_count == 0)
                        {
                            if (OB_SUCCESS != (ret = root_table->commit()))
                            {
                                TBSYS_LOG(ERROR, "failed to commit change, err=%d", ret);
                            }
                            else
                            {
                                deleted_replicas += batch_count;
                            }
                        }
                    }
                    break;
                }
            } // end for
        } // end while

        if (OB_ITER_END != ret)
        {
            TBSYS_LOG(WARN, "failed to remove replicas, err=%d", ret);
        }
        else
        {
            ret = OB_SUCCESS;
        }
        if (updated_count != deleted_replicas)
        {
            if (OB_SUCCESS != (ret = root_table->commit()))
            {
                TBSYS_LOG(ERROR, "failed to commit change, err=%d", ret);
            }
        }
        TBSYS_LOG(INFO, "delete replicas by cs, cs=%s replicas_num=%d",
                  cs.to_cstring(), deleted_replicas);
    }
    release_root_table(root_table);
    return ret;
}