示例#1
0
int MockChunkServer::report_tablets(const ObTabletReportInfoList& tablets, int64_t time_stamp, bool has_more)
{
  int ret = OB_SUCCESS;
  ThreadSpecificBuffer::Buffer* thread_buffer = response_packet_buffer_.get_buffer();
  thread_buffer->reset();
  ObDataBuffer data_buff(thread_buffer->current(),thread_buffer->remain());

  const int64_t report_timeout = 10000000;
  ObServer client_server = self_;

  // serialize ObServer(chunkserver) + ObTabletReportInfoList + int64_t(timestamp)
  // 1. serialize ObServer(client_server)
  if (OB_SUCCESS == ret)
  {
    ret = client_server.serialize(data_buff.get_data(), data_buff.get_capacity(),
        data_buff.get_position());
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "serialize ObServer(chunkserver) failed: ret[%d].", ret);
    }
  }

  // 2. serialize report Tablets
  if (OB_SUCCESS == ret)
  {
    // report tablets information.
    for (int64_t i = 0; i < tablets.get_tablet_size(); ++i)
    {
      const common::ObTabletReportInfo& info = tablets.get_tablet()[i];
      TBSYS_LOG(DEBUG, "report begin dump tablets:i:%ld, row count:%ld", 
          i, info.tablet_info_.row_count_);
      info.tablet_info_.range_.hex_dump();
      TBSYS_LOG(DEBUG, "tablet occupy size:%ld, row count:%ld", 
          info.tablet_info_.occupy_size_, info.tablet_info_.row_count_);
    }

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

  // 3. serialize time_stamp
  if (OB_SUCCESS == ret)
  {
    TBSYS_LOG(DEBUG, "report_tablets, timestamp:%ld count = %ld", time_stamp, tablets.tablet_list_.get_array_index());
    ret = serialization::encode_vi64(data_buff.get_data(), 
        data_buff.get_capacity(), data_buff.get_position(), time_stamp);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "encode_vi64 time_stamp failed: ret[%d].", ret);
    }
  }

  if (OB_SUCCESS == ret)
  {
    ret = client_manager_.send_request(root_server_, OB_REPORT_TABLETS,
        1 , report_timeout, data_buff);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "send_request(ReportTablets) to RootServer failed: ret[%d].", ret);
    }
  }

  int64_t return_start_pos = 0;
  if (OB_SUCCESS == ret)
  {
    ObResultCode report_result;
    ret = report_result.deserialize(data_buff.get_data(), 
        data_buff.get_position(), return_start_pos);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "deserialize ObResultCode(report tablet result) failed: ret[%d].", ret);
    }
    else if (OB_SUCCESS != report_result.result_code_)
    {
      TBSYS_LOG(ERROR, "report Tablet failed, the RootServer returned error: ret[%d].", 
          report_result.result_code_);
      ret = report_result.result_code_;
    }
  }

  if (OB_SUCCESS == ret)
  {
    if (!has_more)  // at the end of report process
    {
      TBSYS_LOG(INFO, "report tablets over, send OB_WAITING_JOB_DONE message.");
      // reset param buffer, for new remote procedure call process(OB_WAITING_JOB_DONE)
      data_buff.get_position() = 0;
      // serialize input param (const ObServer& client, const int64_t time_stamp)
      ret = client_server.serialize(data_buff.get_data(), 
          data_buff.get_capacity(), data_buff.get_position());
      if (OB_SUCCESS != ret)
      {
        TBSYS_LOG(ERROR, "serialize ObServer(chunkserver) failed: ret[%d].", ret);
      }

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

      if (OB_SUCCESS == ret)
      {
        ret = client_manager_.send_request(root_server_, OB_WAITING_JOB_DONE,
            1 , report_timeout, data_buff);
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(ERROR, "ObClientManager::send_request(schema_changed) to "
              "RootServer failed: ret[%d].", ret);
        }
      }

    }
  }

  return ret;

}
示例#2
0
int ObRootServerRpcStub::report_tablets(const ObTabletReportInfoList& tablets, int64_t time_stamp, bool has_more)
{
  int ret = OB_SUCCESS;
  ObDataBuffer data_buff;
  ret = get_frame_buffer(data_buff);

  const int64_t report_timeout = ObChunkServerMain::get_instance()->
    get_chunk_server().get_param().get_network_time_out() ;  // send_request timeout us
  const ObChunkServer& chunk_server = ObChunkServerMain::get_instance()->get_chunk_server();
  ObServer client_server;

  if (OB_SUCCESS == ret)
  {
    client_server = chunk_server.get_self();
  }

  // serialize ObServer(chunkserver) + ObTabletReportInfoList + int64_t(timestamp)
  // 1. serialize ObServer(client_server)
  if (OB_SUCCESS == ret)
  {
    ret = client_server.serialize(data_buff.get_data(), data_buff.get_capacity(),
        data_buff.get_position());
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "serialize ObServer(chunkserver) failed: ret[%d].", ret);
    }
  }

  // 2. serialize report Tablets
  if (OB_SUCCESS == ret)
  {
    char range_buf[OB_RANGE_STR_BUFSIZ];
    // report tablets information.
    for (int64_t i = 0; i < tablets.get_tablet_size(); ++i)
    {
      const common::ObTabletReportInfo& info = tablets.get_tablet()[i];
      info.tablet_info_.range_.to_string(range_buf, OB_RANGE_STR_BUFSIZ);
      TBSYS_LOG(INFO, "report begin dump tablets[%ld]<%s>, "
          "tablet occupy size:%ld, row count:%ld, checksum:%lu, version:%ld", 
          i, range_buf, info.tablet_info_.occupy_size_, 
          info.tablet_info_.row_count_, info.tablet_info_.crc_sum_,
          info.tablet_location_.tablet_version_);
    }

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

  // 3. serialize time_stamp
  if (OB_SUCCESS == ret)
  {
    TBSYS_LOG(DEBUG, "report_tablets, timestamp:%ld", time_stamp);
    ret = serialization::encode_vi64(data_buff.get_data(), 
        data_buff.get_capacity(), data_buff.get_position(), time_stamp);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "encode_vi64 time_stamp failed: ret[%d].", ret);
    }
  }

  if (OB_SUCCESS == ret)
  {
    ret = rpc_frame_->send_request(root_server_, OB_REPORT_TABLETS,
        DEFAULT_VERSION, report_timeout, data_buff);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "send_request(ReportTablets) to RootServer failed: ret[%d].", ret);
    }
  }

  int64_t return_start_pos = 0;
  if (OB_SUCCESS == ret)
  {
    ObResultCode report_result;
    ret = report_result.deserialize(data_buff.get_data(), 
        data_buff.get_position(), return_start_pos);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "deserialize ObResultCode(report tablet result) failed: ret[%d].", ret);
    }
    else if (OB_SUCCESS != report_result.result_code_)
    {
      TBSYS_LOG(ERROR, "report Tablet failed, the RootServer returned error: ret[%d].", 
          report_result.result_code_);
      ret = report_result.result_code_;
    }
  }

  if (OB_SUCCESS == ret)
  {
    if (!has_more)  // at the end of report process
    {
      TBSYS_LOG(INFO, "report tablets over, send OB_WAITING_JOB_DONE message.");
      // reset param buffer, for new remote procedure call process(OB_WAITING_JOB_DONE)
      data_buff.get_position() = 0;
      // serialize input param (const ObServer& client, const int64_t time_stamp)
      ret = client_server.serialize(data_buff.get_data(), 
          data_buff.get_capacity(), data_buff.get_position());
      if (OB_SUCCESS != ret)
      {
        TBSYS_LOG(ERROR, "serialize ObServer(chunkserver) failed: ret[%d].", ret);
      }

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

      if (OB_SUCCESS == ret)
      {
        ret = rpc_frame_->send_request(root_server_, OB_WAITING_JOB_DONE,
            DEFAULT_VERSION, report_timeout, data_buff);
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(ERROR, "ObClientManager::send_request(schema_changed) to "
              "RootServer failed: ret[%d].", ret);
        }
      }

      char addr_buf[BUFSIZ];
      if (!root_server_.to_string(addr_buf, BUFSIZ))
      {
        strcpy(addr_buf, "Get Server IP failed");
      }


      if (OB_SUCCESS == ret) 
      {
        TBSYS_LOG(DEBUG, "schema_changed request is sent: "
            "dst[%s] code[%d] version[%d] data_length[%ld]",
            addr_buf, OB_WAITING_JOB_DONE, DEFAULT_VERSION, data_buff.get_position());

        ObResultCode report_result;
        return_start_pos = 0;
        ret = report_result.deserialize(data_buff.get_data(), 
            data_buff.get_position(), return_start_pos);
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(ERROR, "deserialize ObResultCode(schema changed result)"
              "failed: ret[%d].", ret);
        }
        else if (OB_SUCCESS != report_result.result_code_)
        {
          TBSYS_LOG(ERROR, "report schema changed failed, "
              "the RootServer returned error: ret[%d].", 
              report_result.result_code_);
          ret = report_result.result_code_;
        }
      }
    }
  }

  return ret;
}