예제 #1
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;
}
예제 #2
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;
}
예제 #3
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;

  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 = common::serialization::encode_vi64(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position(), mem_version)))
  {
    TBSYS_LOG(ERROR, "failed to serialize keey_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;
    msgbuf.get_position() = 0;
    if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position())))
    {
      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;
}
예제 #4
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;
}
예제 #5
0
int ObRootServerRpcStub::dest_load_tablet(
    const common::ObServer &dest_server, 
    const common::ObRange &range,
    const int32_t dest_disk_no,
    const int64_t tablet_version,
    const uint64_t crc_sum,
    const int64_t size,
    const char (*path)[common::OB_MAX_FILE_NAME_LENGTH])
{
  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 range 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);
    }
  }

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

  // tablet_version
  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);
    }
  }

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

  // number of sstable files 
  if(OB_SUCCESS == ret)
  {
    ret = serialization::encode_vi64(data_buff.get_data(), data_buff.get_capacity(),
                                     data_buff.get_position(), size);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "serialize file num failed=[%d]", ret);
    }
  }

  // path
  if (OB_SUCCESS == ret)
  {
    for ( int64_t idx =0 ; idx < size; idx++)
    {
      ret = serialization::encode_vstr(data_buff.get_data(), data_buff.get_capacity(),
          data_buff.get_position(), path[idx]);
      if (OB_SUCCESS != ret)
      {
        TBSYS_LOG(ERROR, "serialize file path failed=[%d]", ret);
        break;
      }
    }
  } 

  if (OB_SUCCESS == ret)
  {
    ret = rpc_frame_->send_request(dest_server, 
        OB_MIGRATE_OVER, DEFAULT_VERSION, timeout, data_buff);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "send request to chunkserver for dest load tablet"
          ",ret=[%d].", ret);
    }
    else
    {
      TBSYS_LOG(INFO,"send request to destination server success"); 
    }
  }


  // 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;
}