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; }
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; }
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; }
int ObClientManager::get_next(const ObServer& server, const int64_t session_id, const int64_t timeout, ObDataBuffer& in_buffer, ObDataBuffer& out_buffer) const { int rc = OB_SUCCESS; ObPacket* response = NULL; //rc = send_request(server, pcode, version, timeout, in_buffer, response); ObPacket* packet = new (std::nothrow) ObPacket(); if (NULL == packet) { rc = OB_ALLOCATE_MEMORY_FAILED; } else { packet->set_packet_code(OB_SESSION_NEXT_REQUEST); packet->setChannelId(0); packet->set_api_version(0); packet->set_data(in_buffer); packet->set_source_timeout(timeout); packet->set_session_id(session_id); //TODO } if (OB_SUCCESS == rc) { rc = packet->serialize(); if (OB_SUCCESS != rc) TBSYS_LOG(WARN, "packet serialize error, code=%d", packet->get_packet_code()); } // serialize failed if (OB_SUCCESS != rc && NULL != packet) { packet->free(); } if (OB_SUCCESS == rc) { rc = do_send_packet(server, packet, timeout, response); } // deserialize response packet to out_buffer if (OB_SUCCESS == rc && NULL != response) { // 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; }