cache data version in session for performance optimize

This commit is contained in:
felix-w15
2024-02-27 09:44:46 +00:00
committed by ob-robot
parent 86e6b53016
commit fd54ded76c
16 changed files with 90 additions and 46 deletions

View File

@ -106,7 +106,7 @@ int ObTMService::tm_rm_start(ObExecContext &exec_ctx,
tx_param.timeout_us_ = tx_timeout;
tx_param.lock_timeout_us_ = my_session->get_trx_lock_timeout();
if (OB_FAIL(xa_service->xa_start_for_tm(0, timeout_seconds, my_session->get_sessid(),
tx_param, tx_desc, xid))) {
tx_param, tx_desc, xid, my_session->get_data_version()))) {
LOG_WARN("xa start for dblink failed", K(ret), K(tx_param));
// TODO, reset
my_session->reset_first_need_txn_stmt_type();

View File

@ -99,7 +99,8 @@ int ObPlXaStartExecutor::execute(ObExecContext &ctx, ObXaStartStmt &stmt)
my_session->get_xa_end_timeout_seconds(),
my_session->get_sessid(),
tx_param,
tx_desc))) {
tx_desc,
my_session->get_data_version()))) {
LOG_WARN("xa start failed", K(ret), K(tx_param));
my_session->reset_tx_variable();
my_session->set_early_lock_release(false);

View File

@ -171,7 +171,7 @@ int ObSqlTransControl::explicit_start_trans(ObExecContext &ctx, const bool read_
ObTxParam &tx_param = plan_ctx->get_trans_param();
OZ (build_tx_param_(session, tx_param, &read_only));
OZ (txs->acquire_tx(session->get_tx_desc(), session->get_sessid()));
OZ (txs->acquire_tx(session->get_tx_desc(), session->get_sessid(), session->get_data_version()));
OZ (txs->start_tx(*session->get_tx_desc(), tx_param), tx_param);
OX (tx_id = session->get_tx_desc()->get_tx_id());
@ -1220,7 +1220,10 @@ int ObSqlTransControl::get_trans_result(ObExecContext &exec_ctx)
return get_trans_result(exec_ctx, exec_ctx.get_my_session()->get_trans_result());
}
int ObSqlTransControl::reset_session_tx_state(ObBasicSessionInfo *session, bool reuse_tx_desc, bool reset_trans_variable)
int ObSqlTransControl::reset_session_tx_state(ObBasicSessionInfo *session,
bool reuse_tx_desc,
bool reset_trans_variable,
const uint64_t data_version)
{
int ret = OB_SUCCESS;
LOG_DEBUG("reset session tx state", KPC(session->get_tx_desc()), K(lbt()));
@ -1233,7 +1236,7 @@ int ObSqlTransControl::reset_session_tx_state(ObBasicSessionInfo *session, bool
transaction::ObTransService *txs = NULL;
OZ (get_tx_service(session, txs), *session, tx_desc);
if (reuse_tx_desc) {
if (OB_FAIL(txs->reuse_tx(tx_desc))) {
if (OB_FAIL(txs->reuse_tx(tx_desc, data_version))) {
LOG_ERROR("reuse txn descriptor fail, will release it", K(ret), KPC(session), K(tx_desc));
OZ (txs->release_tx(tx_desc), tx_id);
session->get_tx_desc() = NULL;
@ -1262,7 +1265,8 @@ int ObSqlTransControl::reset_session_tx_state(ObSQLSessionInfo *session, bool re
LOG_WARN_RET(temp_ret, "trx level temporary table clean failed", KR(temp_ret));
}
}
int ret = reset_session_tx_state(static_cast<ObBasicSessionInfo*>(session), reuse_tx_desc, reset_trans_variable);
int ret = reset_session_tx_state(static_cast<ObBasicSessionInfo*>(session), reuse_tx_desc,
reset_trans_variable, session->get_data_version());
return COVER_SUCC(temp_ret);
}
@ -1291,7 +1295,7 @@ int ObSqlTransControl::acquire_tx_if_need_(transaction::ObTransService *txs, ObS
{
int ret = OB_SUCCESS;
if (OB_ISNULL(session.get_tx_desc())) {
OZ (txs->acquire_tx(session.get_tx_desc(), session.get_sessid()), session);
OZ (txs->acquire_tx(session.get_tx_desc(), session.get_sessid(), session.get_data_version()), session);
}
return ret;
}
@ -1313,7 +1317,7 @@ int ObSqlTransControl::lock_table(ObExecContext &exec_ctx,
OZ (get_tx_service(session, txs));
OZ (get_lock_service(session->get_effective_tenant_id(), lock_service));
if (OB_SUCC(ret) && OB_ISNULL(session->get_tx_desc())) {
OZ (txs->acquire_tx(session->get_tx_desc(), session->get_sessid()), *session);
OZ (txs->acquire_tx(session->get_tx_desc(), session->get_sessid(), session->get_data_version()), *session);
}
ObTxParam tx_param;
OZ (build_tx_param_(session, tx_param));
@ -1442,7 +1446,7 @@ int ObSqlTransControl::check_ls_readable(const uint64_t tenant_id,
bool has_tx_desc = OB_NOT_NULL(tx_desc); \
transaction::ObTransID prev_tx_id; \
if (has_tx_desc) { prev_tx_id = session.get_tx_id(); } \
OZ (txs->txn_free_route__update_##name##_state(session.get_sessid(), tx_desc, session.get_txn_free_route_ctx(), buf, len, pos), session); \
OZ (txs->txn_free_route__update_##name##_state(session.get_sessid(), tx_desc, session.get_txn_free_route_ctx(), buf, len, pos, session.get_data_version()), session); \
if (OB_SUCC(ret) && has_tx_desc && (OB_ISNULL(tx_desc) || tx_desc->get_tx_id() != prev_tx_id)) { \
session.reset_tx_variable(); \
} \

View File

@ -168,7 +168,10 @@ class ObSqlTransControl
{
public:
static int reset_session_tx_state(ObSQLSessionInfo *session, bool reuse_tx_desc = false, bool active_tx_end = true);
static int reset_session_tx_state(ObBasicSessionInfo *session, bool reuse_tx_desc = false, bool active_tx_end = true);
static int reset_session_tx_state(ObBasicSessionInfo *session,
bool reuse_tx_desc = false,
bool active_tx_end = true,
const uint64_t data_version = 0);
static int create_stash_savepoint(ObExecContext &exec_ctx, const ObString &name);
static int release_stash_savepoint(ObExecContext &exec_ctx, const ObString &name);
static int explicit_start_trans(ObExecContext &exec_ctx, const bool read_only, const ObString hint = ObString());

View File

@ -2791,6 +2791,13 @@ void ObSQLSessionInfo::ObCachedTenantConfigInfo::refresh()
LOG_DEBUG("refresh tenant config where tenant changed",
K_(saved_tenant_info), K(effective_tenant_id));
ATOMIC_STORE(&saved_tenant_info_, effective_tenant_id);
}
// 缓存data version 用于性能优化
uint64_t data_version = 0;
if (OB_TMP_FAIL(GET_MIN_DATA_VERSION(effective_tenant_id, data_version))) {
LOG_WARN_RET(tmp_ret, "get data version fail", "ret", tmp_ret, K(effective_tenant_id));
} else {
ATOMIC_STORE(&data_version_, data_version);
}
// 1.是否支持外部一致性
is_external_consistent_ = transaction::ObTsMgr::get_instance().is_external_consistent(effective_tenant_id);

View File

@ -689,6 +689,7 @@ public:
at_type_(ObAuditTrailType::NONE),
sort_area_size_(128*1024*1024),
hash_area_size_(128*1024*1024),
data_version_(0),
enable_query_response_time_stats_(false),
enable_user_defined_rewrite_rules_(false),
range_optimizer_max_mem_size_(128*1024*1024),
@ -708,6 +709,7 @@ public:
ObAuditTrailType get_at_type() const { return at_type_; }
int64_t get_sort_area_size() const { return ATOMIC_LOAD(&sort_area_size_); }
int64_t get_hash_area_size() const { return ATOMIC_LOAD(&hash_area_size_); }
uint64_t get_data_version() const { return ATOMIC_LOAD(&data_version_); }
bool enable_query_response_time_stats() const { return enable_query_response_time_stats_; }
bool enable_udr() const { return ATOMIC_LOAD(&enable_user_defined_rewrite_rules_); }
int64_t get_print_sample_ppm() const { return ATOMIC_LOAD(&print_sample_ppm_); }
@ -728,6 +730,7 @@ public:
ObAuditTrailType at_type_;
int64_t sort_area_size_;
int64_t hash_area_size_;
uint64_t data_version_;
bool enable_query_response_time_stats_;
bool enable_user_defined_rewrite_rules_;
int64_t range_optimizer_max_mem_size_;
@ -1280,6 +1283,11 @@ public:
cached_tenant_config_info_.refresh();
return cached_tenant_config_info_.get_sort_area_size();
}
uint64_t get_data_version()
{
cached_tenant_config_info_.refresh();
return cached_tenant_config_info_.get_data_version();
}
bool enable_query_response_time_stats()
{
cached_tenant_config_info_.refresh();