int ObClientManager::send_request(const ObServer& server, const int32_t pcode, const int32_t version, 
        const int64_t timeout, ObDataBuffer& in_buffer, ObDataBuffer& out_buffer, int64_t& session_id) const
    {
      int rc = OB_SUCCESS;

      ObPacket* response = NULL;
      rc = do_send_request(server, pcode, version, timeout, in_buffer, response);

      // deserialize response packet to out_buffer
      if (OB_SUCCESS == rc && NULL != response)
      {
        session_id = response->get_session_id() ; // TODO
        // copy response's inner_buffer to out_buffer.
        int64_t data_length = response->get_data_length();
        ObDataBuffer* response_buffer = response->get_buffer();
        if (out_buffer.get_remain() < data_length)
        {
          TBSYS_LOG(ERROR, "insufficient memory in out_buffer, remain:%ld, length=%ld",
              out_buffer.get_remain(), data_length);
          rc = OB_ERROR;
        }
        else
        {
          memcpy(out_buffer.get_data() + out_buffer.get_position(),
              response_buffer->get_data() + response_buffer->get_position(),
              data_length);
          out_buffer.get_position() += data_length;
        }

      }

      return rc;
    }
Exemple #2
0
int ObRootRpcStub::heartbeat_to_cs(const common::ObServer& cs, const int64_t lease_time, const int64_t frozen_mem_version)
{
  int ret = OB_SUCCESS;
  static const int MY_VERSION = 2;
  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(), lease_time)))
  {
    TBSYS_LOG(ERROR, "failed to serialize, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = common::serialization::encode_vi64(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position(), frozen_mem_version)))
  {
    TBSYS_LOG(ERROR, "failed to serialize, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = client_mgr_->post_request(cs, OB_REQUIRE_HEARTBEAT, MY_VERSION, msgbuf)))
  {
    TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
  }
  else
  {
    // success
  }
  return ret;
}
int MockChunkServer::handle_get_table(ObPacket * ob_packet)
{
  int ret = OB_SUCCESS;
  ObDataBuffer* data = ob_packet->get_buffer();
  if (NULL == data)
  {
    ret = OB_ERROR;
  }

  ObGetParam param;
  if (OB_SUCCESS == ret)
  {
    ret = param.deserialize(data->get_data(), data->get_capacity(), data->get_position());
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "%s", "check param failed");
    }
  }

  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;
    ret = result_msg.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());

    // fake data cell
    ObCellInfo cell;
    ObScanner scanner;
    ObRowkey row_key;
    ObString column_name;
    char temp[256] = "";
    cell.table_id_ = 101; 
    for (uint64_t i = 0; i < 10; ++i)
    {
      snprintf(temp, 256, "chunk_%lu_get_row_key:%lu", i, i);
      row_key = make_rowkey(temp, &allocator_);
      cell.row_key_ = row_key;
      cell.column_id_ = i + 1;
      cell.value_.set_int(2234 + i);
      scanner.add_cell(cell);
    }
    scanner.set_is_req_fullfilled(true, 1);
    int32_t channel_id = ob_packet->getChannelId();
    ret = scanner.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());
    //
    ret = send_response(OB_GET_RESPONSE, 1, out_buffer, connection, channel_id);
  }
  TBSYS_LOG(INFO, "handle get table result:ret[%d]", ret);
  return ret;
}
Exemple #4
0
int append_header_delima(ObDataBuffer &buff)
{
  if (buff.get_remain() < 1)
    return OB_ERROR;

  buff.get_data()[buff.get_position()++] = header_delima;
  return OB_SUCCESS;
}
Exemple #5
0
int append_end_rec(ObDataBuffer &buff)
{
  char *data = buff.get_data();
  int64_t pos = buff.get_position();
  int64_t cap = buff.get_remain();

  int len = snprintf(data + pos, cap, "\n");
  if (len >=0 )
    buff.get_position() += len;

  return len;
}
 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;
 }
Exemple #7
0
int MockRootServer::handle_fetch_schema(ObPacket * ob_packet)
{
  int ret = OB_SUCCESS;
  ObDataBuffer* data = ob_packet->get_buffer();
  if (NULL == data)
  {
    ret = OB_ERROR;
  }
  
  if (OB_SUCCESS == ret)
  {
    int64_t timestamp = 0;
    ret = serialization::decode_vi64(data->get_data(), data->get_capacity(), data->get_position(), &timestamp);
    if ((timestamp != 0) && (timestamp != 1024))
    {
      TBSYS_LOG(ERROR, "check timestamp failed:timestamp[%ld]", timestamp);
      ret = OB_ERROR;
    }
  }
  
  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;
    ret = result_msg.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());
    
    // new version
    ObSchemaManagerV2 schema(1025);
    tbsys::CConfig conf;
    if (!schema.parse_from_file("schema.ini", conf))
    {
      TBSYS_LOG(ERROR, "%s", "parse from file failed");
    }
    
    int32_t channel_id = ob_packet->getChannelId();
    ret = schema.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());
    ret = send_response(OB_REPORT_TABLETS_RESPONSE, 1, out_buffer, connection, channel_id);
  }
  return ret;
}
Exemple #8
0
int ObClientServerStub::get_frame_buffer(ObDataBuffer & data_buffer) const
{
  int ret = OB_SUCCESS;
  if (!check_inner_stat())
  {
    TBSYS_LOG(ERROR, "check inner stat failed.");
    ret = OB_ERROR;
  }

  ThreadSpecificBuffer::Buffer* rpc_buffer = frame_buffer_.get_buffer();
  if (OB_SUCCESS == ret)
  {
    if (NULL == rpc_buffer)
    {
      TBSYS_LOG(ERROR, "get thread rpc buff failed:buffer[%p].", rpc_buffer);
      ret = OB_ERROR;
    }
    else
    {
      rpc_buffer->reset();
      data_buffer.set_data(rpc_buffer->current(), rpc_buffer->remain());
    }
  }
  return ret;
}
Exemple #9
0
    int ObServerRpc::get_frame_buffer(ObDataBuffer& data_buffer) const
    {
      int ret = OB_SUCCESS;
      ThreadSpecificBuffer::Buffer* rpc_buffer = NULL;

      if (NULL == rpc_frame_)
      {
        TBSYS_LOG(WARN, "server rpc doesn't init.");
        ret = OB_ERROR;
      }
      
      if (OB_SUCCESS == ret)
      {
        rpc_buffer = frame_buffer_.get_buffer();
        if (NULL == rpc_buffer)
        {
          TBSYS_LOG(WARN, "get thread rpc buff failed,buffer=%p.", rpc_buffer);
          ret = OB_ERROR;
        }
        else
        {
          rpc_buffer->reset();
          data_buffer.set_data(rpc_buffer->current(), rpc_buffer->remain());
        }
      }

      return ret;
    }
Exemple #10
0
    int ObUpsRpcStub :: get_thread_buffer_(ObDataBuffer& data_buff)
    {
      int err = OB_SUCCESS;

      ThreadSpecificBuffer::Buffer* rpc_buffer = NULL;
      // get buffer for rpc send and receive
      ObUpdateServerMain* obj = ObUpdateServerMain::get_instance();
      if (NULL == obj)
      {
        TBSYS_LOG(ERROR, "get ObUpdateServerMain instance failed.");
      }
      else
      {
        const ObUpdateServer& server = obj->get_update_server();
        rpc_buffer = server.get_rpc_buffer();
        if (NULL == rpc_buffer)
        {
          TBSYS_LOG(ERROR, "get thread rpc buff failed:buffer[%p].", rpc_buffer);
          err = OB_ERROR;
        }
        else
        {
          rpc_buffer->reset();
          data_buff.set_data(rpc_buffer->current(), rpc_buffer->remain());
        }
      }

      return err;
    }
Exemple #11
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;
 }
Exemple #12
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;
 }
Exemple #13
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;
    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 migrate tablet, err=%d", result.result_code_);
      ret = result.result_code_;
    }
    else
    {
    }
  }
  return ret;
}
Exemple #14
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;
}
Exemple #15
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;
}
Exemple #16
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;

}
Exemple #17
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;      
    }
Exemple #18
0
    //append ObScanner to output file
    int TaskOutputFile::append(common::ObScanner &scanner)
    {
      int ret = OB_SUCCESS;
      ObDataBuffer buffer;

      TBSYS_LOG(DEBUG, "in task output file append");
      if (file_ == NULL)
      {
        TBSYS_LOG(ERROR, "output file is not opened");
        ret = OB_ERROR;
      }

      if (ret == OB_SUCCESS)
      {
        ret = get_buffer(buffer);
        if (ret != OB_SUCCESS)
        {
          TBSYS_LOG(ERROR, "can't get internal buffer");
        }
      }

      if (ret == OB_SUCCESS)
      {
        ret = convert_result(scanner, buffer);
        if (ret == OB_SUCCESS)
        {
          TBSYS_LOG(DEBUG, "result buffer len = %d", buffer.get_position());
          if (file_->append(buffer) == -1)
          {
            ret = OB_ERROR;
            TBSYS_LOG(ERROR, "can't append buffer to writable file");
          }
        }
        else
        {
          TBSYS_LOG(ERROR, "convert_result failed");
        }
      }

      return ret;
    }
Exemple #19
0
int MockChunkServer::handle_start_merge(ObPacket *ob_packet)
{
  int ret = OB_SUCCESS;
  ObDataBuffer* data = ob_packet->get_buffer();
  int32_t channel_id = ob_packet->getChannelId();
  tbnet::Connection* connection = ob_packet->get_connection();
  int64_t tmp_version = 0;
  if (NULL == data)
  {
    ret = OB_ERROR;
  }
  ThreadSpecificBuffer::Buffer* thread_buffer = response_packet_buffer_.get_buffer();
  if (NULL == thread_buffer)
  {
    ret = OB_ERROR;
  }
  else
  {
    ret = common::serialization::decode_vi64(data->get_data(), data->get_capacity(), data->get_position(), &tmp_version);
    thread_buffer->reset();
    ObDataBuffer out_buffer(thread_buffer->current(), thread_buffer->remain());

    ObResultCode result_msg;
    result_msg.result_code_ = ret;
    ret = result_msg.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());

    if (OB_SUCCESS == ret)
    {
      ret = send_response(OB_HEARTBEAT_RESPONSE, 1, out_buffer, connection, channel_id);
    }
  }
  TBSYS_LOG(INFO, "handle start merge result:ret[%d]", ret);
  if (OB_SUCCESS == ret && tmp_version > version_) 
  {
    version_ = tmp_version;
    split_table();
  }
  return ret;
}
Exemple #20
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;
}
Exemple #21
0
int ObRootRpcStub::set_obi_role(const common::ObServer& ups, const common::ObiRole& role, 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 = role.serialize(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position())))
  {
    TBSYS_LOG(WARN, "failed to serialize role, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = client_mgr_->send_request(ups, OB_SET_OBI_ROLE, DEFAULT_VERSION, timeout_us, msgbuf)))
  {
    TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
  }
  else
  {
    ObResultCode result_code;
    int64_t pos = 0;
    if (OB_SUCCESS != (ret = result_code.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
    {
      TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret);
    }
    else if (OB_SUCCESS != result_code.result_code_)
    {
      TBSYS_LOG(WARN, "failed to set obi role, err=%d", result_code.result_code_);
      ret = result_code.result_code_;
    }
  }
  return ret;
}
Exemple #22
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;
}
Exemple #23
0
int ObRootRpcStub::grant_lease_to_ups(const common::ObServer& ups,
                                      const common::ObServer& master, const int64_t lease,
                                      const ObiRole &obi_role,
                                      const int64_t config_version)
{
  int ret = OB_SUCCESS;
  ObDataBuffer msgbuf;
  ObMsgUpsHeartbeat msg;
  msg.ups_master_ = master;
  msg.self_lease_ = lease;
  msg.obi_role_ = obi_role;
  
  UNUSED(config_version);

  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 msg, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = client_mgr_->post_request(ups, OB_RS_UPS_HEARTBEAT, msg.MY_VERSION, msgbuf)))
  {
    TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
  }
  else
  {
    // success
  }
  return ret;
}
Exemple #24
0
    void ObPacketQueue::push(ObPacket* packet)
    {
      if (packet != NULL)
      {
        ObPacket* ret_ptr = NULL;
        ObDataBuffer* buf = packet->get_packet_buffer();
        int64_t size = sizeof(ObPacket) + buf->get_position();
        void* return_ptr = NULL;
        int err = ring_buffer_.push_task((const void*)packet, size, return_ptr);

        if (err == OB_SUCCESS)
        {
          ret_ptr = (ObPacket*)return_ptr;
          ret_ptr->_next = NULL;
          if (tail_ == NULL)
          {
            head_ = ret_ptr;
          }
          else
          {
            tail_->_next = ret_ptr;
          }
          ret_ptr->set_packet_buffer((char*)ret_ptr + sizeof(ObPacket), buf->get_position());

          tail_ = ret_ptr;
          size_ ++;
        }
        else
        {
          TBSYS_LOG(WARN, "push packet into ring buffer failed, size:%ld, err: %d", size, err);
        }
      }
      else
      {
        TBSYS_LOG(ERROR, "cast packet to ObPacket failed");
      }
    }
Exemple #25
0
    int TaskOutputFile::get_buffer(ObDataBuffer &buffer)
    {
      int ret = OB_SUCCESS;
      ret = buffer_.ensure_space(2 * OB_MAX_PACKET_LENGTH);
      if (ret != OB_SUCCESS) 
      {
        TBSYS_LOG(ERROR, "no enough memory for buffer");
      }
      else
      {
        buffer.set_data(buffer_.get_buffer(), buffer_.get_buffer_size());
      }

      return ret;
    }
Exemple #26
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;
}
Exemple #27
0
int ObRootRpcStub::heartbeat_to_ms(
    const common::ObServer& ms, 
    const int64_t lease_time, 
    const int64_t schema_version, 
    const common::ObiRole &role,
    const int64_t config_version)
{
  int ret = OB_SUCCESS;
  ObDataBuffer msgbuf;
  /*
   * VERSION UPDATE LOG:
   *  - 2012/7/20 xiaochu.yh: add config_version, update MY_VERSION from 3 to 4
   */
  static const int MY_VERSION = 4;

  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(), lease_time)))
  {
    TBSYS_LOG(ERROR, "failed to serialize, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = common::serialization::encode_vi64(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position(), schema_version)))
  {
    TBSYS_LOG(ERROR, "failed to serialize, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = role.serialize(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position())))
  {
    TBSYS_LOG(ERROR, "failed to serialize, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = common::serialization::encode_vi64(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position(), config_version)))
  {
    TBSYS_LOG(ERROR, "failed to serialize, err=%d", ret);
  }
  else if (OB_SUCCESS != (ret = client_mgr_->post_request(ms, OB_REQUIRE_HEARTBEAT, MY_VERSION, msgbuf)))
  {
    TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
  }
  else
  {
    // success
  }
  return ret;
}
Exemple #28
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;
}
 int ObRpcStub::get_rpc_buffer(ObDataBuffer & data_buffer) const
 {
   int ret = OB_SUCCESS;
   common::ThreadSpecificBuffer::Buffer* rpc_buffer = NULL;
   if (!check_inner_stat())
   {
     TBSYS_LOG(WARN, "check inner stat failed");
     ret = OB_INNER_STAT_ERROR;
   }
   else if (NULL == (rpc_buffer = rpc_buffer_->get_buffer()))
   {
     TBSYS_LOG(ERROR, "get thread rpc buff failed:buffer[%p].", rpc_buffer);
     ret = OB_INNER_STAT_ERROR;
   }
   else
   {
     rpc_buffer->reset();
     data_buffer.set_data(rpc_buffer->current(), rpc_buffer->remain());
   }
   return ret;
 }
int ObCommitLogReceiver::start_log(ObDataBuffer& buff)
{
  int ret = OB_SUCCESS;

  ObLogEntry entry;
  ret = entry.deserialize(buff.get_data(), buff.get_limit(), buff.get_position());
  if (OB_SUCCESS != ret)
  {
    TBSYS_LOG(ERROR, "ObLogEntry deserialize error, ret=%d", ret);
  }
  else
  {
    if (OB_LOG_SWITCH_LOG != entry.cmd_)
    {
      TBSYS_LOG(ERROR, "when starting log, the log entry must be SWITCH_LOG");
    }
    else
    {
      uint64_t log_id = 0;
      ret = serialization::decode_i64(buff.get_data(), buff.get_limit(),
                buff.get_position(), (int64_t*)&log_id);
      if (OB_SUCCESS != ret)
      {
        TBSYS_LOG(WARN, "decode_i64 log_id error, ret=%d", ret);
      }
      else
      {
        ret = log_writer_->start_log(log_id, entry.seq_);
        if (OB_SUCCESS != ret)
        {
          TBSYS_LOG(WARN, "start_log error, log_id=%lu ret=%d", log_id, ret);
        }
      }
    }
  }

  return ret;
}