int CellinfoBuilder::get_mutator(const ObString &row_key, const ObSchema &schema, int64_t &cur_seed, ObMutator &mutator, PageArena<char> &allocer) { int ret = OB_SUCCESS; int64_t sign = ob_crc64(row_key.ptr(), row_key.length()); uint64_t table_id = schema.get_table_id(); sign = ob_crc64(sign, &table_id, sizeof(uint64_t)); struct drand48_data rand_data; cur_seed += 1; srand48_r(sign + cur_seed, &rand_data); int64_t rand = 0; lrand48_r(&rand_data, &rand); int64_t op_num = range_rand(1, max_op_num_, rand); for (int64_t i = 0; i < op_num; i++) { ret = build_operator_(rand_data, row_key, schema, mutator, allocer); if (OB_SUCCESS != ret) { break; } } ObString table_name; table_name.assign_ptr(const_cast<char*>(schema.get_table_name()), strlen(schema.get_table_name())); ObString column_name; column_name.assign_ptr(SEED_COLUMN_NAME, strlen(SEED_COLUMN_NAME)); ObObj obj; obj.set_int(cur_seed); mutator.update(table_name, row_key, column_name, obj); return ret; }
bool get_check_row(const ObSchema &schema, const ObString &row_key, CellinfoBuilder &cb, MockClient &client, const int64_t table_start_version, const bool using_id) { bool bret = false; ObGetParam get_param; const ObColumnSchema *iter = NULL; for (iter = schema.column_begin(); iter != schema.column_end(); iter++) { ObCellInfo ci; ci.row_key_ = row_key; if (using_id) { ci.table_id_ = schema.get_table_id(); ci.column_id_ = iter->get_id(); } else { ci.table_name_.assign_ptr(const_cast<char*>(schema.get_table_name()), strlen(schema.get_table_name())); ci.column_name_.assign_ptr(const_cast<char*>(iter->get_name()), strlen(iter->get_name())); } get_param.add_cell(ci); } ObVersionRange version_range; version_range.start_version_ = table_start_version; version_range.border_flag_.set_max_value(); version_range.border_flag_.set_inclusive_start(); get_param.set_version_range(version_range); ObScanner scanner; int ret = client.ups_get(get_param, scanner, TIMEOUT_MS); if (OB_SUCCESS == ret) { RowChecker rc; while (OB_SUCCESS == scanner.next_cell()) { ObCellInfo *ci = NULL; if (OB_SUCCESS == scanner.get_cell(&ci)) { if (!using_id) { trans_name2id(*ci, schema); } rc.add_cell(ci); } } bret = rc.check_row(cb, schema); } else { TBSYS_LOG(WARN, "get ret=%d", ret); } return bret; return true; }
void trans_name2id(ObCellInfo &ci, const ObSchema &schema) { ci.table_id_ = schema.get_table_id(); if (NULL == ci.column_name_.ptr()) { ci.column_id_ = OB_INVALID_ID; } else { ci.column_id_ = schema.find_column_info(ci.column_name_)->get_id(); } }
int CellinfoBuilder::get_result(const ObString &row_key, const ObSchema &schema, const int64_t begin_seed, const int64_t end_seed, result_set_t &result, PageArena<char> &allocer) { int ret = OB_SUCCESS; for (int64_t seed = begin_seed; seed <= end_seed; seed++) { int64_t sign = ob_crc64(row_key.ptr(), row_key.length()); uint64_t table_id = schema.get_table_id(); sign = ob_crc64(sign, &table_id, sizeof(uint64_t)); struct drand48_data rand_data; srand48_r(sign + seed, &rand_data); int64_t rand = 0; lrand48_r(&rand_data, &rand); int64_t op_num = range_rand(1, max_op_num_, rand); for (int64_t i = 0; i < op_num; i++) { int op_type = 0; int64_t column_pos = 0; ObCellInfo *cell_info = (ObCellInfo*)allocer.alloc(sizeof(ObCellInfo)); cell_info->reset(); const ObColumnSchema *column_schema = schema.column_begin(); build_cell_(rand_data, row_key, schema, cell_info->value_, column_pos, op_type, allocer); cell_info->table_id_ = table_id; cell_info->row_key_ = row_key; if (DEL_ROW == op_type) { cell_info->column_id_ = OB_INVALID_ID; } else { cell_info->column_id_ = column_schema[column_pos].get_id(); } merge_obj(op_type, cell_info, result); } } return ret; }
void prepare_scan_param(ObScanParam &scan_param, const ObSchema &schema, const int64_t table_start_version, const bool using_id) { ObRange range; range.border_flag_.set_min_value(); range.border_flag_.set_max_value(); const ObColumnSchema *iter = NULL; for (iter = schema.column_begin(); iter != schema.column_end(); iter++) { if (using_id) { scan_param.add_column(iter->get_id()); } else { ObString column_name; column_name.assign_ptr(const_cast<char*>(iter->get_name()), strlen(iter->get_name())); scan_param.add_column(column_name); } } if (using_id) { scan_param.set(schema.get_table_id(), ObString(), range); } else { ObString table_name; table_name.assign(const_cast<char*>(schema.get_table_name()), strlen(schema.get_table_name())); scan_param.set(OB_INVALID_ID, table_name, range); } ObVersionRange version_range; version_range.start_version_ = table_start_version; version_range.border_flag_.set_max_value(); version_range.border_flag_.set_inclusive_start(); scan_param.set_version_range(version_range); }
int64_t MutatorBuilder::get_cur_seed_(const seed_map_t &seed_map, const ObSchema &schema, const ObString &row_key, const bool using_id) { int64_t cur_seed = 0; TEKey te_key; te_key.table_id = schema.get_table_id(); te_key.row_key = row_key; int hash_ret = 0; if (HASH_EXIST != (hash_ret = seed_map.get(te_key, cur_seed))) { ObGetParam get_param; ObScanner scanner; ObCellInfo cell_info; cell_info.row_key_ = row_key; if (using_id) { cell_info.table_id_ = schema.get_table_id(); cell_info.column_id_ = SEED_COLUMN_ID; } else { cell_info.table_name_.assign_ptr(const_cast<char*>(schema.get_table_name()), static_cast<int32_t>(strlen(schema.get_table_name()))); cell_info.column_name_.assign_ptr((char*)SEED_COLUMN_NAME, static_cast<int32_t>(strlen(SEED_COLUMN_NAME))); } get_param.add_cell(cell_info); ObVersionRange version_range; version_range.start_version_ = table_start_version_; version_range.border_flag_.set_max_value(); version_range.border_flag_.set_inclusive_start(); get_param.set_version_range(version_range); if (OB_SUCCESS == client_.get(get_param, scanner)) { CellinfoBuilder::result_set_t result_set; MemTank mem_tank; while (OB_SUCCESS == scanner.next_cell()) { ObCellInfo *ci = NULL; if (OB_SUCCESS != scanner.get_cell(&ci)) { break; } if (!using_id) { ::trans_name2id(*ci, schema); } ObCellInfo *new_ci = copy_cell(mem_tank, ci); CellinfoBuilder::merge_obj(new_ci, result_set); } if (0 != result_set.size()) { ObCellInfo *ret_ci = NULL; result_set.get(SEED_COLUMN_ID, ret_ci); if (NULL != ret_ci) { ret_ci->value_.get_int(cur_seed); } TBSYS_LOG(DEBUG, "seed get from oceanbase %s", print_cellinfo(ret_ci)); } } else { abort(); } } if (0 == cur_seed) { cur_seed = SEED_START; TBSYS_LOG(DEBUG, "first seed from cur_seed=%ld row_key=[%.*s]", cur_seed, row_key.length(), row_key.ptr()); } else { cur_seed += 1; } TBSYS_LOG(DEBUG, "get cur_seed=%ld hash_ret=%d row_key=[%.*s]", cur_seed, hash_ret, row_key.length(), row_key.ptr()); return cur_seed; }
int64_t MutatorBuilder::query_prefix_meta_(const ObSchema &schema, const bool using_id, const int64_t prefix_start, const char *column_name) { int64_t ret = 0; ObGetParam get_param; ObScanner scanner; ObCellInfo cell_info; if (using_id) { cell_info.table_id_ = schema.get_table_id(); cell_info.column_id_ = schema.find_column_info(column_name)->get_id(); } else { cell_info.table_name_.assign_ptr(const_cast<char*>(schema.get_table_name()), static_cast<int32_t>(strlen(schema.get_table_name()))); cell_info.column_name_.assign_ptr(const_cast<char*>(column_name), static_cast<int32_t>(strlen(column_name))); } char rowkey_info_buffer[1024]; sprintf(rowkey_info_buffer, "%s%020ld", ROWKEY_INFO_ROWKEY, prefix_start); cell_info.row_key_.assign_ptr(rowkey_info_buffer, static_cast<int32_t>(strlen(rowkey_info_buffer))); get_param.add_cell(cell_info); ObVersionRange version_range; version_range.start_version_ = table_start_version_; version_range.border_flag_.set_max_value(); version_range.border_flag_.set_inclusive_start(); get_param.set_version_range(version_range); if (OB_SUCCESS == (ret = client_.get(get_param, scanner))) { CellinfoBuilder::result_set_t result_set; ::MemTank mem_tank; while (OB_SUCCESS == scanner.next_cell()) { ObCellInfo *ci = NULL; if (OB_SUCCESS != scanner.get_cell(&ci)) { break; } if (!using_id) { ::trans_name2id(*ci, schema); } ObCellInfo *new_ci = copy_cell(mem_tank, ci); CellinfoBuilder::merge_obj(new_ci, result_set); } if (0 != result_set.size()) { ObCellInfo *ret_ci = NULL; result_set.get(schema.find_column_info(column_name)->get_id(), ret_ci); if (NULL != ret_ci) { ret_ci->value_.get_int(ret); } } } else { abort(); } return ret; }