From 04204295ad0d115e89f938dca0526208fae3bc05 Mon Sep 17 00:00:00 2001 From: cr0 Date: Thu, 16 Sep 2021 16:32:05 +0800 Subject: [PATCH] fix active_trx_count leak when add memtable fail --- src/storage/memtable/ob_memtable_context.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/storage/memtable/ob_memtable_context.cpp b/src/storage/memtable/ob_memtable_context.cpp index 5839028ae1..4b63f8bec4 100644 --- a/src/storage/memtable/ob_memtable_context.cpp +++ b/src/storage/memtable/ob_memtable_context.cpp @@ -260,17 +260,20 @@ int ObMemtableCtx::set_host_(ObMemtable* host, const bool for_replay) ret = OB_NOT_MASTER; } else if (host == get_active_mt()) { // do nothing + } else if (memtable_arr_wrap_.is_contain_this_memtable(host)) { + ret = OB_ERR_UNEXPECTED; + TRANS_LOG(ERROR, "memstore already exist", K(ret), K(*this), KP(host)); } else if (memtable_arr_wrap_.is_reach_max_memtable_cnt()) { ret = OB_ERR_UNEXPECTED; TRANS_LOG(ERROR, "reach max memstore in storage", K(ret), K(*this), KP(host)); - } else { - if (memtable_arr_wrap_.is_contain_this_memtable(host)) { - ret = OB_ERR_UNEXPECTED; - TRANS_LOG(ERROR, "memstore already exist", K(ret), K(*this), KP(host)); - } else if (OB_FAIL(host->inc_active_trx_count())) { - TRANS_LOG(ERROR, "increase active_trx_count error", K(ret), K(*this), KP(host)); + } else if (OB_FAIL(host->inc_active_trx_count())) { + TRANS_LOG(ERROR, "increase active_trx_count error", K(ret), K(*this), KP(host)); + } else if (OB_FAIL(memtable_arr_wrap_.add_memtable(host))) { + int tmp_ret = OB_SUCCESS; + if (OB_SUCCESS != (tmp_ret = host->dec_active_trx_count())) { + TRANS_LOG(ERROR, "decrease active_trx_count error when add memtable fail", K(tmp_ret), K(ret), K(*this), KP(host)); } else { - memtable_arr_wrap_.add_memtable(host); + TRANS_LOG(WARN, "decrease active_trx_count success when add memtable fail", K(ret), K(*this), KP(host)); } } return ret; -- GitLab