示例#1
0
int MockNodeServer::do_request(ObPacket* base_packet)
{
  int err = OB_SUCCESS;
  ObPacket* req = static_cast<ObPacket*>(base_packet);                                                            
  int packet_code = req->get_packet_code();
  err = req->deserialize();
  if(OB_SUCCESS == err)
  {
    switch(packet_code)
    {
      case OB_MMS_HEART_BEAT:
      case OB_MMS_STOP_SLAVE:
      case OB_MMS_SLAVE_DOWN:
      case OB_MMS_TRANSFER_2_MASTER:
        err = node_.handlePacket(req);
        break;
      default:
        err = OB_ERROR;
        TBSYS_LOG(ERROR, "wrong packet code:packet[%d]", packet_code);
        break;
    }
  }
  if(err != OB_SUCCESS)
  {
    TBSYS_LOG(WARN, "check handle failed:ret[%d]", err);
  } 
  return err;
}
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;
}
示例#3
0
int MockMergeServer::do_request(ObPacket * base_packet)
{
  ObPacket * packet = base_packet;
  int32_t packet_code = packet->get_packet_code();
  int ret = OB_SUCCESS;
  ret = packet->deserialize();
  int64_t receive_time = packet->get_receive_ts();
  int32_t version = packet->get_api_version();
  int32_t channelId = packet->getChannelId();
  tbnet::Connection *connection = packet->get_connection();
  ObDataBuffer *in_buff = packet->get_buffer();
  ThreadSpecificBuffer::Buffer *thread_buff = response_packet_buffer_.get_buffer();
  //貌似刨去了网络时间?
  int64_t timeout_us = packet->get_source_timeout() - (tbsys::CTimeUtil::getTime() - packet->get_receive_ts());
  if (NULL != thread_buff)
  {
    thread_buff->reset();
    ObDataBuffer out_buff(thread_buff->current(), thread_buff->remain());
    if (OB_SUCCESS == ret)
    {
      switch(packet_code)
      {
        case OB_SCAN_REQUEST:
          ret = ms_scan(receive_time, version, channelId, connection, *in_buff, out_buff, timeout_us);
          if (ret != OB_SUCCESS)
          {
            TBSYS_LOG(WARN, "ms_scan failed");
          }
          break;
      }
    }

  }
  return ret;
  
}