[4.0] dec unsubmitted cnt that is added in prepare of multi-transaction for replay when transaction abort

This commit is contained in:
obdev
2022-11-03 10:07:55 +00:00
committed by wangzelin.wzl
parent 68f54889e2
commit 6dba6ed96f
4 changed files with 31 additions and 11 deletions

View File

@ -620,7 +620,7 @@ int ObTablet::set_multi_data_for_commit(
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
bool is_callback = true; bool is_callback = true;
TRANS_LOG(INFO, "set_multi_data_for_commit", K(multi_source_data_unit)); TRANS_LOG(INFO, "set_multi_data_for_commit", K(multi_source_data_unit), K(ref_op));
if (IS_NOT_INIT) { if (IS_NOT_INIT) {
ret = OB_NOT_INIT; ret = OB_NOT_INIT;
TRANS_LOG(WARN, "not inited", K(ret), K_(is_inited)); TRANS_LOG(WARN, "not inited", K(ret), K_(is_inited));

View File

@ -1003,6 +1003,21 @@ int ObTabletBindingHelper::set_log_ts(const ObIArray<ObTabletID> &tablet_ids) co
return ret; return ret;
} }
int ObTabletBindingHelper::check_need_dec_cnt_for_abort(const ObTabletTxMultiSourceDataUnit &tx_data, bool &need_dec)
{
int ret = OB_SUCCESS;
const int cnt = tx_data.get_unsync_cnt_for_multi_data();
need_dec = false;
if ((tx_data.is_tx_end() && cnt == 2) || (!tx_data.is_tx_end() && cnt == 1)) {
need_dec = true;
} else if ((tx_data.is_tx_end() && cnt == 1) || (!tx_data.is_tx_end() && cnt == 0)) {
} else {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("invalid cnt", K(ret), K(tx_data));
}
return ret;
}
/// for commit or abort, reentrant for replay /// for commit or abort, reentrant for replay
int ObTabletBindingHelper::unlock_tablet_binding(ObTabletHandle &handle, const ObMulSourceDataNotifyArg &trans_flags) int ObTabletBindingHelper::unlock_tablet_binding(ObTabletHandle &handle, const ObMulSourceDataNotifyArg &trans_flags)
{ {
@ -1034,8 +1049,12 @@ int ObTabletBindingHelper::unlock_tablet_binding(ObTabletHandle &handle, const O
tx_data.tx_id_ = ObTabletCommon::FINAL_TX_ID; tx_data.tx_id_ = ObTabletCommon::FINAL_TX_ID;
tx_data.tx_log_ts_ = abort_without_redo ? old_log_ts : log_ts; tx_data.tx_log_ts_ = abort_without_redo ? old_log_ts : log_ts;
const int64_t memtable_log_ts = (OB_INVALID_TIMESTAMP == log_ts) ? ObLogTsRange::MAX_TS: log_ts; const int64_t memtable_log_ts = (OB_INVALID_TIMESTAMP == log_ts) ? ObLogTsRange::MAX_TS: log_ts;
MemtableRefOp ref_op = (abort_without_redo ? MemtableRefOp::DEC_REF : MemtableRefOp::NONE); bool need_dec = false;
if (OB_FAIL(tablet->set_tablet_final_status(tx_data, memtable_log_ts, for_replay, ref_op))) { MemtableRefOp ref_op = MemtableRefOp::NONE;
if (OB_FAIL(check_need_dec_cnt_for_abort(tx_data, need_dec))) {
LOG_WARN("failed to save tx data", K(ret), K(tx_data), K(log_ts), K(for_replay));
} else if (FALSE_IT(ref_op = (need_dec ? MemtableRefOp::DEC_REF : MemtableRefOp::NONE))) {
} else if (OB_FAIL(tablet->set_tablet_final_status(tx_data, memtable_log_ts, for_replay, ref_op))) {
LOG_WARN("failed to save tx data", K(ret), K(tx_data), K(log_ts), K(for_replay), K(ref_op)); LOG_WARN("failed to save tx data", K(ret), K(tx_data), K(log_ts), K(for_replay), K(ref_op));
} }
} }

View File

@ -155,6 +155,7 @@ public:
// common // common
static bool has_lob_tablets(const obrpc::ObBatchCreateTabletArg &arg, const obrpc::ObCreateTabletInfo &info); static bool has_lob_tablets(const obrpc::ObBatchCreateTabletArg &arg, const obrpc::ObCreateTabletInfo &info);
static int check_need_dec_cnt_for_abort(const ObTabletTxMultiSourceDataUnit &tx_data, bool &need_dec);
static int lock_and_set_tx_data(ObTabletHandle &handle, ObTabletTxMultiSourceDataUnit &tx_data, const bool for_replay); static int lock_and_set_tx_data(ObTabletHandle &handle, ObTabletTxMultiSourceDataUnit &tx_data, const bool for_replay);
static int lock_tablet_binding(ObTabletHandle &handle, const transaction::ObMulSourceDataNotifyArg &trans_flags); static int lock_tablet_binding(ObTabletHandle &handle, const transaction::ObMulSourceDataNotifyArg &trans_flags);
static int set_log_ts(ObTabletHandle &handle, const transaction::ObMulSourceDataNotifyArg &trans_flags); static int set_log_ts(ObTabletHandle &handle, const transaction::ObMulSourceDataNotifyArg &trans_flags);

View File

@ -849,12 +849,11 @@ int ObTabletCreateDeleteHelper::roll_back_remove_tablet(
} else { } else {
LOG_WARN("failed to get tablet", K(ret), K(ls_id), K(tablet_id)); LOG_WARN("failed to get tablet", K(ret), K(ls_id), K(tablet_id));
} }
} else if (trans_flags.for_replay_) {
// for replay, no need to dec ref for memtable
} else { } else {
ObTablet *tablet = tablet_handle.get_obj(); ObTablet *tablet = tablet_handle.get_obj();
ObTabletMemtableMgr *memtable_mgr = static_cast<ObTabletMemtableMgr*>(tablet->get_memtable_mgr()); ObTabletMemtableMgr *memtable_mgr = static_cast<ObTabletMemtableMgr*>(tablet->get_memtable_mgr());
ObSEArray<ObTableHandleV2, MAX_MEMSTORE_CNT> memtable_handle_array; ObSEArray<ObTableHandleV2, MAX_MEMSTORE_CNT> memtable_handle_array;
bool need_dec = false;
if (OB_FAIL(memtable_mgr->get_all_memtables(memtable_handle_array))) { if (OB_FAIL(memtable_mgr->get_all_memtables(memtable_handle_array))) {
LOG_WARN("failed to get all memtables", K(ret), K(ls_id), K(tablet_id)); LOG_WARN("failed to get all memtables", K(ret), K(ls_id), K(tablet_id));
} else if (memtable_handle_array.empty()) { } else if (memtable_handle_array.empty()) {
@ -874,7 +873,9 @@ int ObTabletCreateDeleteHelper::roll_back_remove_tablet(
LOG_INFO("last memtable does not have msd, do nothing", K(ret), K(ls_id), K(tablet_id), K(cnt)); LOG_INFO("last memtable does not have msd, do nothing", K(ret), K(ls_id), K(tablet_id), K(cnt));
} else if (OB_FAIL(tablet->get_tx_data(tx_data))) { } else if (OB_FAIL(tablet->get_tx_data(tx_data))) {
LOG_WARN("failed to get tx data", K(ret), K(ls_id), K(tablet_id), K(cnt)); LOG_WARN("failed to get tx data", K(ret), K(ls_id), K(tablet_id), K(cnt));
} else if (OB_FAIL(tablet->save_multi_source_data_unit(&tx_data, ObLogTsRange::MAX_TS, } else if (OB_FAIL(ObTabletBindingHelper::check_need_dec_cnt_for_abort(tx_data, need_dec))) {
LOG_WARN("failed to save tx data", K(ret), K(tx_data), K(trans_flags));
} else if (need_dec && OB_FAIL(tablet->save_multi_source_data_unit(&tx_data, ObLogTsRange::MAX_TS,
trans_flags.for_replay_, MemtableRefOp::DEC_REF, true/*is_callback*/))) { trans_flags.for_replay_, MemtableRefOp::DEC_REF, true/*is_callback*/))) {
LOG_WARN("failed to save msd", K(ret), K(ls_id), K(tablet_id), K(cnt)); LOG_WARN("failed to save msd", K(ret), K(ls_id), K(tablet_id), K(cnt));
} else { } else {
@ -1255,11 +1256,10 @@ int ObTabletCreateDeleteHelper::do_abort_remove_tablet(
is_valid = false; is_valid = false;
LOG_INFO("tablet status is not DELETING", K(ret), K(key), K(trans_flags), K(tx_data)); LOG_INFO("tablet status is not DELETING", K(ret), K(key), K(trans_flags), K(tx_data));
} else { } else {
if (trans_flags.for_replay_) { bool need_dec = false;
} else if (trans_flags.is_redo_synced()) { if (OB_FAIL(ObTabletBindingHelper::check_need_dec_cnt_for_abort(tx_data, need_dec))) {
// on redo cb has been called LOG_WARN("failed to save tx data", K(ret), K(tx_data), K(trans_flags));
// do nothing(on redo cb has already done DEC_REF) } else if (need_dec) {
} else {
ref_op = MemtableRefOp::DEC_REF; ref_op = MemtableRefOp::DEC_REF;
} }
} }