void total_scan(const char *fname, PageArena<char> &allocer, MockClient &client, const char *version_range) { ObScanner scanner; ObScanParam scan_param; read_scan_param(fname, SCAN_PARAM_SECTION, allocer, scan_param); scan_param.set_version_range(str2range(version_range)); scan_param.set_is_read_consistency(false); int64_t total_fullfilled_num = 0; int64_t total_row_counter = 0; int64_t total_timeu = 0; while (true) { int64_t timeu = tbsys::CTimeUtil::getTime(); int err = client.ups_scan(scan_param, scanner, timeout); timeu = tbsys::CTimeUtil::getTime() - timeu; if (OB_SUCCESS != err) { fprintf(stdout, "[%s] err=%d\n", __FUNCTION__, err); break; } else { int64_t row_counter = 0; while (OB_SUCCESS == scanner.next_cell()) { ObCellInfo *ci = NULL; bool is_row_changed = false; scanner.get_cell(&ci, &is_row_changed); //fprintf(stdout, "%s\n", updateserver::print_cellinfo(ci, "CLI_SCAN")); if (is_row_changed) { row_counter++; } } bool is_fullfilled = false; int64_t fullfilled_num = 0; ObRowkey last_rk; scanner.get_last_row_key(last_rk); scanner.get_is_req_fullfilled(is_fullfilled, fullfilled_num); fprintf(stdout, "[SINGLE_SCAN] is_fullfilled=%s fullfilled_num=%ld row_counter=%ld timeu=%ld last_row_key=[%s]\n", STR_BOOL(is_fullfilled), fullfilled_num, row_counter, timeu, to_cstring(last_rk)); total_fullfilled_num += fullfilled_num; total_row_counter += row_counter; total_timeu += timeu; if (is_fullfilled) { break; } else { const_cast<ObNewRange*>(scan_param.get_range())->start_key_ = last_rk; const_cast<ObNewRange*>(scan_param.get_range())->border_flag_.unset_min_value(); const_cast<ObNewRange*>(scan_param.get_range())->border_flag_.unset_inclusive_start(); } } } fprintf(stdout, "[TOTAL_SCAN] total_fullfilled_num=%ld total_row_counter=%ld total_timeu=%ld\n", total_fullfilled_num, total_row_counter, total_timeu); }
int print_scanner(const char * buffer, const int64_t len, int64_t & pos, FILE * file) { int ret = OB_SUCCESS; if ((NULL == buffer) || (NULL == file)) { TBSYS_LOG(ERROR, "check buffer failed:buff[%p], file[%p]", buffer, file); ret = OB_ERROR; } else { ObScanner result; ret = result.deserialize(buffer, len, pos); if (ret != OB_SUCCESS) { TBSYS_LOG(ERROR, "check deserialize scanner failed:pos[%ld], ret[%d]", pos, ret); } else { bool first_cell = true; ObCellInfo * cur_cell = NULL; ObCellInfo * pre_cell = NULL; while (result.next_cell() == OB_SUCCESS) { ret = result.get_cell(&cur_cell); if (OB_SUCCESS == ret) { pre_cell = cur_cell; if (first_cell) { first_cell = false; fprintf(file, "table_name:%.*s, rowkey:%.*s\n", cur_cell->table_name_.length(), cur_cell->table_name_.ptr(), cur_cell->row_key_.length(), cur_cell->row_key_.ptr()); } /* fprintf(file, "table_name:%.*s, rowkey:%.*s, column_name:%.*s, ext:%ld, type:%d\n", cur_cell->table_name_.length(), cur_cell->table_name_.ptr(), cur_cell->row_key_.length(), cur_cell->row_key_.ptr(), cur_cell->column_name_.length(), cur_cell->column_name_.ptr(), cur_cell->value_.get_ext(),cur_cell->value_.get_type()); //cur_cell->value_.dump(); */ } else { ret = OB_ERROR; TBSYS_LOG(ERROR, "get cell failed:ret[%d]", ret); break; } } if (OB_SUCCESS == ret) { fprintf(file, "table_name:%.*s, rowkey:%.*s\n", pre_cell->table_name_.length(), pre_cell->table_name_.ptr(), pre_cell->row_key_.length(), pre_cell->row_key_.ptr()); } } } 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; }
bool MultiGetP::check_result(const uint32_t min_key_include, const uint32_t max_key_include, ObScanner &result, void *arg) { bool res = true; int err = OB_SUCCESS; UNUSED(min_key_include); UNUSED(max_key_include); ObGetParam *get_param = reinterpret_cast<ObGetParam*>(arg); ObCellInfo *cur_cell = NULL; if ((OB_SUCCESS == err) && (result.get_cell_num() != get_param->get_cell_size())) { TBSYS_LOG(WARN,"result cell count not correct [got_cell_count:%ld,request_cell_count:%ld]", result.get_cell_num(), get_param->get_cell_size()); err = OB_ERR_UNEXPECTED; } for (int64_t i = 0; (i < get_param->get_cell_size()) && (OB_SUCCESS == err); i++) { if ((OB_SUCCESS == err) && (OB_SUCCESS != (err = result.next_cell()))) { TBSYS_LOG(WARN,"fail to get next cell [err:%d]", err); } if ((OB_SUCCESS == err) && (OB_SUCCESS != (err = result.get_cell(&cur_cell)))) { TBSYS_LOG(WARN,"fail to get next cell [err:%d]", err); } if (OB_SUCCESS == err) { if ((cur_cell->table_name_ != (*get_param)[i]->table_name_) || (cur_cell->column_name_ != (*get_param)[i]->column_name_) || (cur_cell->row_key_ != (*get_param)[i]->row_key_) || !(msolap::olap_check_cell(*cur_cell))) { TBSYS_LOG(WARN,"cell error"); err = OB_ERR_UNEXPECTED; } } } if ((OB_SUCCESS == err) && (result.next_cell() != OB_ITER_END)) { TBSYS_LOG(WARN,"result not ended as expected"); err = OB_ERR_UNEXPECTED; } if (OB_SUCCESS != err) { res = false; } return res; }
bool GetNotExistRows::check_result(const uint32_t min_key_include, const uint32_t max_key_include, ObScanner &result, void *arg) { bool res = true; int err = OB_SUCCESS; UNUSED(min_key_include); UNUSED(max_key_include); ObGetParam *get_param = reinterpret_cast<ObGetParam*>(arg); if(result.get_cell_num() != get_param->get_cell_size()) { TBSYS_LOG(WARN,"result cell number error [got:%ld,expcted:%ld]", result.get_cell_num(), get_param->get_cell_size()); err = OB_ERR_UNEXPECTED; } int64_t got_cell_num = 0; ObCellInfo *cur_cell = NULL; for (got_cell_num = 0; (got_cell_num < get_param->get_cell_size()) && (OB_SUCCESS == err); got_cell_num++) { if (OB_SUCCESS != (err = result.next_cell())) { TBSYS_LOG(WARN,"fail to get next cell from result [err:%d]", err); } if ((OB_SUCCESS == err) && (OB_SUCCESS != (err = result.get_cell(&cur_cell)))) { TBSYS_LOG(WARN,"fail to get next cell from result [err:%d]", err); } if ((OB_SUCCESS == err) && ((cur_cell->table_name_ != msolap::target_table_name) || (cur_cell->row_key_ != (*get_param)[got_cell_num]->row_key_) || (ObActionFlag::OP_ROW_DOES_NOT_EXIST != cur_cell->value_.get_ext()))) { TBSYS_LOG(WARN,"cell content error"); err = OB_ERR_UNEXPECTED; } } if ((OB_SUCCESS == err) && (OB_ITER_END != result.next_cell())) { TBSYS_LOG(WARN,"fail to get enough cells from result"); err = OB_ERR_UNEXPECTED; } if (OB_SUCCESS != err) { res = false; } return res; }
void print_root_table(FILE* fd, ObScanner &scanner) { ObCellInfo* cell = NULL; bool is_row_changed = false; while(OB_SUCCESS == scanner.next_cell()) { if (OB_SUCCESS == scanner.get_cell(&cell, &is_row_changed)) { if (is_row_changed) { fprintf(fd, "\n"); print_rowkey(fd, cell->row_key_); fprintf(fd, "|"); } fprintf(fd, "%.*s ", cell->column_name_.length(), cell->column_name_.ptr()); cell->value_.print_value(fd); fprintf(fd, "|"); } } fprintf(fd, "\n"); }
void print_scanner(ObScanner &scanner) { int64_t row_counter = 0; while (OB_SUCCESS == scanner.next_cell()) { ObCellInfo *ci = NULL; bool is_row_changed = false; scanner.get_cell(&ci, &is_row_changed); fprintf(stdout, "%s\n", common::print_cellinfo(ci, "CLI_SCAN")); if (is_row_changed) { row_counter++; } } bool is_fullfilled = false; int64_t fullfilled_num = 0; ObRowkey last_rk; scanner.get_last_row_key(last_rk); scanner.get_is_req_fullfilled(is_fullfilled, fullfilled_num); fprintf(stdout, "is_fullfilled=%s fullfilled_num=%ld row_counter=%ld last_row_key=[%s]\n", STR_BOOL(is_fullfilled), fullfilled_num, row_counter, to_cstring(last_rk)); }
int param_get(const char *fname, MockClient &client) { int err = OB_SUCCESS; int fd = open(fname, O_RDONLY); if (-1 == fd) { fprintf(stdout, "open [%s] fail errno=%u\n", fname, errno); err = OB_ERROR; } else { struct stat st; fstat(fd, &st); char *buf = (char*)malloc(st.st_size); if (NULL == buf) { fprintf(stdout, "malloc buf fail size=%ld\n", st.st_size); err = OB_ERROR; } else { ssize_t __attribute__((unused)) ret = read(fd, buf, st.st_size); int64_t pos = 0; ObGetParam get_param; if (OB_SUCCESS != get_param.deserialize(buf, st.st_size, pos)) { fprintf(stdout, "deserialize get_param fail\n"); err = OB_ERROR; } else { get_param.set_is_read_consistency(false); ObScanner scanner; int err = client.ups_get(get_param, scanner, timeout); fprintf(stdout, "[%s] err=%d\n", __FUNCTION__, err); if (OB_SUCCESS == err) { int64_t row_counter = 0; while (OB_SUCCESS == scanner.next_cell()) { ObCellInfo *ci = NULL; bool is_row_changed = false; scanner.get_cell(&ci, &is_row_changed); fprintf(stdout, "%s\n", common::print_cellinfo(ci, "CLI_GET")); if (is_row_changed) { row_counter++; } } bool is_fullfilled = false; int64_t fullfilled_num = 0; ObRowkey last_rk; scanner.get_last_row_key(last_rk); scanner.get_is_req_fullfilled(is_fullfilled, fullfilled_num); fprintf(stdout, "is_fullfilled=%s fullfilled_num=%ld row_counter=%ld last_row_key=[%s]\n", STR_BOOL(is_fullfilled), fullfilled_num, row_counter, to_cstring(last_rk)); } } free(buf); } close(fd); } return err; }
TEST(TestObScanner, add_cell) { ObScanner fem; fem.set_is_req_fullfilled(true, 1011); fem.set_data_version(170); char buf[BUFSIZ]; int64_t pospos = 0; fem.serialize(buf, BUFSIZ, pospos); FILE *fd; fd = fopen("tmptest", "w+"); fwrite(buf, 1, pospos, fd); fclose(fd); ObScanner os; ObScanner ost; /*** added by wushi ***/ int64_t fullfilled_item = 0; int64_t tmp = 0; bool is_fullfilled = true; bool tmp_bool = false; /// initialize ASSERT_EQ(os.get_is_req_fullfilled(tmp_bool, fullfilled_item),0); EXPECT_FALSE(tmp_bool); ASSERT_EQ(fullfilled_item,0); /// set fullfilled is_fullfilled = true; fullfilled_item = 1000; os.set_is_req_fullfilled(is_fullfilled,fullfilled_item); ASSERT_EQ(os.get_is_req_fullfilled(tmp_bool, tmp),0); ASSERT_EQ(tmp_bool,is_fullfilled); ASSERT_EQ(tmp,fullfilled_item); /*** added by wushi ***/ ObCellInfo oci; oci.table_name_.assign((char*)"table1", 6); oci.row_key_.assign((char*)"row1", 4); oci.column_name_.assign((char*)"column1", 7); oci.value_.set_int(0xff); ost.set_mem_size_limit(20); ASSERT_EQ(OB_SIZE_OVERFLOW, ost.add_cell(oci)); os.set_mem_size_limit(1024 * 1024 * 2); ASSERT_EQ(OB_SUCCESS, os.add_cell(oci)); oci.column_name_.assign((char*)"column2", 7); oci.value_.set_int(0xfe); ASSERT_EQ(OB_SUCCESS, os.add_cell(oci)); ObScannerIterator iter = os.begin(); ObCellInfo tci; ASSERT_EQ(OB_SUCCESS, iter.get_cell(tci)); ASSERT_EQ(string("table1"), string(tci.table_name_.ptr(), tci.table_name_.length())); ASSERT_EQ(string("row1"), string(tci.row_key_.ptr(), tci.row_key_.length())); ASSERT_EQ(string("column1"), string(tci.column_name_.ptr(), tci.column_name_.length())); ASSERT_EQ(OB_SUCCESS, tci.value_.get_int(tmp)); ASSERT_EQ(0xff, tmp); iter++; ASSERT_EQ(OB_SUCCESS, iter.get_cell(tci)); ASSERT_EQ(string("table1"), string(tci.table_name_.ptr(), tci.table_name_.length())); ASSERT_EQ(string("row1"), string(tci.row_key_.ptr(), tci.row_key_.length())); ASSERT_EQ(string("column2"), string(tci.column_name_.ptr(), tci.column_name_.length())); ASSERT_EQ(OB_SUCCESS, tci.value_.get_int(tmp)); ASSERT_EQ(0xfe, tmp); iter++; ASSERT_EQ(true, os.end() == iter); //ObCellInfo oci; char row_key_buffer[1024]; oci.table_name_.assign((char*)"table1", 6); sprintf(row_key_buffer, "row1"); oci.row_key_.assign(row_key_buffer, 4); oci.column_name_.assign((char*)"column1", 7); oci.value_.set_int(0xff); ASSERT_EQ(OB_SUCCESS, os.add_cell(oci)); oci.table_name_.assign((char*)"table1", 6); sprintf(row_key_buffer, "row1"); oci.row_key_.assign(row_key_buffer, 4); oci.column_name_.assign((char*)"column2", 7); oci.value_.set_int(0xee); os.set_mem_size_limit(20); ASSERT_EQ(OB_SIZE_OVERFLOW, os.add_cell(oci)); os.set_mem_size_limit(1024 * 1024 * 2); ASSERT_EQ(OB_SUCCESS, os.add_cell(oci)); oci.table_name_.assign((char*)"table1", 6); sprintf(row_key_buffer, "row2"); oci.row_key_.assign(row_key_buffer, 4); oci.column_name_.assign((char*)"column1", 7); oci.value_.set_int(0xdd); ASSERT_EQ(OB_SUCCESS, os.add_cell(oci)); oci.table_name_.assign((char*)"table2", 6); sprintf(row_key_buffer, "row2"); oci.row_key_.assign(row_key_buffer, 4); oci.column_name_.assign((char*)"column1", 7); oci.value_.set_int(0xcc); ASSERT_EQ(OB_SUCCESS, os.add_cell(oci)); oci.table_name_.assign((char*)"table3", 6); sprintf(row_key_buffer, "row2"); oci.row_key_.assign(row_key_buffer, 4); oci.column_name_.assign((char*)"column1", 7); oci.value_.set_int(0xbb); ASSERT_EQ(OB_SUCCESS, os.add_cell(oci)); fprintf(stdout, "size=%ld\n", os.get_serialize_size()); char buffer[2048]; int64_t pos = 0; ASSERT_EQ(OB_SUCCESS, os.serialize(buffer, 1024, pos)); ASSERT_EQ(pos, os.get_serialize_size()); fd = fopen("./test.data.before_rollback", "w+"); fwrite(buffer, 1, 1024, fd); fclose(fd); for (iter = os.begin(); iter != os.end(); iter++) { ObCellInfo ci; ASSERT_EQ(OB_SUCCESS, iter.get_cell(ci)); fprintf(stdout, "table_name=[%.*s] row_key=[%.*s] column_name=[%.*s]\n", ci.table_name_.length(), ci.table_name_.ptr(), ci.row_key_.length(), ci.row_key_.ptr(), ci.column_name_.length(), ci.column_name_.ptr()); } fprintf(stdout, "==============================\n"); while (OB_SUCCESS == os.next_cell()) { ObCellInfo *ci = NULL; bool is_row_changed; ASSERT_EQ(OB_SUCCESS, os.get_cell(&ci, &is_row_changed)); fprintf(stdout, "table_name=[%.*s] row_key=[%.*s] column_name=[%.*s] " "table_id=[%lu] column_id=[%lu] row_changed=[%d]\n", ci->table_name_.length(), ci->table_name_.ptr(), ci->row_key_.length(), ci->row_key_.ptr(), ci->column_name_.length(),ci->column_name_.ptr(), ci->table_id_, ci->column_id_, is_row_changed); } os.reset_iter(); fprintf(stdout, "==============================\n"); ASSERT_EQ(OB_SUCCESS, os.rollback()); fprintf(stdout, "size=%ld\n", os.get_serialize_size()); pos = 0; ASSERT_EQ(OB_SUCCESS, os.serialize(buffer, 1024, pos)); ASSERT_EQ(pos, os.get_serialize_size()); fd = fopen("./test.data.after_rollback", "w+"); fwrite(buffer, 1, 1024, fd); fclose(fd); for (iter = os.begin(); iter != os.end(); iter++) { ObCellInfo ci; ASSERT_EQ(OB_SUCCESS, iter.get_cell(ci)); fprintf(stdout, "table_name=[%.*s] row_key=[%.*s] column_name=[%.*s]\n", ci.table_name_.length(), ci.table_name_.ptr(), ci.row_key_.length(), ci.row_key_.ptr(), ci.column_name_.length(), ci.column_name_.ptr()); ASSERT_EQ(OB_SUCCESS, iter.get_cell(ci)); fprintf(stdout, "table_name=[%.*s] row_key=[%.*s] column_name=[%.*s]\n", ci.table_name_.length(), ci.table_name_.ptr(), ci.row_key_.length(), ci.row_key_.ptr(), ci.column_name_.length(), ci.column_name_.ptr()); } fprintf(stdout, "==============================\n"); while (OB_SUCCESS == os.next_cell()) { ObCellInfo *ci = NULL; bool is_row_changed; ASSERT_EQ(OB_SUCCESS, os.get_cell(&ci, &is_row_changed)); fprintf(stdout, "table_name=[%.*s] row_key=[%.*s] column_name=[%.*s] " "table_id=[%lu] column_id=[%lu] row_changed=[%d]\n", ci->table_name_.length(), ci->table_name_.ptr(), ci->row_key_.length(), ci->row_key_.ptr(), ci->column_name_.length(),ci->column_name_.ptr(), ci->table_id_, ci->column_id_, is_row_changed); ASSERT_EQ(OB_SUCCESS, os.get_cell(&ci, &is_row_changed)); fprintf(stdout, "table_name=[%.*s] row_key=[%.*s] column_name=[%.*s] " "table_id=[%lu] column_id=[%lu] row_changed=[%d]\n", ci->table_name_.length(), ci->table_name_.ptr(), ci->row_key_.length(), ci->row_key_.ptr(), ci->column_name_.length(),ci->column_name_.ptr(), ci->table_id_, ci->column_id_, is_row_changed); } os.reset_iter(); fprintf(stdout, "==============================\n"); pos = 0; ASSERT_EQ(OB_SUCCESS, os.deserialize(buffer, os.get_serialize_size(), pos)); ASSERT_EQ(pos, os.get_serialize_size()); for (iter = os.begin(); iter != os.end(); iter++) { ObCellInfo ci; ASSERT_EQ(OB_SUCCESS, iter.get_cell(ci)); fprintf(stdout, "table_name=[%.*s] row_key=[%.*s] column_name=[%.*s]\n", ci.table_name_.length(), ci.table_name_.ptr(), ci.row_key_.length(), ci.row_key_.ptr(), ci.column_name_.length(), ci.column_name_.ptr()); ASSERT_EQ(OB_SUCCESS, iter.get_cell(ci)); fprintf(stdout, "table_name=[%.*s] row_key=[%.*s] column_name=[%.*s]\n", ci.table_name_.length(), ci.table_name_.ptr(), ci.row_key_.length(), ci.row_key_.ptr(), ci.column_name_.length(), ci.column_name_.ptr()); } fprintf(stdout, "==============================\n"); while (OB_SUCCESS == os.next_cell()) { ObCellInfo *ci = NULL; bool is_row_changed; ASSERT_EQ(OB_SUCCESS, os.get_cell(&ci, &is_row_changed)); fprintf(stdout, "table_name=[%.*s] row_key=[%.*s] column_name=[%.*s] " "table_id=[%lu] column_id=[%lu] row_changed=[%d]\n", ci->table_name_.length(), ci->table_name_.ptr(), ci->row_key_.length(), ci->row_key_.ptr(), ci->column_name_.length(),ci->column_name_.ptr(), ci->table_id_, ci->column_id_, is_row_changed); } os.reset_iter(); /// set fullfilled // ASSERT_EQ(os.get_is_req_fullfilled(tmp_bool, tmp),0); // ASSERT_EQ(tmp_bool,is_fullfilled); // ASSERT_EQ(tmp,fullfilled_item); { ObRange range; range.border_flag_.set_inclusive_start(); range.start_key_.assign((char*)"11111", 5); range.end_key_.assign((char*)"22222", 5); ObRange range2; range2.border_flag_.set_inclusive_start(); range2.start_key_.assign((char*)"11111", 5); range2.end_key_.assign((char*)"22222", 5); int64_t pos = 0; int64_t data_len = 0; is_fullfilled = true; fullfilled_item = 1212; ObScanner os1; ObScanner os2; ASSERT_EQ(os1.set_is_req_fullfilled(is_fullfilled, fullfilled_item),0); os1.set_data_version(100); ASSERT_EQ(os1.set_range(range),0); range.border_flag_.set_inclusive_end(); char buf[1024]; ASSERT_EQ(os1.serialize(buf,sizeof(buf),pos),0); data_len = pos; pos = 0; ASSERT_EQ(os2.deserialize(buf, data_len, pos),0); memset(buf, 0x00, 1024); ASSERT_EQ(os2.get_is_req_fullfilled(tmp_bool, tmp),0); EXPECT_EQ(is_fullfilled, tmp_bool); ASSERT_EQ(fullfilled_item, tmp); ASSERT_EQ(os1.get_data_version(),100); ObRange range3; ASSERT_EQ(OB_SUCCESS, os2.get_range(range3)); ASSERT_EQ(range2.border_flag_.get_data(), range3.border_flag_.get_data()); ASSERT_EQ(string(range3.start_key_.ptr(), range3.start_key_.length()), string(range2.start_key_.ptr(), range2.start_key_.length())); ASSERT_EQ(string(range3.end_key_.ptr(), range3.end_key_.length()), string(range2.end_key_.ptr(), range2.end_key_.length())); const int times = 1000000; ObScanner os3; ObCellInfo cinull; cinull.table_name_.assign((char*)"hello", 5); cinull.value_.set_ext(ObActionFlag::OP_INSERT); ASSERT_EQ(OB_ERROR, os3.add_cell(cinull)); cinull.value_.set_ext(ObActionFlag::OP_DEL_ROW); ASSERT_EQ(OB_SUCCESS, os3.add_cell(cinull)); cinull.value_.set_ext(ObActionFlag::OP_ROW_DOES_NOT_EXIST); ASSERT_EQ(OB_SUCCESS, os3.add_cell(cinull)); int i = 0; for (; i < times; i++) { if (OB_SUCCESS != os3.add_cell(oci)) { break; } } const int64_t buf_len = 1 << 22; char* buff = (char*)ob_malloc(buf_len); int64_t ppos = 0; int64_t len = os3.get_serialize_size(); ASSERT_EQ(OB_BUF_NOT_ENOUGH, os3.serialize(buff, len - 4, ppos)); ASSERT_EQ(OB_SUCCESS, os3.serialize(buff, buf_len, ppos)); int64_t npos = 0; ObScanner os4; ASSERT_EQ(OB_ERROR, os4.deserialize(buff, 10, npos)); ASSERT_EQ(OB_SUCCESS, os4.deserialize(buff, ppos, npos)); ASSERT_EQ(npos, ppos); int64_t otmp; oci.value_.get_int(otmp); ObCellInfo *oo; int t = 0; ASSERT_EQ(OB_SUCCESS, os4.next_cell()); ASSERT_EQ(OB_SUCCESS, os4.get_cell(&oo)); ASSERT_EQ(0, oo->row_key_.length()); ASSERT_EQ(string(cinull.table_name_.ptr(), cinull.table_name_.length()), string(oo->table_name_.ptr(), oo->table_name_.length())); ASSERT_EQ(OB_SUCCESS, oo->value_.get_ext(tmp)); ASSERT_EQ(+ObActionFlag::OP_DEL_ROW, tmp); ASSERT_EQ(OB_SUCCESS, os4.next_cell()); ASSERT_EQ(OB_SUCCESS, os4.get_cell(&oo)); ASSERT_EQ(string(cinull.table_name_.ptr(), cinull.table_name_.length()), string(oo->table_name_.ptr(), oo->table_name_.length())); ASSERT_EQ(OB_SUCCESS, oo->value_.get_ext(tmp)); ASSERT_EQ(+ObActionFlag::OP_ROW_DOES_NOT_EXIST, tmp); while (OB_SUCCESS == os4.next_cell()) { ASSERT_EQ(OB_SUCCESS, os4.get_cell(&oo)); t++; ASSERT_EQ(string(oci.table_name_.ptr(), oci.table_name_.length()), string(oo->table_name_.ptr(), oo->table_name_.length())); ASSERT_EQ(string(oci.row_key_.ptr(), oci.row_key_.length()), string(oo->row_key_.ptr(), oo->row_key_.length())); ASSERT_EQ(string(oci.column_name_.ptr(), oci.column_name_.length()), string(oo->column_name_.ptr(), oo->column_name_.length())); ASSERT_EQ(OB_SUCCESS, oo->value_.get_int(tmp)); ASSERT_EQ(otmp, tmp); } ASSERT_EQ(t, i); ob_free(buff); } ObCellInfo st; st.table_name_.assign((char*)"table1", 6); st.row_key_.assign((char*)"row1", 4); st.column_name_.assign((char*)"column1", 7); st.value_.set_int(0xff); ObScanner ss; ss.add_cell(st); st.table_name_.assign((char*)"table2", 6); st.row_key_.assign((char*)"row1", 4); st.column_name_.assign((char*)"column1", 7); st.value_.set_int(0xff); ss.add_cell(st); ObCellInfo *sto; bool is_row_changed; ASSERT_EQ(OB_SUCCESS, ss.next_cell()); ASSERT_EQ(OB_SUCCESS, ss.get_cell(&sto, &is_row_changed)); ASSERT_EQ(true, is_row_changed); ASSERT_EQ(OB_SUCCESS, ss.next_cell()); ASSERT_EQ(OB_SUCCESS, ss.get_cell(&sto, &is_row_changed)); ASSERT_EQ(true, is_row_changed); ASSERT_EQ(OB_ITER_END, ss.next_cell()); }
TEST_F(TestGet, test_get_one_row) { int err = 0; CommonSchemaManagerWrapper schema_mgr; tbsys::CConfig config; bool ret_val = schema_mgr.parse_from_file("scan_schema.ini", config); ASSERT_TRUE(ret_val); ObUpsTableMgr& mgr = ObUpdateServerMain::get_instance()->get_update_server().get_table_mgr(); err = mgr.init(); ASSERT_EQ(0, err); err = mgr.set_schemas(schema_mgr); ASSERT_EQ(0, err); TestUpsTableMgrHelper test_helper(mgr); TableMgr& table_mgr = test_helper.get_table_mgr(); table_mgr.sstable_scan_finished(10); TableItem* active_memtable_item = table_mgr.get_active_memtable(); MemTable& active_memtable = active_memtable_item->get_memtable(); // construct multi-row mutator static const int64_t ROW_NUM = 1; static const int64_t COL_NUM = 10; ObCellInfo cell_infos[ROW_NUM][COL_NUM]; char row_key_strs[ROW_NUM][50]; uint64_t table_id = 10; // init cell infos for (int64_t i = 0; i < ROW_NUM; ++i) { sprintf(row_key_strs[i], "row_key_%08ld", i); for (int64_t j = 0; j < COL_NUM; ++j) { cell_infos[i][j].table_id_ = table_id; cell_infos[i][j].row_key_.assign(row_key_strs[i], strlen(row_key_strs[i])); cell_infos[i][j].column_id_ = j + 1; cell_infos[i][j].value_.set_int(1000 + i * COL_NUM + j); } } ObUpsMutator ups_mutator; ObMutator &mutator = ups_mutator.get_mutator(); // add cell to array for (int64_t i = 0; i < ROW_NUM; ++i) { for (int64_t j = 0; j < COL_NUM; ++j) { ObMutatorCellInfo mutator_cell; mutator_cell.cell_info = cell_infos[i][j]; mutator_cell.op_type.set_ext(ObActionFlag::OP_UPDATE); err = mutator.add_cell(mutator_cell); EXPECT_EQ(0, err); } } // write row to active memtable MemTableTransHandle write_handle; err = active_memtable.start_transaction(WRITE_TRANSACTION, write_handle); ASSERT_EQ(0, err); ups_mutator.set_mutate_timestamp(0); err = active_memtable.set(write_handle, ups_mutator); EXPECT_EQ(0, err); err = active_memtable.end_transaction(write_handle); ASSERT_EQ(0, err); /* ObString text; text.assign("/tmp", strlen("/tmp")); active_memtable.dump2text(text); */ for (int64_t i = 0; i < ROW_NUM; ++i) { ObScanner scanner; ObGetParam get_param; //get_param.set_timestamp(version); ObVersionRange version_range; //version_range.start_version_ = version; //version_range.end_version_ = version; version_range.start_version_ = 2; version_range.end_version_ = 2; version_range.border_flag_.set_inclusive_start(); version_range.border_flag_.set_inclusive_end(); get_param.set_version_range(version_range); for (int64_t j = 0; j < COL_NUM; ++j) { get_param.add_cell(cell_infos[i][j]); } int64_t count = 0; err = mgr.get(get_param, scanner, tbsys::CTimeUtil::getTime(), 2000000000 * 1000L * 1000L); EXPECT_EQ(0, err); // check result count = 0; while (OB_SUCCESS == scanner.next_cell()) { ObCellInfo* p_cell = NULL; scanner.get_cell(&p_cell); ASSERT_TRUE(p_cell != NULL); ObCellInfo expected = cell_infos[count / COL_NUM + i][count % COL_NUM]; check_cell(expected, *p_cell); ++count; } EXPECT_EQ(COL_NUM, count); } }
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; }
void scan_check_all(MutatorBuilder &mb, MockClient &client, const int64_t table_start_version, const bool using_id, const bool check) { for (int64_t i = 0; i < mb.get_schema_num(); ++i) { ObScanParam scan_param; prepare_scan_param(scan_param, mb.get_schema(i), table_start_version, using_id); int ret = OB_SUCCESS; bool is_fullfilled = false; int64_t fullfilled_item_num = 0; RowChecker rc; int64_t row_counter = 0; ObScanner scanner; while (!is_fullfilled && OB_SUCCESS == ret) { int64_t timeu = tbsys::CTimeUtil::getTime(); ret = client.ups_scan(scan_param, scanner, TIMEOUT_MS); TBSYS_LOG(INFO, "scan ret=%d timeu=%ld", ret, tbsys::CTimeUtil::getTime() - timeu); if (check && OB_SUCCESS == ret) { while (OB_SUCCESS == scanner.next_cell()) { ObCellInfo *ci = NULL; bool is_row_changed = false; if (OB_SUCCESS == scanner.get_cell(&ci, &is_row_changed)) { if (!using_id) { trans_name2id(*ci, mb.get_schema(i)); } if (is_row_changed && 0 != rc.cell_num()) { std::string row_key_str(rc.get_cur_rowkey().ptr(), 0, rc.get_cur_rowkey().length()); //fprintf(stderr, "[%.*s] ", rc.get_cur_rowkey().length(), rc.get_cur_rowkey().ptr()); bool get_row_bret = get_check_row(mb.get_schema(i), rc.get_cur_rowkey(), mb.get_cellinfo_builder(i), client, table_start_version, using_id); //fprintf(stderr, "[get_row check_ret=%d] ", bret); bool cell_info_bret = rc.check_row(mb.get_cellinfo_builder(i), mb.get_schema(i)); //fprintf(stderr, "[cell_info check_ret=%d]\n", bret); TBSYS_LOG(INFO, "[%s] [get_row check_ret=%d] [cell_info check_ret=%d]", row_key_str.c_str(), get_row_bret, cell_info_bret); } if (is_row_changed && 0 != rc.rowkey_num() && rc.is_prefix_changed(ci->row_key_)) { std::string row_key_str(rc.get_last_rowkey().ptr(), 0, rc.get_last_rowkey().length()); //fprintf(stderr, "[%.*s] ", rc.get_last_rowkey().length(), rc.get_last_rowkey().ptr()); bool bret = rc.check_rowkey(mb.get_rowkey_builder(i)); //fprintf(stderr, "row_key check_ret=%d\n", bret); TBSYS_LOG(INFO, "[%s] [row_key check_ret=%d]", row_key_str.c_str(), bret); } rc.add_cell(ci); if (is_row_changed) { rc.add_rowkey(ci->row_key_); row_counter++; } } } if (0 != rc.cell_num()) { std::string row_key_str(rc.get_cur_rowkey().ptr(), 0, rc.get_cur_rowkey().length()); //fprintf(stderr, "[%.*s] ", rc.get_cur_rowkey().length(), rc.get_cur_rowkey().ptr()); bool get_row_bret = get_check_row(mb.get_schema(i), rc.get_cur_rowkey(), mb.get_cellinfo_builder(i), client, table_start_version, using_id); //fprintf(stderr, "[get_row check_ret=%d] ", bret); bool cell_info_bret = rc.check_row(mb.get_cellinfo_builder(i), mb.get_schema(i)); //fprintf(stderr, "[cell_info check_ret=%d]\n", bret); TBSYS_LOG(INFO, "[%s] [get_row check_ret=%d] [cell_info check_ret=%d]", row_key_str.c_str(), get_row_bret, cell_info_bret); } } scanner.get_is_req_fullfilled(is_fullfilled, fullfilled_item_num); ObRange *range = const_cast<ObRange*>(scan_param.get_range()); scanner.get_last_row_key(range->start_key_); range->border_flag_.unset_min_value(); range->border_flag_.unset_inclusive_start(); } if (check && 0 != rc.rowkey_num()) { std::string row_key_str(rc.get_last_rowkey().ptr(), 0, rc.get_last_rowkey().length()); //fprintf(stderr, "[%.*s] ", rc.get_last_rowkey().length(), rc.get_last_rowkey().ptr()); bool bret = rc.check_rowkey(mb.get_rowkey_builder(i)); //fprintf(stderr, "row_key check_ret=%d\n", bret); TBSYS_LOG(INFO, "[%s] [row_key check_ret=%d]", row_key_str.c_str(), bret); } TBSYS_LOG(INFO, "table_id=%lu row_counter=%ld", mb.get_schema(i).get_table_id(), row_counter); } }
bool check_result(const ObScanParam &scan_param, ObScanner &ob_scanner, ObFinalResult & local_result) { int err = OB_SUCCESS; bool res = true; ObScanner local_scanner; ObCellInfo *ob_cell = NULL; ObCellInfo *local_cell = NULL; err = local_result.scan(scan_param,local_scanner); if (OB_SUCCESS != err) { TBSYS_LOG(WARN,"fail to scan local result"); } int64_t row_number = 0; bool ob_end = false; ObString rowkey; while (OB_SUCCESS == err) { for (int64_t scan_idx = 0; scan_idx < scan_param.get_column_name_size(); scan_idx ++) { if (OB_SUCCESS == err) { err = ob_scanner.next_cell(); } if (OB_ITER_END == err && scan_idx == 0) { ob_end = true; err = OB_SUCCESS; } else if (OB_SUCCESS == err) { err = ob_scanner.get_cell(&ob_cell); } if (OB_SUCCESS != err) { TBSYS_LOG(WARN,"fail to get cell from ob result [row_idx:%lld,idx:%lld]", row_number, scan_idx); } if (OB_SUCCESS == err) { err = local_scanner.next_cell(); if (ob_end && OB_ITER_END != err) { TBSYS_LOG(WARN,"local result return more cells than ob result"); err = OB_INVALID_ARGUMENT; } if ( !ob_end && OB_ITER_END == err) { TBSYS_LOG(WARN,"ob result return more cells than local result"); err = OB_INVALID_ARGUMENT; } if (ob_end && OB_ITER_END == err) { err = OB_ITER_END; break; } if (OB_SUCCESS == err) { err = local_scanner.get_cell(&local_cell); } if (OB_SUCCESS != err) { TBSYS_LOG(WARN,"fail to get cell from local result [row_idx:%lld,idx:%lld]", row_number, scan_idx); } } if (OB_SUCCESS == err) { if (0 == scan_idx) { rowkey = ob_cell->row_key_; } /// check ob result if (ob_cell->table_name_ != scan_param.get_table_name()) { TBSYS_LOG(WARN,"ob result table name error [row_idx:%lld,idx:%lld,ob.table_name_:%.*s," "param.table_name_:%.*s]", row_number, scan_idx,ob_cell->table_name_.length(), ob_cell->table_name_.ptr(), scan_param.get_table_name().length(), scan_param.get_table_name().ptr()); err = OB_INVALID_ARGUMENT; } if (ob_cell->column_name_ != scan_param.get_column_name()[scan_idx]) { TBSYS_LOG(WARN,"ob result rowkey error [row_idx:%lld,idx:%lld,ob.column_name_:%.*s," "param.column_name_:%.*s]", row_number, scan_idx,ob_cell->column_name_.length(), ob_cell->column_name_.ptr(), scan_param.get_column_name()[scan_idx].length(), scan_param.get_column_name()[scan_idx].ptr()); err = OB_INVALID_ARGUMENT; } /// check local result if (local_cell->table_name_ != scan_param.get_table_name()) { TBSYS_LOG(WARN,"ob result table name error [row_idx:%lld,idx:%lld,ob.table_name_:%.*s," "param.table_name_:%.*s]", row_number, scan_idx,local_cell->table_name_.length(), local_cell->table_name_.ptr(), scan_param.get_table_name().length(), scan_param.get_table_name().ptr()); err = OB_INVALID_ARGUMENT; } if (local_cell->column_name_ != scan_param.get_column_name()[scan_idx]) { TBSYS_LOG(WARN,"ob result rowkey error [row_idx:%lld,idx:%lld,ob.column_name_:%.*s," "param.column_name_:%.*s]", row_number,scan_idx,local_cell->column_name_.length(), local_cell->column_name_.ptr(), scan_param.get_column_name()[scan_idx].length(), scan_param.get_column_name()[scan_idx].ptr()); err = OB_INVALID_ARGUMENT; } if (local_cell->row_key_ != ob_cell->row_key_) { TBSYS_LOG(WARN,"rowkey error [row_idx:%lld,idx:%lld,ob.row_key_:%.*s," "local.row_key_:%.*s]", row_number, scan_idx,ob_cell->row_key_.length(), ob_cell->row_key_.ptr(), local_cell->row_key_.length(), local_cell->row_key_.ptr()); err = OB_INVALID_ARGUMENT; } if (local_cell->row_key_ != rowkey) { TBSYS_LOG(WARN,"rowkey error [row_idx:%lld,idx:%lld,ob.row_key_:%.*s," "row_first_cell.row_key_:%.*s]", row_number,scan_idx,local_cell->row_key_.length(), local_cell->row_key_.ptr(), rowkey.length(), rowkey.ptr()); err = OB_INVALID_ARGUMENT; } if (OB_SUCCESS == err) { if (ob_cell->value_.get_ext() != local_cell->value_.get_ext()) { TBSYS_LOG(WARN,"ext info not coincident [row_idx:%lld,idx:%lld," "ob.ext:%lld,local.ext:%lld]", row_number, scan_idx, ob_cell->value_.get_ext(), local_cell->value_.get_ext()); err = OB_INVALID_ARGUMENT; } if (ob_cell->value_.get_type() == ObNullType && ob_cell->value_.get_type() == local_cell->value_.get_type()) { /// check pass } else { int64_t ob_value = 0; int64_t local_value = 0; if (OB_SUCCESS == err) { err = ob_cell->value_.get_int(ob_value); } if (OB_SUCCESS == err) { err = local_cell->value_.get_int(local_value); } if (OB_SUCCESS != err) { TBSYS_LOG(WARN,"fail to get int value [row_idx:%lld,idx:%lld]",row_number, scan_idx); err = OB_INVALID_ARGUMENT; } else { if (ob_value != local_value) { TBSYS_LOG(WARN,"value not coincident [row_idx:%lld,idx:%lld,ob.value:%lld," "local.value:%lld]",row_number, scan_idx, ob_value, local_value); err = OB_INVALID_ARGUMENT; } } } } } } if (OB_ITER_END == err) { err = OB_SUCCESS; break; } row_number ++; } if (OB_SUCCESS != err) { res = false; TBSYS_LOG(DEBUG, "check fail"); } else { res = true; TBSYS_LOG(DEBUG, "check pass"); } return res; }
bool check_result(const ObGetParam &get_param, ObScanner &ob_scanner, ObFinalResult & local_result) { int err = OB_SUCCESS; bool res = true; ObScanner local_scanner; ObCellInfo *ob_cell = NULL; ObCellInfo *local_cell = NULL; err = local_result.get(get_param,local_scanner); if (OB_SUCCESS != err) { TBSYS_LOG(WARN,"fail to get local result"); } for (int64_t get_idx = 0; get_idx < get_param.get_cell_size() && OB_SUCCESS == err; get_idx ++) { int ob_err = ob_scanner.next_cell(); int local_err = local_scanner.next_cell(); if (OB_ITER_END == ob_err && OB_ITER_END == local_err) { err = OB_SUCCESS; break; } if (OB_SUCCESS != ob_err) { err = ob_err; TBSYS_LOG(WARN,"ob next cell err"); break; } if (OB_SUCCESS != local_err) { err = local_err; TBSYS_LOG(WARN,"local next cell err"); break; } if (OB_SUCCESS == err) { err = ob_scanner.get_cell(&ob_cell); } if (OB_SUCCESS != err) { TBSYS_LOG(WARN,"fail to get cell from ob result [idx:%lld]", get_idx); } if (OB_SUCCESS == err) { if (OB_SUCCESS == err) { err = local_scanner.get_cell(&local_cell); } if (OB_SUCCESS != err) { TBSYS_LOG(WARN,"fail to get cell from local result [idx:%lld]", get_idx); } } if (OB_SUCCESS == err) { /* /// check ob result if (ob_cell->table_name_ != get_param[get_idx]->table_name_) { TBSYS_LOG(WARN,"ob result table name error [idx:%lld,ob.table_name_:%.*s," "param.table_name_:%.*s]", get_idx,ob_cell->table_name_.length(), ob_cell->table_name_.ptr(), get_param[get_idx]->table_name_.length(), get_param[get_idx]->table_name_.ptr()); err = OB_INVALID_ARGUMENT; } if (ob_cell->row_key_ != get_param[get_idx]->row_key_) { TBSYS_LOG(WARN,"ob result rowkey error [idx:%lld,ob.row_key_:%.*s," "param.row_key_:%.*s]", get_idx,ob_cell->row_key_.length(), ob_cell->row_key_.ptr(), get_param[get_idx]->row_key_.length(), get_param[get_idx]->row_key_.ptr()); err = OB_INVALID_ARGUMENT; } if (ob_cell->column_name_ != get_param[get_idx]->column_name_) { TBSYS_LOG(WARN,"ob result column name error [idx:%lld,ob.column_name_:%.*s," "param.column_name_:%.*s]", get_idx,ob_cell->column_name_.length(), ob_cell->column_name_.ptr(), get_param[get_idx]->column_name_.length(), get_param[get_idx]->column_name_.ptr()); err = OB_INVALID_ARGUMENT; } /// check local result if (local_cell->table_name_ != get_param[get_idx]->table_name_) { TBSYS_LOG(WARN,"local result table name error [idx:%lld,ob.table_name_:%.*s," "param.table_name_:%.*s]", get_idx,local_cell->table_name_.length(), local_cell->table_name_.ptr(), get_param[get_idx]->table_name_.length(), get_param[get_idx]->table_name_.ptr()); err = OB_INVALID_ARGUMENT; } if (local_cell->row_key_ != get_param[get_idx]->row_key_) { TBSYS_LOG(WARN,"local result rowkey error [idx:%lld,local.row_key_:%.*s," "param.row_key_:%.*s]", get_idx,local_cell->row_key_.length(), local_cell->row_key_.ptr(), get_param[get_idx]->row_key_.length(), get_param[get_idx]->row_key_.ptr()); err = OB_INVALID_ARGUMENT; } if (local_cell->column_name_ != get_param[get_idx]->column_name_) { TBSYS_LOG(WARN,"local result column_name error [idx:%lld,local.column_name_:%.*s," "param.column_name_:%.*s]", get_idx,local_cell->column_name_.length(), local_cell->column_name_.ptr(), get_param[get_idx]->column_name_.length(), get_param[get_idx]->column_name_.ptr()); err = OB_INVALID_ARGUMENT; } */ TBSYS_LOG(DEBUG, "ob.table_name:%.*s,ob.rowkey:%.*s,ob.column_name:%.*s", ob_cell->table_name_.length(),ob_cell->table_name_.ptr(), ob_cell->row_key_.length(),ob_cell->row_key_.ptr(), ob_cell->column_name_.length(),ob_cell->column_name_.ptr() ); TBSYS_LOG(DEBUG, "local.table_name:%.*s,local.rowkey:%.*s,local.column_name:%.*s", local_cell->table_name_.length(),local_cell->table_name_.ptr(), local_cell->row_key_.length(),local_cell->row_key_.ptr(), local_cell->column_name_.length(),local_cell->column_name_.ptr() ); if (local_cell->table_name_ != ob_cell->table_name_) { TBSYS_LOG(WARN,"table name not coincident [idx:%lld,ob.table_name_:%.*s," "local.table_name_:%.*s]", get_idx,ob_cell->table_name_.length(), ob_cell->table_name_.ptr(), local_cell->table_name_.length(), local_cell->table_name_.ptr()); err = OB_INVALID_ARGUMENT; } if (local_cell->row_key_ != ob_cell->row_key_) { TBSYS_LOG(WARN,"rowkey not coincident [idx:%lld,ob.row_key_:%.*s," "local.row_key_:%.*s]", get_idx,ob_cell->row_key_.length(), ob_cell->row_key_.ptr(), local_cell->row_key_.length(), local_cell->row_key_.ptr()); err = OB_INVALID_ARGUMENT; } if (local_cell->column_name_ != ob_cell->column_name_) { TBSYS_LOG(WARN,"column name not coincident [idx:%lld,ob.column_name_:%.*s," "local.column_name_:%.*s]", get_idx,ob_cell->column_name_.length(), ob_cell->column_name_.ptr(), local_cell->column_name_.length(), local_cell->column_name_.ptr()); err = OB_INVALID_ARGUMENT; } if (OB_SUCCESS == err) { if (ob_cell->value_.get_ext() != local_cell->value_.get_ext()) { TBSYS_LOG(WARN,"ext info not coincident [idx:%lld,ob.ext:%lld,local.ext:%lld]", get_idx, ob_cell->value_.get_ext(), local_cell->value_.get_ext()); err = OB_INVALID_ARGUMENT; } if (OB_SUCCESS == err && ObExtendType != ob_cell->value_.get_type()) { int64_t ob_value; int64_t local_value; if (ob_cell->value_.get_ext() != local_cell->value_.get_ext()) { TBSYS_LOG(WARN,"ext not coincident [idx:%lld,ob.ext:%lld," "local.ext:%lld]",get_idx, ob_cell->value_.get_ext(), local_cell->value_.get_ext()); err = OB_INVALID_ARGUMENT; } if (ob_cell->value_.get_ext() == 0 && OB_SUCCESS == err) { if (ob_cell->value_.get_type() == ObNullType && ob_cell->value_.get_type() == local_cell->value_.get_type()) { /// check pass } else { if (OB_SUCCESS == err) { err = local_cell->value_.get_int(local_value); if (OB_SUCCESS != err) { TBSYS_LOG(WARN,"fail to get int from local, ext:%lld,type:%d", local_cell->value_.get_ext(),local_cell->value_.get_type()); } else { TBSYS_LOG(DEBUG, "local value:%lld", local_value); } } if (OB_SUCCESS == err) { err = ob_cell->value_.get_int(ob_value); if (OB_SUCCESS != err) { TBSYS_LOG(WARN,"fail to get int from ob, ext:%lld,type:%d", ob_cell->value_.get_ext(),ob_cell->value_.get_type()); } else { TBSYS_LOG(DEBUG, "ob value:%lld", ob_value); } } if (OB_SUCCESS != err) { TBSYS_LOG(WARN,"fail to get int value [idx:%lld]", get_idx); err = OB_INVALID_ARGUMENT; } else { if (ob_value != local_value) { TBSYS_LOG(WARN,"value not coincident [idx:%lld,ob.value:%lld," "local.value:%lld]",get_idx, ob_value, local_value); err = OB_INVALID_ARGUMENT; } } } } } } } } if (OB_SUCCESS == err && ob_scanner.next_cell() != OB_ITER_END) { TBSYS_LOG(WARN,"ob return more result than expected"); } if (OB_SUCCESS == err && local_scanner.next_cell() != OB_ITER_END) { TBSYS_LOG(WARN,"local return more result than expected"); } if (OB_SUCCESS != err) { res = false; TBSYS_LOG(DEBUG, "check fail"); } else { res = true; TBSYS_LOG(DEBUG, "check pass"); } return res; }
bool GetSingleRowAllColumn::check_result(const uint32_t min_key_include, const uint32_t max_key_include, ObScanner &result, void *arg) { bool res = true; int err = OB_SUCCESS; UNUSED(min_key_include); UNUSED(max_key_include); ObGetParam *get_param = reinterpret_cast<ObGetParam*>(arg); uint32_t big_endian_rowkey_val = *(uint32_t*)(((*get_param)[0])->row_key_.ptr()); uint32_t rowkey_val = ntohl(big_endian_rowkey_val); ObCellInfo target_cell; target_cell.row_key_.assign((char*)&big_endian_rowkey_val, sizeof(big_endian_rowkey_val)); target_cell.table_name_ = msolap::target_table_name; if (result.get_cell_num() != msolap::max_column_id - msolap::min_column_id + 1) { TBSYS_LOG(WARN,"result cell number error [got:%ld,expcted:%ld]", result.get_cell_num(), msolap::max_column_id - msolap::min_column_id + 1); err = OB_ERR_UNEXPECTED; } int64_t got_cell_num = 0; ObCellInfo *cur_cell = NULL; int64_t intval = 0; for (got_cell_num = 0; (got_cell_num < result.get_cell_num()) && (OB_SUCCESS == err); got_cell_num++) { if (OB_SUCCESS != (err = result.next_cell())) { TBSYS_LOG(WARN,"fail to get next cell from result [err:%d]", err); } if ((OB_SUCCESS == err) && (OB_SUCCESS != (err = result.get_cell(&cur_cell)))) { TBSYS_LOG(WARN,"fail to get next cell from result [err:%d]", err); } if ((OB_SUCCESS == err) && ((cur_cell->table_name_ != msolap::target_table_name) || (cur_cell->row_key_ != target_cell.row_key_) || (cur_cell->column_name_.length() != 1) || (OB_SUCCESS != cur_cell->value_.get_int(intval)))) { TBSYS_LOG(WARN,"cell content error"); err = OB_ERR_UNEXPECTED; } if ((OB_SUCCESS == err) && ((cur_cell->column_name_.ptr()[0] < 'a') || (cur_cell->column_name_.ptr()[0] > 'z'))) { TBSYS_LOG(WARN,"cell content error"); err = OB_ERR_UNEXPECTED; } if (OB_SUCCESS == err) { int64_t expect_intval = 0; char c_name = cur_cell->column_name_.ptr()[0]; switch (c_name) { case 'a': case 'b': case 'c': case 'd': expect_intval = ((unsigned char*)&big_endian_rowkey_val)[c_name - 'a']; break; default: expect_intval = rowkey_val; } if (expect_intval != intval) { TBSYS_LOG(WARN,"intvalue error [column_name:%c,expect_val:%ld,got_val:%ld,rowkey:%u]", c_name, expect_intval, intval, rowkey_val); err = OB_ERR_UNEXPECTED; } } } if ((OB_SUCCESS == err) && (got_cell_num != msolap::max_column_id - msolap::min_column_id + 1)) { TBSYS_LOG(WARN,"fail to get enough cells from result"); err = OB_ERR_UNEXPECTED; } if ((OB_SUCCESS == err) && (OB_ITER_END != result.next_cell())) { TBSYS_LOG(WARN,"fail to get enough cells from result"); err = OB_ERR_UNEXPECTED; } if (OB_SUCCESS != err) { res = false; } return res; }