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 rpc_cs_migrate(ObClientManager& cp, const ObServer& src, const ObServer& dest, const ObRange& range, bool keep_src) { int ret = OB_SUCCESS; int64_t start = 0, end = 0; const int32_t BUFFER_SIZE = 2*1024*1024; char* param_buffer = new char[BUFFER_SIZE]; ObDataBuffer ob_inout_buffer; ObResultCode rc; int64_t return_start_pos = 0; if (NULL == param_buffer) { goto exit; } ob_inout_buffer.set_data(param_buffer, BUFFER_SIZE); ret = range.serialize(ob_inout_buffer.get_data(), ob_inout_buffer.get_capacity(), ob_inout_buffer.get_position()); if (OB_SUCCESS != ret) { fprintf(stderr,"serialize migrate range into buffer failed\n"); goto exit; } ret = dest.serialize(ob_inout_buffer.get_data(), ob_inout_buffer.get_capacity(), ob_inout_buffer.get_position()); if (OB_SUCCESS != ret) { fprintf(stderr,"serialize dest_server into buffer failed\n"); goto exit; } ret = encode_bool(ob_inout_buffer.get_data(),ob_inout_buffer.get_capacity(),ob_inout_buffer.get_position(),keep_src); if (OB_SUCCESS != ret) { fprintf(stderr,"serialize keep_src into buffer failed\n"); goto exit; } // send request; start = tbsys::CTimeUtil::getTime(); ret = cp.send_request(src, OB_CS_MIGRATE, 1, 2000*2000, ob_inout_buffer); end = tbsys::CTimeUtil::getTime(); fprintf(stderr,"time consume:%ld\n", end - start); if (OB_SUCCESS != ret) { fprintf(stderr,"rpc failed\n"); goto exit; } ret = rc.deserialize(ob_inout_buffer.get_data(), ob_inout_buffer.get_position(), return_start_pos); if (OB_SUCCESS != ret) { fprintf(stderr,"deserialize failed\n"); goto exit; } fprintf(stderr,"return rc code:%d, msg:%s\n", rc.result_code_, rc.message_.ptr()); if (OB_SUCCESS != rc.result_code_) { goto exit; } fprintf(stderr,"return_start_pos:%ld, %ld\n", return_start_pos, ob_inout_buffer.get_position()); exit: if (param_buffer) delete []param_buffer; return ret; }
int ObMergerTabletLocationCache::set(const ObRange & range, const ObMergerTabletLocationList & location) { int ret = OB_SUCCESS; if (!init_) { TBSYS_LOG(ERROR, "%s", "check init failed"); ret = OB_INNER_STAT_ERROR; } else { ObCachePair pair; // malloc the pair mem buffer int64_t size = range.get_serialize_size(); ret = tablet_cache_.malloc(pair, static_cast<int32_t>(size), static_cast<int32_t>(location.get_serialize_size())); if (OB_SUCCESS != ret) { TBSYS_LOG(ERROR, "check malloc failed:key_size[%lu], ret[%d]", size, ret); } int64_t pos = 0; // key serialize to the pair if (OB_SUCCESS == ret) { ret = range.serialize(pair.get_key().ptr(), size, pos); if (ret != OB_SUCCESS) { TBSYS_LOG(ERROR, "serialize range failed:ret[%d]", ret); } } // value serialize to the pair if (OB_SUCCESS == ret) { pos = 0; ret = location.serialize(pair.get_value().ptr(), location.get_serialize_size(), pos); if (ret != OB_SUCCESS) { TBSYS_LOG(ERROR, "serialize locationlist failed:ret[%d]", ret); } } // delete the old cache item if (OB_SUCCESS == ret) { ret = del(range.table_id_, range.end_key_); if ((ret != OB_SUCCESS) && (ret != OB_ENTRY_NOT_EXIST)) { TBSYS_LOG(WARN, "del the old item:table[%lu], ret[%d]", range.table_id_, ret); } else { ret = OB_SUCCESS; } } // add new pair and return the old pair for deletion if (OB_SUCCESS == ret) { ObCachePair oldpair; ret = tablet_cache_.add(pair, oldpair); if (ret != OB_SUCCESS) { TBSYS_LOG(ERROR, "add the pair failed:ret[%d]", ret); } else { TBSYS_LOG(DEBUG, "%s", "set tablet location cache succ"); } } } return ret; }