[CP] Add defensive check code for inner table and weak read
This commit is contained in:
@ -174,6 +174,15 @@ public:
|
||||
{
|
||||
return consistency_level_;
|
||||
}
|
||||
bool check_consistency_level_validation(const bool contain_inner_table)
|
||||
{
|
||||
bool bool_ret = true;
|
||||
if (contain_inner_table) {
|
||||
// Statement which contain inner tables should be strong read;
|
||||
bool_ret = (consistency_level_ == ObConsistencyLevel::STRONG);
|
||||
}
|
||||
return bool_ret;
|
||||
}
|
||||
void restore_param_store(const int64_t param_count);
|
||||
// param store
|
||||
int reserve_param_space(int64_t param_count);
|
||||
|
||||
@ -730,12 +730,13 @@ int ObSqlTransControl::stmt_sanity_check_(ObSQLSessionInfo *session,
|
||||
int ret = OB_SUCCESS;
|
||||
ObConsistencyLevel current_consist_level = plan_ctx->get_consistency_level();
|
||||
CK (current_consist_level != ObConsistencyLevel::INVALID_CONSISTENCY);
|
||||
const bool contain_inner_table = plan->is_contain_inner_table();
|
||||
|
||||
// adjust stmt's consistency level
|
||||
if (OB_SUCC(ret)) {
|
||||
// Weak read statement with inner table should be converted to strong read.
|
||||
// For example, schema refresh statement;
|
||||
if (plan->is_contain_inner_table() ||
|
||||
if (contain_inner_table ||
|
||||
(!plan->is_plain_select() && current_consist_level != ObConsistencyLevel::STRONG)) {
|
||||
plan_ctx->set_consistency_level(ObConsistencyLevel::STRONG);
|
||||
}
|
||||
@ -762,6 +763,13 @@ int ObSqlTransControl::stmt_sanity_check_(ObSQLSessionInfo *session,
|
||||
LOG_USER_ERROR(OB_NOT_SUPPORTED, "weak consistency under SERIALIZABLE and REPEATABLE-READ isolation level");
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)
|
||||
&& !plan_ctx->check_consistency_level_validation(contain_inner_table)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
TRANS_LOG(ERROR, "unexpected consistency level", K(ret), K(contain_inner_table),
|
||||
"current_level", current_consist_level,
|
||||
"plan_ctx_level", plan_ctx->get_consistency_level());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -12,6 +12,17 @@ Variable_name Value
|
||||
ob_max_read_stale_time -1
|
||||
alter system set weak_read_version_refresh_interval="6s";
|
||||
alter system set weak_read_version_refresh_interval="3s";
|
||||
use oceanbase;
|
||||
set ob_read_consistency = 'weak';
|
||||
show variables like 'ob_read_consistency';
|
||||
Variable_name Value
|
||||
ob_read_consistency WEAK
|
||||
select count(1) > 0 from __all_server;
|
||||
count(1) > 0
|
||||
1
|
||||
select count(1) from gv$ob_sql_audit where consistency_level=3 and query_sql = 'select count(1) > 0 from __all_server' and query_sql not like '%sql_audit%';
|
||||
count(1)
|
||||
1
|
||||
set global ob_max_read_stale_time = -1;
|
||||
show global variables like '%stale_time%';
|
||||
Variable_name Value
|
||||
|
||||
@ -22,6 +22,13 @@ show global variables like '%stale_time%';
|
||||
connection conn1;
|
||||
alter system set weak_read_version_refresh_interval="6s";
|
||||
alter system set weak_read_version_refresh_interval="3s";
|
||||
|
||||
#测试内部表查询是否为强读
|
||||
use oceanbase;
|
||||
set ob_read_consistency = 'weak';
|
||||
show variables like 'ob_read_consistency';
|
||||
select count(1) > 0 from __all_server;
|
||||
select count(1) from gv$ob_sql_audit where consistency_level=3 and query_sql = 'select count(1) > 0 from __all_server' and query_sql not like '%sql_audit%';
|
||||
--sleep 2
|
||||
|
||||
# 0. 禁用ob_max_read_stale_time
|
||||
|
||||
Reference in New Issue
Block a user