[CP] [OBKV] Fix TTL status wrong when leader switch and hbase TTL MaxVersions delete

This commit is contained in:
shenyunlong.syl
2023-12-22 11:18:08 +00:00
committed by ob-robot
parent 8c4838638d
commit 043cf555ed
14 changed files with 252 additions and 115 deletions

View File

@ -19,6 +19,7 @@
#include "observer/table/ob_table_query_common.h"
#include "observer/table/ob_table_query_and_mutate_processor.h"
#include "lib/utility/utility.h"
#include "share/table/ob_table_util.h"
using namespace oceanbase::sql;
using namespace oceanbase::transaction;
@ -28,7 +29,6 @@ using namespace oceanbase::share;
using namespace oceanbase::table;
using namespace oceanbase::rootserver;
const ObString ObTableTTLDeleteTask::TTL_TRACE_INFO = ObString::make_string("TTL Delete");
/**
* ---------------------------------------- ObTableTTLDeleteTask ----------------------------------------
@ -41,6 +41,7 @@ ObTableTTLDeleteTask::ObTableTTLDeleteTask():
allocator_(ObMemAttr(MTL_ID(), "TTLDelTaskCtx")),
rowkey_(),
ttl_tablet_mgr_(NULL),
hbase_cur_version_(0),
rowkey_allocator_(ObMemAttr(MTL_ID(), "TTLDelTaskRKey"))
{
}
@ -163,7 +164,8 @@ int ObTableTTLDeleteTask::process_one()
info_.table_id_,
param_,
PER_TASK_DEL_ROWS,
rowkey_);
rowkey_,
hbase_cur_version_);
SMART_VAR(ObTableCtx, scan_ctx, allocator_) {
if (OB_FAIL(init_scan_tb_ctx(scan_ctx, cache_guard))) {
LOG_WARN("fail to init tb ctx", KR(ret));
@ -210,7 +212,7 @@ int ObTableTTLDeleteTask::process_one()
if (trans_state.is_start_trans_executed() && trans_state.is_start_trans_success()) {
int tmp_ret = ret;
if (OB_FAIL(ObTableApiProcessorBase::sync_end_trans_(OB_SUCCESS != ret, trans_desc, get_timeout_ts(),
nullptr, &TTL_TRACE_INFO))) {
nullptr, &ObTableUtils::get_kv_ttl_trace_info()))) {
LOG_WARN("fail to end trans", KR(ret));
}
ret = (OB_SUCCESS == tmp_ret) ? ret : tmp_ret;
@ -503,6 +505,7 @@ int ObTableTTLDeleteRowIterator::init(const schema::ObTableSchema &table_schema,
ObObj *obj_ptr = const_cast<ObObj *>(ttl_operation.start_rowkey_.get_obj_ptr());
cur_rowkey_ = obj_ptr[ObHTableConstants::COL_IDX_K].get_string();
cur_qualifier_ = obj_ptr[ObHTableConstants::COL_IDX_Q].get_string();
cur_version_ = ttl_operation.hbase_cur_version_;
is_inited_ = true;
}
}
@ -672,6 +675,7 @@ int ObTableTTLDeleteTask::execute_ttl_delete(ObTableTTLDeleteRowIterator &ttl_ro
if (OB_SUCC(ret)) {
rowkey_.assign(rowkey_buf, rowkey_cnt);
hbase_cur_version_ = ttl_row_iter.cur_version_;
}
}
}
@ -679,13 +683,36 @@ int ObTableTTLDeleteTask::execute_ttl_delete(ObTableTTLDeleteRowIterator &ttl_ro
if (OB_SUCC(ret) && rowkey_.is_valid()) {
// if ITER_END in ttl_row_iter, rowkey_ will not be assigned by last_row_ in this round
uint64_t buf_len = rowkey_.get_serialize_size();
char *buf = static_cast<char *>(allocator_.alloc(buf_len));
int64_t pos = 0;
if (OB_FAIL(rowkey_.serialize(buf, buf_len, pos))) {
LOG_WARN("fail to serialize", K(ret), K(buf_len), K(pos), K_(rowkey));
} else {
result.end_rowkey_.assign_ptr(buf, buf_len);
ObRowkey saved_rowkey = rowkey_;
if (param_.is_htable_) {
// for hbase table, only k,q is saved, set t to min, cuz we do not remember version in sys table
const int hbase_rowkey_size = 3;
ObObj *hbase_rowkey_objs = nullptr;
if (rowkey_.get_obj_cnt() < hbase_rowkey_size) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument", KR(ret), K_(rowkey));
} else if (OB_ISNULL(hbase_rowkey_objs =
static_cast<ObObj*>(allocator_.alloc(sizeof(ObObj) * hbase_rowkey_size)))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("fail to alloc", K(ret), K(hbase_rowkey_size));
} else {
ObObj *raw_obj_ptr = const_cast<ObObj *>(rowkey_.get_obj_ptr());
hbase_rowkey_objs[ObHTableConstants::COL_IDX_K] = raw_obj_ptr[ObHTableConstants::COL_IDX_K];
hbase_rowkey_objs[ObHTableConstants::COL_IDX_Q] = raw_obj_ptr[ObHTableConstants::COL_IDX_Q];
hbase_rowkey_objs[ObHTableConstants::COL_IDX_T].set_min_value();
saved_rowkey.assign(hbase_rowkey_objs, hbase_rowkey_size);
}
}
if (OB_SUCC(ret)) {
uint64_t buf_len = saved_rowkey.get_serialize_size();
char *buf = static_cast<char *>(allocator_.alloc(buf_len));
int64_t pos = 0;
if (OB_FAIL(saved_rowkey.serialize(buf, buf_len, pos))) {
LOG_WARN("fail to serialize", K(ret), K(buf_len), K(pos), K_(rowkey));
} else {
result.end_rowkey_.assign_ptr(buf, buf_len);
}
}
}
}