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; }
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; }
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; }
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; }
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; 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 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; }
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; 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 if (OB_SUCCESS != (ret = serialization::decode_vi64(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position(), &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; }
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; 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 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_capacity(), msgbuf.get_position()))) { 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; }
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; msgbuf.get_position() = 0; if (OB_SUCCESS != (ret = result_code.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_code.result_code_) { TBSYS_LOG(WARN, "failed to set obi role, err=%d", result_code.result_code_); ret = result_code.result_code_; } } return ret; }
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; }
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(), ×tamp); 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; }
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; }
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 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; }
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; }
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; }
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; }
int ObRootRpcStub::heartbeat_to_cs( const common::ObServer& cs, const int64_t lease_time, const int64_t frozen_mem_version, const int64_t schema_version, const int64_t config_version) { int ret = OB_SUCCESS; static const int MY_VERSION = 3; ObDataBuffer msgbuf; 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 = 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 = 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 = 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 ObFileService::receive_file_end(ObString& file_path, ObString& tmp_file_path, const int64_t file_size, easy_request_t* request, ObDataBuffer& out_buffer, int32_t& response_cid, const int64_t session_id) { int ret = OB_SUCCESS; struct stat file_stat; char tmp_path_buf[OB_MAX_FILE_NAME_LENGTH]; char path_buf[OB_MAX_FILE_NAME_LENGTH]; int n = snprintf(tmp_path_buf, OB_MAX_FILE_NAME_LENGTH, "%.*s", tmp_file_path.length(), tmp_file_path.ptr()); if (n<0 || n>=OB_MAX_FILE_NAME_LENGTH) { TBSYS_LOG(ERROR, "failed to get tmp_file_path length[%d] [%.*s]", n, tmp_file_path.length(), tmp_file_path.ptr()); ret = OB_SIZE_OVERFLOW; } else if (stat(tmp_path_buf, &file_stat) != 0) { TBSYS_LOG(ERROR, "stat tmp_file_path[%s] failed: %s", tmp_path_buf, strerror(errno)); ret = OB_IO_ERROR; } n = snprintf(path_buf, OB_MAX_FILE_NAME_LENGTH, "%.*s", file_path.length(), file_path.ptr()); if (OB_SUCCESS == ret && (n<0 || n>=OB_MAX_FILE_NAME_LENGTH)) { TBSYS_LOG(ERROR, "failed to get path_buf length[%d] [%.*s]", n, file_path.length(), file_path.ptr()); ret = OB_SIZE_OVERFLOW; } if (OB_SUCCESS == ret && file_stat.st_size != file_size) { TBSYS_LOG(ERROR, "The size of received tmp file size[%ld], " "remote file size[%ld]", file_stat.st_size, file_size); ret = OB_INVALID_DATA; } if (OB_SUCCESS == ret && 0 != rename(tmp_path_buf, path_buf)) { TBSYS_LOG(ERROR, "Rename [%s] to path[%s] failed: errno[%d] %s", tmp_path_buf, path_buf, errno, strerror(errno)); ret = OB_IO_ERROR; } int err = OB_SUCCESS; ObResultCode rc; rc.result_code_ = ret; err = rc.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position()); if (OB_SUCCESS != err) { TBSYS_LOG(WARN, "Encode result code failed:ret=[%d]", err); } if (OB_SUCCESS == err) { err = server_->send_response(OB_SEND_FILE_REQUEST_RESPONSE, DEFAULT_VERSION, out_buffer, request, response_cid, session_id); if (OB_SUCCESS != err) { TBSYS_LOG(WARN, "Send send_file_end_response failed:ret[%d]", err); } } if (OB_SUCCESS == ret && OB_SUCCESS != err) { ret = err; } return ret; }
int MockChunkServer::handle_scan_table(ObPacket * ob_packet) { int ret = OB_SUCCESS; ObDataBuffer* data = ob_packet->get_buffer(); if (NULL == data) { ret = OB_ERROR; } ObScanParam 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 cell ObCellInfo cell; ObScanner scanner; ObRowkey row_key; ObString column_name; char temp[256] = ""; #if 1 cell.table_id_ = 101; for (uint64_t i = 0; i < 10; ++i) { snprintf(temp, 256, "chunk_%lu_scan_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); } #else cell.table_id_ = 123; for (uint64_t i = 100; i < 200; ++i) { snprintf(temp, 256, "row_%lu", i); row_key = make_rowkey(temp, &allocator_); cell.row_key_ = row_key; cell.column_id_ = 101; cell.value_.set_int(2234 + i); scanner.add_cell(cell); } #endif /* begin add by xiaochu */ //Scanner Range must be set other wise the ms client will report error ObNewRange range; /* /// This will cause rowkey mismatch //char *start= "chunk_0_scan_row_key:0"; //char *end = "chunk_9_scan_row_key:9"; */ char *start= (char*)"row_100"; char *end = (char*)"row_200"; range.start_key_ = make_rowkey(start, &allocator_);; range.end_key_ = make_rowkey(end, &allocator_); range.table_id_ = 103; scanner.set_range(range); scanner.set_is_req_fullfilled(true, 10); /* end add by xiaochu */ int32_t channel_id = ob_packet->getChannelId(); ret = scanner.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position()); ObScannerIterator iter; for (iter = scanner.begin(); iter != scanner.end(); ++iter) { iter.get_cell(cell); printf("server_temp:%s\n", to_cstring(cell.row_key_)); }// ret = send_response(OB_SCAN_RESPONSE, 1, out_buffer, connection, channel_id); } TBSYS_LOG(INFO, "handle scan table result:ret[%d]", ret); return ret; }
int ObFileService::receive_file_block(ObFileAppender& file_appender, char* block_buf, easy_request_t* request, ObDataBuffer& in_buffer, ObDataBuffer& out_buffer, int32_t & response_cid, const int64_t session_id) { int err = OB_SUCCESS; int64_t offset; int64_t read_size = -1; //FILL_TRACE_LOG("Start receive_file_block"); if (OB_SUCCESS == err) { err = serialization::decode_i64(in_buffer.get_data(), in_buffer.get_capacity(), in_buffer.get_position(), &offset); if (OB_SUCCESS != err) { TBSYS_LOG(WARN, "Decode offset failed: err=[%d]", err); } } if (OB_SUCCESS == err) { if (NULL == serialization::decode_vstr(in_buffer.get_data(), in_buffer.get_capacity(), in_buffer.get_position(), block_buf, block_size_, &read_size)) { err = OB_DESERIALIZE_ERROR; TBSYS_LOG(WARN, "Decode block failed"); } } //FILL_TRACE_LOG("decode end"); // write file block if (OB_SUCCESS == err) { const bool is_fsync = false; err = file_appender.append(block_buf, read_size, is_fsync); if (OB_SUCCESS != err) { TBSYS_LOG(WARN, "Appender file block failed:err=[%d]", err); } } //FILL_TRACE_LOG("append end"); // send response ObResultCode rc; int ret = OB_SUCCESS; rc.result_code_ = err; if (OB_SUCCESS == ret) { ret = rc.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position()); if (OB_SUCCESS != ret) { TBSYS_LOG(WARN, "Encode result code failed:ret=[%d]", ret); } } //FILL_TRACE_LOG("encode end"); if (OB_SUCCESS == ret) { ret = queue_thread_->prepare_for_next_request(session_id); if(OB_SUCCESS != ret) { TBSYS_LOG(WARN, "prepare for next request fail:ret[%d]", ret); } } if (OB_SUCCESS == ret) { ret = server_->send_response(OB_SEND_FILE_REQUEST_RESPONSE, DEFAULT_VERSION, out_buffer, request, response_cid, session_id); if (OB_SUCCESS != ret) { TBSYS_LOG(WARN, "Send send_file_end_response failed:ret[%d]", ret); } } //FILL_TRACE_LOG("send response end"); if (OB_SUCCESS == ret && OB_SUCCESS != err) { ret = err; } return ret; }
int ObRootRpcStub::table_exist_in_cs(const ObServer &cs, const int64_t timeout_us, const uint64_t table_id, bool &is_exist_in_cs) { int ret = OB_SUCCESS; ObDataBuffer msgbuf; if (NULL == client_mgr_) { TBSYS_LOG(ERROR, "client_mgr_=NULL"); ret = OB_ERROR; } if (OB_SUCCESS == ret) { if (OB_SUCCESS != (ret = get_thread_buffer_(msgbuf))) { TBSYS_LOG(ERROR, "failed to get thread buffer, err=%d", ret); } } if (OB_SUCCESS == ret) { if (OB_SUCCESS != (ret = serialization::encode_vi64(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position(), table_id))) { TBSYS_LOG(WARN, "fail to encode table_id, table_id=%ld, ret=%d", table_id, ret); } } if (OB_SUCCESS == ret) { if (OB_SUCCESS != (ret = client_mgr_->send_request(cs, OB_CS_CHECK_TABLET, DEFAULT_VERSION, timeout_us, msgbuf))) { TBSYS_LOG(WARN, "failed to send request, err=%d", ret); } } ObResultCode result; int64_t pos = 0; if (OB_SUCCESS == ret) { if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos))) { TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret); } } if (OB_SUCCESS == ret) { if (OB_CS_TABLET_NOT_EXIST == result.result_code_) { ret = OB_SUCCESS; is_exist_in_cs = false; } else if (OB_SUCCESS == result.result_code_) { is_exist_in_cs = true; } else { ret = result.result_code_; TBSYS_LOG(WARN, "fail to check cs tablet. table_id=%lu, cs_addr=%s, err=%d", table_id, cs.to_cstring(), ret); } } return ret; }
int MockChunkServer::handle_get_table(ObPacket * ob_packet) { int ret = OB_SUCCESS; #if 0 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; ObNewScanner scanner; ObRow row; ObObj obj_a, obj_b, obj_d; ObObj str_c; ObString var_str; var_str.assign("hello", 5); row_desc_.add_column_desc(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 0); row_desc_.add_column_desc(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 1); row_desc_.add_column_desc(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 2); row_desc_.add_column_desc(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 3); obj_a.set_int(19); obj_b.set_int(2); str_c.set_varchar(var_str); obj_d.set_int(3); row_.set_row_desc(row_desc_); row_.set_cell(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 0, obj_a); row_.set_cell(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 1, obj_b); row_.set_cell(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 2, str_c); row_.set_cell(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 3, obj_d); ObString row_key; ObString column_name; char temp[256] = ""; cell.table_id_ = 101; for (uint64_t i = 0; i < 10; ++i) { const ObRowStore::StoredRow *stored_row = NULL; ASSERT_EQ(OB_SUCCESS, store_.add_row(row_, stored_row)); ASSERT_TRUE(NULL != stored_row); /* snprintf(temp, 256, "chunk_%lu_get_row_key:%lu", i, i); row_key.assign(temp, static_cast<int32_t>(strlen(temp))); printf("server:%.*s\n", row_key.length(), row_key.ptr()); 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); } #endif TBSYS_LOG(INFO, "handle get table result:ret[%d]", ret); return ret; }
int MockChunkServer::handle_scan_table(ObPacket * ob_packet) { int ret = OB_SUCCESS; ObDataBuffer* data = ob_packet->get_buffer(); if (NULL == data) { ret = OB_ERROR; } ObScanParam 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 cell ObNewScanner scanner; ObRow row_; ObRowDesc row_desc_; ObString row_key; ObString column_name; char temp[256] = ""; ObObj obj_a, obj_b, obj_d; ObObj str_c; ObString var_str; row_desc_.add_column_desc(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 0); //row_desc_.add_column_desc(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 1); //row_desc_.add_column_desc(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 2); //row_desc_.add_column_desc(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 3); obj_a.set_int(19); obj_b.set_int(2); var_str.assign("hello", 5); str_c.set_varchar(var_str); obj_d.set_int(3); row_.set_row_desc(row_desc_); row_.set_cell(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 0, obj_a); //row_.set_cell(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 1, obj_b); //row_.set_cell(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 2, str_c); //row_.set_cell(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 3, obj_d); for (uint64_t i = 0; i < 10; ++i) { if (OB_SUCCESS != scanner.add_row(row_)) { printf("handle table scan: fail! \n"); } printf("handle table scan: add new row to scanner\n"); } /* begin add by xiaochu */ //Scanner Range must be set other wise the ms client will report error ObRange range; ObString start_key; ObString end_key; /* /// This will cause rowkey mismatch //char *start= "chunk_0_scan_row_key:0"; //char *end = "chunk_9_scan_row_key:9"; */ char *start= (char*)"row_100"; char *end = (char*)"row_200"; start_key.assign(start, static_cast<int32_t>(strlen(start))); end_key.assign(end, static_cast<int32_t>(strlen(end))); range.start_key_ = start_key; range.end_key_ = end_key; range.table_id_ = test::ObFakeTable::TABLE_ID; scanner.set_range(range); scanner.set_is_req_fullfilled(true, 10); /* end add by xiaochu */ int32_t channel_id = ob_packet->getChannelId(); if (OB_SUCCESS != (ret = scanner.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position()))) { TBSYS_LOG(WARN, "fail to serialize scanner"); } else if (OB_SUCCESS != (ret = send_response(OB_SCAN_RESPONSE, 1, out_buffer, connection, channel_id))) { TBSYS_LOG(WARN, "fail to send scanner"); } } TBSYS_LOG(INFO, "handle scan table result:ret[%d]", ret); return ret; }
int handle_scan_table2(ObDataBuffer &out_buffer) { int ret = OB_SUCCESS; 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 cell ObNewScanner scanner; ObRow row_; ObRowDesc row_desc_; ObString column_name; char temp[256] = ""; ObObj obj_a, obj_b, obj_d; ObObj str_c; ObString var_str; row_desc_.add_column_desc(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 0); //row_desc_.add_column_desc(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 1); //row_desc_.add_column_desc(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 2); //row_desc_.add_column_desc(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 3); obj_a.set_int(19); obj_b.set_int(2); var_str.assign((char*)"hello", 5); str_c.set_varchar(var_str); obj_d.set_int(3); row_.set_row_desc(row_desc_); row_.set_cell(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 0, obj_a); //row_.set_cell(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 1, obj_b); //row_.set_cell(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 2, str_c); //row_.set_cell(test::ObFakeTable::TABLE_ID, OB_APP_MIN_COLUMN_ID + 3, obj_d); /* begin add by xiaochu */ //Scanner Range must be set other wise the ms client will report error ObNewRange range; ObRowkey start_key; ObRowkey end_key; ObObj start_key_obj; ObObj end_key_obj; bool is_full; ObRowkey last_row_key; ObObj last_row_key_obj; if (times == 0) { for (uint64_t i = 0; i < 3; ++i) { if (OB_SUCCESS != scanner.add_row(row_)) { printf("handle table scan: fail! \n"); } printf("handle table scan: add new row to scanner\n"); } #if 0 start_key_obj.set_min_value(); end_key_obj.set_max_value(); start_key.assign(&start_key_obj, 1); end_key.assign(&end_key_obj, 1); range.border_flag_.set_min_value(); range.border_flag_.set_max_value(); range.border_flag_.unset_inclusive_start(); range.border_flag_.set_inclusive_end(); range.start_key_ = start_key; range.end_key_ = end_key; range.table_id_ = test::ObFakeTable::TABLE_ID; scanner.set_range(range); ObRowkey last_row_key; ObObj last_row_key_obj; last_row_key_obj.set_int(3);//100 * (times + 1)); is_full = true;//false; last_row_key.assign(&last_row_key_obj, 1); #else start_key_obj.set_min_value(); end_key_obj.set_int(100); start_key.assign(&start_key_obj, 1); end_key.assign(&end_key_obj, 1); range.start_key_.set_min_row(); range.border_flag_.unset_inclusive_start(); range.border_flag_.set_inclusive_end(); range.start_key_ = start_key; range.end_key_ = end_key; range.table_id_ = test::ObFakeTable::TABLE_ID; scanner.set_range(range); ObRowkey last_row_key; ObObj last_row_key_obj; last_row_key_obj.set_int(100 * (times + 1)); is_full = false; last_row_key.assign(&last_row_key_obj, 1); #endif scanner.set_last_row_key(last_row_key); scanner.set_is_req_fullfilled(is_full, 3); times++; TBSYS_LOG(INFO, "times = %d", times); } else if (times == 1) { for (uint64_t i = 0; i < 2; ++i) { if (OB_SUCCESS != scanner.add_row(row_)) { printf("handle table scan: fail! \n"); } printf("handle table scan: add new row to scanner\n"); } start_key_obj.set_int(100 * (times)); end_key_obj.set_int(100 * (times) + 2); start_key.assign(&start_key_obj, 1); end_key.assign(&end_key_obj, 1); range.start_key_ = start_key; range.end_key_ = end_key; range.border_flag_.unset_inclusive_start(); range.border_flag_.set_inclusive_end(); range.table_id_ = test::ObFakeTable::TABLE_ID; scanner.set_range(range); ObRowkey last_row_key; ObObj last_row_key_obj; last_row_key_obj.set_int(100 * (times + 1)); is_full = false; last_row_key.assign(&last_row_key_obj, 1); scanner.set_last_row_key(last_row_key); scanner.set_is_req_fullfilled(is_full, 2); times++; TBSYS_LOG(INFO, "times = %d", times); } else if (times == 2) { for (uint64_t i = 0; i < 5; ++i) { if (OB_SUCCESS != scanner.add_row(row_)) { printf("handle table scan: fail! \n"); } printf("handle table scan: add new row to scanner\n"); } start_key_obj.set_int(100 * (times)); end_key_obj.set_int(100 * (times) + 5); start_key.assign(&start_key_obj, 1); end_key.assign(&end_key_obj, 1); range.start_key_ = start_key; range.end_key_ = end_key; range.border_flag_.unset_inclusive_start(); range.border_flag_.set_inclusive_end(); range.table_id_ = test::ObFakeTable::TABLE_ID; scanner.set_range(range); is_full = false; last_row_key_obj.set_int(100 * (times + 1)); last_row_key.assign(&last_row_key_obj, 1); scanner.set_last_row_key(last_row_key); scanner.set_is_req_fullfilled(is_full, 5); times++; TBSYS_LOG(INFO, "times = %d", times); } else if (times == 3) { for (uint64_t i = 0; i < 4; ++i) { if (OB_SUCCESS != scanner.add_row(row_)) { printf("handle table scan: fail! \n"); } printf("handle table scan: add new row to scanner\n"); } start_key_obj.set_int(100 * (times)); end_key_obj.set_max_value(); start_key.assign(&start_key_obj, 1); end_key.assign(&end_key_obj, 1); range.start_key_ = start_key; range.border_flag_.unset_inclusive_start(); range.border_flag_.set_inclusive_end(); range.table_id_ = test::ObFakeTable::TABLE_ID; range.end_key_.set_max_row(); scanner.set_range(range); end_key_obj.set_max_value(); is_full = true; last_row_key_obj.set_max_value(); last_row_key.assign(&last_row_key_obj, 1); scanner.set_last_row_key(last_row_key); scanner.set_is_req_fullfilled(is_full, 4); times++; TBSYS_LOG(INFO, "times = %d", times); } else { TBSYS_LOG(WARN, "invalid times!!! times=%d", times); } /* end add by xiaochu */ if (OB_SUCCESS != (ret = scanner.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position()))) { TBSYS_LOG(WARN, "fail to serialize scanner"); } TBSYS_LOG(INFO, "handle scan table result:ret[%d]", ret); return ret; }
int MockUpdateServer::handle_mock_get(ObPacket *ob_packet) { int ret = OB_SUCCESS; ObDataBuffer* data = ob_packet->get_buffer(); if (NULL == data) { ret = OB_ERROR; } ObGetParam get_param; if (OB_SUCCESS == ret) { ret = get_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 cell ObCellInfo cell; ObScanner scanner; ObString row_key; ObString column_name; for (int32_t i = 0; i < get_param.get_cell_size(); i ++) { cell.table_id_ = get_param[i]->table_id_; cell.column_id_ = get_param[i]->column_id_; if (mock::join_table_id == cell.table_id_) { if (mock::join_column1_id == cell.column_id_) { row_key.assign((char*)mock::join_rowkey,strlen(mock::join_rowkey)); cell.column_id_ = mock::join_column1_id; cell.row_key_ = row_key; cell.value_.set_int(mock::join_column1_ups_value_1,true); ret = scanner.add_cell(cell); if (OB_SUCCESS == ret) { cell.value_.set_int(mock::join_column1_ups_value_2,true); ret = scanner.add_cell(cell); } } else if (mock::join_column2_id == cell.column_id_) { row_key.assign((char*)mock::join_rowkey,strlen(mock::join_rowkey)); cell.column_id_ = mock::join_column2_id; cell.row_key_ = row_key; cell.value_.set_int(mock::join_column2_ups_value_1,true); ret = scanner.add_cell(cell); if (OB_SUCCESS == ret) { cell.value_.set_int(mock::join_column2_ups_value_2,true); ret = scanner.add_cell(cell); } } else if (0 == cell.column_id_) { row_key.assign((char*)mock::join_rowkey,strlen(mock::join_rowkey)); cell.column_id_ = mock::join_column1_id; cell.row_key_ = row_key; cell.value_.set_int(mock::join_column1_ups_value_1,true); ret = scanner.add_cell(cell); if (OB_SUCCESS == ret) { cell.value_.set_int(mock::join_column1_ups_value_2,true); ret = scanner.add_cell(cell); } if (OB_SUCCESS == ret) { row_key.assign((char*)mock::join_rowkey,strlen(mock::join_rowkey)); cell.column_id_ = mock::join_column2_id; cell.row_key_ = row_key; cell.value_.set_int(mock::join_column2_ups_value_1,true); ret = scanner.add_cell(cell); if (OB_SUCCESS == ret) { cell.value_.set_int(mock::join_column2_ups_value_2,true); ret = scanner.add_cell(cell); } } cell.column_id_ = 0; } else { TBSYS_LOG(ERROR, "unepxected column id [tableid:%lu,columnid:%lu]", cell.table_id_, cell.column_id_); ret = OB_ERR_UNEXPECTED; } } else if (mock::table_id == cell.table_id_) { if (mock::column1_id == cell.column_id_) { row_key.assign((char*)mock::rowkey,strlen(mock::rowkey)); cell.column_id_ = mock::column1_id; cell.row_key_ = row_key; cell.value_.set_int(mock::column1_ups_value_1,true); ret = scanner.add_cell(cell); if (OB_SUCCESS == ret) { cell.value_.set_int(mock::column1_ups_value_2,true); ret = scanner.add_cell(cell); } } else if (mock::column2_id == cell.column_id_) { row_key.assign((char*)mock::rowkey,strlen(mock::rowkey)); cell.column_id_ = mock::column2_id; cell.row_key_ = row_key; cell.value_.set_int(mock::column2_ups_value_1,true); ret = scanner.add_cell(cell); if (OB_SUCCESS == ret) { cell.value_.set_int(mock::column2_ups_value_2,true); ret = scanner.add_cell(cell); } } else { TBSYS_LOG(ERROR, "unepxected column id [tableid:%lu,columnid:%lu]", cell.table_id_, cell.column_id_); ret = OB_ERR_UNEXPECTED; } } else { TBSYS_LOG(ERROR, "unexpected table id [tableid:%lu]", cell.table_id_); ret = OB_ERR_UNEXPECTED; } } if (OB_SUCCESS == ret) { int64_t fullfilled_item_num = 0; if(0 == cell.column_id_) { fullfilled_item_num = 1; } else { fullfilled_item_num = 2; } ret = scanner.set_is_req_fullfilled(true,fullfilled_item_num); //scanner.set_timestamp(mock::schema_timestamp); } 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 scan root table result:ret[%d]", ret); return ret; }
int MockUpdateServer::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; ObString row_key; ObString column_name; char temp[256] = ""; ObString table_name; char * name = "update_test_table"; table_name.assign(name, strlen(name)); cell.table_name_ = table_name; for (uint64_t i = 0; i < 10; ++i) { snprintf(temp, 256, "update_%lu_get_row_key:%lu", i, i); row_key.assign(temp, strlen(temp)); cell.row_key_ = row_key; column_name.assign(temp, strlen(temp)); cell.column_name_ = column_name; cell.value_.set_int(2234 + i); scanner.add_cell(cell); } 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_SCAN_RESPONSE, 1, out_buffer, connection, channel_id); } TBSYS_LOG(INFO, "handle scan root table result:ret[%d]", ret); return ret; }
int ObRootRpcStub::get_split_range(const common::ObServer& ups, const int64_t timeout_us, const uint64_t table_id, const int64_t forzen_version, ObTabletInfoList &tablets) { int ret = OB_SUCCESS; ObDataBuffer msgbuf; if (NULL == client_mgr_) { TBSYS_LOG(ERROR, "client_mgr_=NULL"); ret = OB_ERROR; } if (OB_SUCCESS == ret) { if (OB_SUCCESS != (ret = get_thread_buffer_(msgbuf))) { TBSYS_LOG(ERROR, "failed to get thread buffer, err=%d", ret); } } if (OB_SUCCESS == ret) { if (OB_SUCCESS != (ret = serialization::encode_vi64(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position(), forzen_version))) { TBSYS_LOG(WARN, "fail to encode forzen_version. forzen_version=%ld, ret=%d", forzen_version, ret); } } if (OB_SUCCESS == ret) { if (OB_SUCCESS != (ret = serialization::encode_vi64(msgbuf.get_data(), msgbuf.get_capacity(), msgbuf.get_position(), table_id))) { TBSYS_LOG(WARN, "fail to encode table_id. table_id=%lu, ret=%d", table_id, ret); } } if (OB_SUCCESS == ret) { if (OB_SUCCESS != (ret = client_mgr_->send_request(ups, OB_RS_FETCH_SPLIT_RANGE, DEFAULT_VERSION, timeout_us, msgbuf))) { TBSYS_LOG(WARN, "failed to send request, err=%d", ret); } } ObResultCode result; int64_t pos = 0; if (OB_SUCCESS == ret) { 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 fetch split range, err=%d", result.result_code_); ret = result.result_code_; } } if (OB_SUCCESS == ret) { if (OB_SUCCESS != (ret = tablets.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos))) { TBSYS_LOG(WARN, "failed to deserialize tablets, err=%d", ret); } } if (OB_SUCCESS == ret) { TBSYS_LOG(INFO, "fetch split range from ups succ."); } else { TBSYS_LOG(WARN, "fetch split range from ups fail, ups_addr=%s, version=%ld", ups.to_cstring(), forzen_version); } return ret; }
int MockUpdateServer::handle_mock_scan(ObPacket *ob_packet) { int ret = OB_SUCCESS; ObDataBuffer* data = ob_packet->get_buffer(); if (NULL == data) { ret = OB_ERROR; } ObScanParam scan_param; if (OB_SUCCESS == ret) { ret = scan_param.deserialize(data->get_data(), data->get_capacity(), data->get_position()); if (ret != OB_SUCCESS) { TBSYS_LOG(ERROR, "%s", "check scan_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 cell ObCellInfo cell; ObScanner scanner; ObString row_key; ObString column_name; cell.table_id_ = scan_param.get_table_id(); if (mock::join_table_id == cell.table_id_) { for (int32_t i = 0; i < scan_param.get_column_id_size(); i++) { if (mock::join_column1_id == scan_param.get_column_id()[i]) { row_key.assign((char*)mock::join_rowkey,strlen(mock::join_rowkey)); cell.column_id_ = mock::join_column1_id; cell.row_key_ = row_key; cell.value_.set_int(mock::join_column1_ups_value_1,true); ret = scanner.add_cell(cell); if (OB_SUCCESS == ret) { cell.value_.set_int(mock::join_column1_ups_value_2,true); ret = scanner.add_cell(cell); } } else if (mock::join_column2_id == scan_param.get_column_id()[i]) { row_key.assign((char*)mock::join_rowkey,strlen(mock::join_rowkey)); cell.column_id_ = mock::join_column2_id; cell.row_key_ = row_key; cell.value_.set_int(mock::join_column2_ups_value_1,true); ret = scanner.add_cell(cell); if (OB_SUCCESS == ret) { cell.value_.set_int(mock::join_column2_ups_value_2,true); ret = scanner.add_cell(cell); } } else { TBSYS_LOG(ERROR, "unepxected column id [tableid:%lu,columnid:%lu]", cell.table_id_, scan_param.get_column_id()[i]); ret = OB_ERR_UNEXPECTED; } } } else if (mock::table_id == cell.table_id_) { for (int32_t i = 0; i < scan_param.get_column_id_size(); i++) { if (mock::column1_id == scan_param.get_column_id()[i]) { row_key.assign((char*)mock::rowkey,strlen(mock::rowkey)); cell.column_id_ = mock::column1_id; cell.row_key_ = row_key; cell.value_.set_int(mock::column1_ups_value_1,true); ret = scanner.add_cell(cell); if (OB_SUCCESS == ret) { cell.value_.set_int(mock::column1_ups_value_2,true); ret = scanner.add_cell(cell); } } else if (mock::column2_id == scan_param.get_column_id()[i]) { row_key.assign((char*)mock::rowkey,strlen(mock::rowkey)); cell.column_id_ = mock::column2_id; cell.row_key_ = row_key; cell.value_.set_int(mock::column2_ups_value_1,true); ret = scanner.add_cell(cell); if (OB_SUCCESS == ret) { cell.value_.set_int(mock::column2_ups_value_2,true); ret = scanner.add_cell(cell); } } else { TBSYS_LOG(ERROR, "unepxected column id [tableid:%lu,columnid:%lu]", cell.table_id_, scan_param.get_column_id()[i]); ret = OB_ERR_UNEXPECTED; } } } else { TBSYS_LOG(ERROR, "unexpected table id [tableid:%lu]", cell.table_id_); ret = OB_ERR_UNEXPECTED; } if (OB_SUCCESS == ret) { ret = scanner.set_is_req_fullfilled(true,1); // scanner.set_timestamp(mock::schema_timestamp); } int64_t pos = 0; char range_buf[512]; ObString range_str; if (OB_SUCCESS == ret) { ObRange range; range.border_flag_.set_min_value(); range.border_flag_.set_max_value(); ret = range.serialize(range_buf,sizeof(range_buf),pos); if (OB_SUCCESS == ret) { range_str.assign(range_buf,pos); // ret = scanner.set_ext_info(range_str); } pos = 0; TBSYS_LOG(INFO, "pos:%ld,ret:%d",pos, range.deserialize(range_str.ptr(),range_str.length(),pos)); } int32_t channel_id = ob_packet->getChannelId(); if (OB_SUCCESS == ret) { ret = scanner.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position()); } if (OB_SUCCESS == ret) { ret = send_response(OB_GET_RESPONSE, 1, out_buffer, connection, channel_id); } } TBSYS_LOG(INFO, "handle scan root table result:ret[%d]", ret); return ret; }
int serialize_param(ObDataBuffer & data_buffer, const char* arg0) { return serialization::encode_vstr( data_buffer.get_data(), data_buffer.get_capacity(), data_buffer.get_position(), arg0); }
int ObFileService::receive_file_pre(ObFileAppender& file_appender, int64_t& file_size, ObString& file_path, ObString& tmp_file_path, easy_request_t* request, ObDataBuffer& in_buffer, ObDataBuffer& out_buffer, int32_t& response_cid, const int64_t session_id) { int err = OB_SUCCESS; if (OB_SUCCESS == err) { err = serialization::decode_i64(in_buffer.get_data(), in_buffer.get_capacity(), in_buffer.get_position(), &file_size); if (OB_SUCCESS != err) { TBSYS_LOG(WARN, "Decode file_info failed: err=[%d]", err); } } char dest_dir_buf[OB_MAX_FILE_NAME_LENGTH]; ObString dest_dir; dest_dir.assign_buffer(dest_dir_buf, sizeof(dest_dir_buf)); if (OB_SUCCESS == err) { err = dest_dir.deserialize(in_buffer.get_data(), in_buffer.get_capacity(), in_buffer.get_position()); if (OB_SUCCESS != err) { TBSYS_LOG(WARN, "Decode dest_dir failed:err=[%d]", err); } } char dest_file_name_buf[OB_MAX_FILE_NAME_LENGTH]; ObString dest_file_name; dest_file_name.assign_buffer(dest_file_name_buf, sizeof(dest_file_name_buf)); if (OB_SUCCESS == err) { err = dest_file_name.deserialize(in_buffer.get_data(), in_buffer.get_capacity(), in_buffer.get_position()); if (OB_SUCCESS != err) { TBSYS_LOG(WARN, "Decode dest_file_name failed:err=[%d]", err); } } // check dir if (OB_SUCCESS == err) { err = check_dir(dest_dir, file_size); if (OB_SUCCESS != err) { TBSYS_LOG(WARN, "Check dir failed:err=[%d]", err); } } // generate tmp_file_path and file_path char file_path_buf[OB_MAX_FILE_NAME_LENGTH]; char tmp_file_path_buf[OB_MAX_FILE_NAME_LENGTH]; if (OB_SUCCESS == err) { const char tmp_file_prefix[]= "tmp_"; int64_t count = 0; count = snprintf(file_path_buf, OB_MAX_FILE_NAME_LENGTH, "%.*s/%.*s", dest_dir.length(), dest_dir.ptr(), dest_file_name.length(), dest_file_name.ptr()); if (count<0 || count >= OB_MAX_FILE_NAME_LENGTH) { err = OB_SIZE_OVERFLOW; TBSYS_LOG(WARN, "snprintf file name failed, return[%ld] [%.*s]/[%.*s]", count, dest_dir.length(), dest_dir.ptr(), dest_file_name.length(), dest_file_name.ptr()); } count = file_path.write(file_path_buf, static_cast<ObString::obstr_size_t>(strlen(file_path_buf))); if (count != static_cast<int>(strlen(file_path_buf))) { err = OB_SIZE_OVERFLOW; TBSYS_LOG(WARN, "Write file_path_buf to ObString failed"); } count = snprintf(tmp_file_path_buf, OB_MAX_FILE_NAME_LENGTH, "%.*s/%s%.*s", dest_dir.length(), dest_dir.ptr(), tmp_file_prefix, dest_file_name.length(), dest_file_name.ptr()); if (count <0 || count >= OB_MAX_FILE_NAME_LENGTH) { err = OB_SIZE_OVERFLOW; TBSYS_LOG(WARN, "snprintf tmp file name failed, return[%ld] [%.*s]/[%s][%.*s]", count, dest_dir.length(), dest_dir.ptr(), tmp_file_prefix, dest_file_name.length(), dest_file_name.ptr()); } count = tmp_file_path.write(tmp_file_path_buf, static_cast<ObString::obstr_size_t>(strlen(tmp_file_path_buf))); if (count != static_cast<int>(strlen(tmp_file_path_buf))) { err = OB_SIZE_OVERFLOW; TBSYS_LOG(WARN, "Write tmp_file_path_buf to ObString failed"); } } // check if the tmp_file and the dest file exist already if (OB_SUCCESS == err) { if (0 == access(tmp_file_path_buf, F_OK)) { TBSYS_LOG(WARN, "Tmp file [%s] already exists", tmp_file_path_buf); err = OB_FILE_ALREADY_EXIST; } if (0 == access(file_path_buf, F_OK)) { TBSYS_LOG(WARN, "File [%s] already exists", file_path_buf); err = OB_FILE_ALREADY_EXIST; } } // log operation if (OB_SUCCESS == err) { TBSYS_LOG(INFO, "start receive file: dir[%.*s] file_name[%.*s] " "tmp_file_path[%.*s] from server [%s]", dest_dir.length(), dest_dir.ptr(), dest_file_name.length(), dest_file_name.ptr(), tmp_file_path.length(), tmp_file_path.ptr(), get_peer_ip(request)); } // open tmp file if (OB_SUCCESS == err) { bool is_dio = true; bool is_create = true; bool is_trunc = true; err = file_appender.open(tmp_file_path, is_dio, is_create, is_trunc); if (OB_SUCCESS != err) { TBSYS_LOG(WARN, "open file_appender failed:tmp_file[%.*s] err[%d]", tmp_file_path.length(), tmp_file_path.ptr(), err); } } // send response ObResultCode rc; int ret = OB_SUCCESS; rc.result_code_ = err; out_buffer.get_position() = 0; if (OB_SUCCESS == ret) { ret = rc.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position()); if(OB_SUCCESS != ret) { TBSYS_LOG(WARN, "Serialize result code failed:ret=[%d]", ret); } } if(OB_SUCCESS == ret) { ret = queue_thread_->prepare_for_next_request(session_id); if(OB_SUCCESS != ret) { TBSYS_LOG(WARN, "prepare for next request fail:ret=[%d]", ret); } } if (OB_SUCCESS == ret) { ret = server_->send_response(OB_SEND_FILE_REQUEST_RESPONSE, DEFAULT_VERSION, out_buffer, request, response_cid, session_id); if (OB_SUCCESS != ret) { TBSYS_LOG(WARN, "Send send_file_request_response failed:ret=[%d]", ret); } } if (OB_SUCCESS == ret && OB_SUCCESS != err) { ret = err; } return ret; }