int MockMergeServer::ms_scan(const int64_t start_time,const int32_t version,const int32_t channel_id,tbnet::Connection* connection,common::ObDataBuffer& in_buffer,common::ObDataBuffer& out_buffer,const int64_t timeout_us) { ObResultCode rc; rc.result_code_ = OB_SUCCESS; int ret = OB_SUCCESS; const int32_t MS_SCAN_VERSION = 1; ret = rc.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position()); if (OB_SUCCESS == ret) { ObScanner result_scanner; ObCellInfo cell; cell.table_name_.assign((char*)"table1", 6); //TODO char rowkey[30 * 1024]; cell.row_key_.assign(rowkey, 30 * 1024); cell.column_name_.assign((char*)"column1", 7); cell.value_.set_int(0xff); ret = result_scanner.add_cell(cell); result_scanner.set_is_req_fullfilled(true, 1); if (OB_SUCCESS == ret) { ret = result_scanner.serialize(out_buffer.get_data(),out_buffer.get_capacity(), out_buffer.get_position()); } if (OB_SUCCESS == ret) { ret = this->send_response(OB_SCAN_RESPONSE, MS_SCAN_VERSION, out_buffer, connection, channel_id, 0); } } return ret; }
int ObCommitLogReceiver::end_receiving_log(const int32_t version, tbnet::Connection* conn, const int32_t channel_id, common::ObDataBuffer& out_buff) { int ret = OB_SUCCESS; ret = log_writer_->flush_log(); if (OB_SUCCESS != ret) { TBSYS_LOG(ERROR, "ObLogWriter flush_log error, ret=%d", ret); } else { ObResultCode result_msg; result_msg.result_code_ = ret; ret = result_msg.serialize(out_buff.get_data(), out_buff.get_capacity(), out_buff.get_position()); if (OB_SUCCESS != ret) { TBSYS_LOG(ERROR, "ObResultCode serialize error, ret=%d", ret); } else { ret = base_server_->send_response(OB_SEND_LOG_RES, version, out_buff, conn, channel_id); if (OB_SUCCESS != ret) { TBSYS_LOG(WARN, "send_response error, ret=%d", ret); } } } return ret; }
int ObMonitor::slave_failure(const int32_t version, common::ObDataBuffer& in_buff, tbnet::Connection* conn, const uint32_t channel_id, common::ObDataBuffer& out_buff) { int err = OB_SUCCESS; ObResultCode result_msg; result_msg.result_code_ = OB_SUCCESS; if(MY_VERSION != version) { TBSYS_LOG(WARN, "version not equal. version=%d, MY_VERSION=%ld", version, MY_VERSION); result_msg.result_code_ = OB_ERROR_FUNC_VERSION; } //step1: deserialize the slave node, app_name, instance_name ObServer slave_node; if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS) { err = slave_node.deserialize(in_buff.get_data(), in_buff.get_capacity(), in_buff.get_position()); if(OB_SUCCESS != err) { TBSYS_LOG(WARN, "fail to deserialize slave node.err=%d", err); } } char app_name[OB_MAX_APP_NAME_LENGTH]; char instance_name[OB_MAX_INSTANCE_NAME_LENGTH]; int64_t len = 0; if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS) { serialization::decode_vstr(in_buff.get_data(), in_buff.get_capacity(), in_buff.get_position(), app_name, OB_MAX_APP_NAME_LENGTH, &len); if(-1 == len) { err = OB_ERROR; } } len = 0; if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS) { serialization::decode_vstr(in_buff.get_data(), in_buff.get_capacity(), in_buff.get_position(), instance_name, OB_MAX_INSTANCE_NAME_LENGTH, &len); if(-1 == len) { err = OB_ERROR; } } //step2: do the process if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS) { result_msg.result_code_ = slave_failure_(slave_node, app_name, instance_name); if(OB_SUCCESS != result_msg.result_code_) { TBSYS_LOG(WARN, "fail to process slave failure, err=%d", result_msg.result_code_); } } //step3: serialize the resultcode if(OB_SUCCESS == err) { err = result_msg.serialize(out_buff.get_data(), out_buff.get_capacity(), out_buff.get_position()); if(OB_SUCCESS != err) { TBSYS_LOG(WARN, "fail to serialize the result code .err=%d", err); } } //step4: send response if(OB_SUCCESS == err) { err = base_server_->send_response(OB_MMS_SLAVE_FAILURE_RESPONSE, MY_VERSION, out_buff, conn, channel_id); if(err != OB_SUCCESS) { TBSYS_LOG(WARN, "fail to send_response, err=%d", err); } } return err; }
int ObMonitor::node_register(const int32_t version, common::ObDataBuffer& in_buff, tbnet::Connection* conn, const uint32_t channel_id, common::ObDataBuffer& out_buff) { int err = OB_SUCCESS; ObResultCode result_msg; result_msg.result_code_ = OB_SUCCESS; if(MY_VERSION != version) { TBSYS_LOG(WARN, "version not equal. version=%d, MY_VERSION=%ld", version, MY_VERSION); result_msg.result_code_ = OB_ERROR_FUNC_VERSION; } //step1: deserialize the node and app_name instance_name ObServerExt node; char app_name[OB_MAX_APP_NAME_LENGTH]; char instance_name[OB_MAX_INSTANCE_NAME_LENGTH]; if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS) { err = node.deserialize(in_buff.get_data(), in_buff.get_capacity(), in_buff.get_position()); if(OB_SUCCESS != err) { TBSYS_LOG(WARN, "fail to deserialize node server. err = %d", err); } } int64_t len = 0; if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS) { serialization::decode_vstr(in_buff.get_data(), in_buff.get_capacity(), in_buff.get_position(), app_name, OB_MAX_APP_NAME_LENGTH, &len); if(-1 == len) { err = OB_ERROR; } } len = 0; if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS) { serialization::decode_vstr(in_buff.get_data(), in_buff.get_capacity(), in_buff.get_position(), instance_name, OB_MAX_INSTANCE_NAME_LENGTH, &len); if(-1 == len) { err = OB_ERROR; } } MMS_Status status = UNKNOWN; bool is_master = false; //step2: set the node status if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS) { result_msg.result_code_ = node_register_(node, app_name, instance_name, status); if(result_msg.result_code_ != OB_SUCCESS) { TBSYS_LOG(WARN, "fail to register node. err = %d", result_msg.result_code_); } else if(status == MASTER_ACTIVE) { is_master = true; } else { is_master = false; } } //step3: handleNodeRegister if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS) { if(node_register_handler_ != NULL) { result_msg.result_code_ = node_register_handler_->handleNodeRegister(node, app_name, instance_name, is_master); } else { TBSYS_LOG(ERROR, "have not set node_register_handler_"); result_msg.result_code_ = OB_INNER_STAT_ERROR; } if(result_msg.result_code_ != OB_SUCCESS) { TBSYS_LOG(WARN, "fail to handleNodeRegister. err=%d", result_msg.result_code_); } } //step4: serialize result_code if(OB_SUCCESS == err) { err = result_msg.serialize(out_buff.get_data(), out_buff.get_capacity(), out_buff.get_position()); if(OB_SUCCESS != err) { TBSYS_LOG(WARN, "fail to serialize result_msg,err=%d", err); } } //step5: serialize status if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS) { err = serialization::encode_vi32(out_buff.get_data(), out_buff.get_capacity(), out_buff.get_position(), status); if(OB_SUCCESS != err) { TBSYS_LOG(WARN, "fail to serialize status, err =%d", err); } } //setp6: send response if(OB_SUCCESS == err) { err = base_server_->send_response(OB_MMS_NODE_REGISTER_RESPONSE, MY_VERSION, out_buff, conn, channel_id); if(OB_SUCCESS != err) { TBSYS_LOG(WARN, "fail to send response. err=%d", err); } } return err; }
int ObFileService::handle_send_file_request( const int32_t version, const int32_t channel_id, easy_request_t* request, common::ObDataBuffer& in_buffer, common::ObDataBuffer& out_buffer) { int ret = OB_SUCCESS; bool inc_concurrency_count_flag = false; int32_t response_cid = channel_id; int64_t session_id = queue_thread_->generate_session_id(); const char* src_ip; //FILL_TRACE_LOG("handle_send_file_request"); if (!inited_) { ret = OB_NOT_INIT; TBSYS_LOG(ERROR, "ob file client is not inited yet."); } if (OB_SUCCESS == ret && NULL == request) { ret = OB_INVALID_ARGUMENT; TBSYS_LOG(WARN, "Connection param in receive_file_loop should not be null"); } if (request != NULL && request->ms != NULL && request->ms->c != NULL) { src_ip = get_peer_ip(request); } else { src_ip = ""; TBSYS_LOG(WARN, "can't get src ip for send_file_request"); } if (DEFAULT_VERSION != version) { ret = OB_ERROR_FUNC_VERSION; TBSYS_LOG(ERROR, "Can'd handle send_file_request in different version:" "Server version:%d, Packet version:%d", DEFAULT_VERSION, version); // send back error message ObResultCode rc; rc.result_code_ = OB_ERROR_FUNC_VERSION; int err = OB_SUCCESS; out_buffer.get_position() = 0; 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); } else { 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 error message for OB_SEND_FILE_REQUEST failed:" "ret[%d]", err); } } } if (OB_SUCCESS == ret) { ret = inc_concurrency_count(); if(OB_SUCCESS == ret) { inc_concurrency_count_flag = true; } else { // send back error message ObResultCode rc; int err = OB_SUCCESS; rc.result_code_ = ret; out_buffer.get_position() = 0; 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); } else { 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 error message for OB_SEND_FILE_REQUEST failed:" "ret[%d]", err); } } } } // handle... ObFileAppender file_appender; int64_t file_size; ObString file_path; ObString tmp_file_path; char file_path_buf[OB_MAX_FILE_NAME_LENGTH]; char tmp_file_path_buf[OB_MAX_FILE_NAME_LENGTH]; int64_t t1 = tbsys::CTimeUtil::getTime(); file_path.assign_buffer(file_path_buf, sizeof(file_path_buf)); tmp_file_path.assign_buffer(tmp_file_path_buf, sizeof(tmp_file_path_buf)); if (OB_SUCCESS == ret) { ret = receive_file_pre(file_appender, file_size, file_path, tmp_file_path, request, in_buffer, out_buffer, response_cid, session_id); if (OB_SUCCESS != ret) { TBSYS_LOG(ERROR, "Prepare for receive_file failed: ret=[%d]", ret); } } if (OB_SUCCESS == ret) { ret = receive_file_loop(file_path, tmp_file_path, file_size, file_appender, request, out_buffer, response_cid, session_id); if (OB_SUCCESS != ret) { TBSYS_LOG(ERROR, "Reveive_file_loop failed:ret=[%d]", ret); } } int64_t duration = tbsys::CTimeUtil::getTime() - t1; if (OB_SUCCESS == ret && duration == 0) { TBSYS_LOG(ERROR, "duration of recieve time should not be zero"); ret = OB_ERR_UNEXPECTED; } if (OB_SUCCESS == ret) { TBSYS_LOG(INFO, "Recieve file from server[%s] to file_path[%.*s] " "tmp_file_path[%.*s] filesize[%ld] time[%ld]us speed[%ld]KB/s", src_ip, file_path.length(), file_path.ptr(), tmp_file_path.length(), tmp_file_path.ptr(), file_size, duration, file_size*1000000/1024/duration); } else { TBSYS_LOG(ERROR, "Recieve file from server[%s] to file_path[%.*s] " "tmp_file_path[%.*s] failed, filesize[%ld] cost time[%ld]:ret[%d]", src_ip, file_path.length(), file_path.ptr(), tmp_file_path.length(), tmp_file_path.ptr(), file_size, duration, ret); } if (inc_concurrency_count_flag) { dec_concurrency_count(); } int tmp_ret = queue_thread_->destroy_session(session_id); if (OB_SUCCESS == ret && OB_SUCCESS != tmp_ret) { ret = tmp_ret; } //PRINT_TRACE_LOG(); return ret; }