Fix: sys var default values modify cause session sync fail

This commit is contained in:
yaojing624
2023-06-30 05:42:27 +00:00
committed by ob-robot
parent 35a45f4768
commit 10f91ccac7
7 changed files with 1033 additions and 516 deletions

View File

@ -163,7 +163,8 @@ def make_head_file(pdir, head_file_name, sorted_list):
head_file.write(" ObSysVarClassType id_;\n");
head_file.write(" common::ObString name_;\n");
head_file.write(" common::ObObjType data_type_;\n");
head_file.write(" common::ObString value_;\n");
head_file.write(" common::ObString default_value_; // used for init tenant\n");
head_file.write(" common::ObString base_value_; // used for session sync\n");
head_file.write(" common::ObString min_val_;\n");
head_file.write(" common::ObString max_val_;\n");
head_file.write(" common::ObString enum_names_;\n");
@ -178,7 +179,7 @@ def make_head_file(pdir, head_file_name, sorted_list):
head_file.write(" common::ObString get_meta_type_func_;\n");
head_file.write(" common::ObString session_special_update_func_;\n");
head_file.write("\n");
head_file.write(" ObSysVarFromJson():id_(SYS_VAR_INVALID), name_(\"\"), data_type_(common::ObNullType), value_(\"\"), min_val_(\"\"), max_val_(\"\"), enum_names_(\"\"), info_(\"\"), flags_(ObSysVarFlag::NONE), alias_(\"\"), base_class_(\"\"), on_check_and_convert_func_(""), on_update_func_(""), to_select_obj_func_(""), to_show_str_func_(""), get_meta_type_func_(""), session_special_update_func_("") {}\n");
head_file.write(" ObSysVarFromJson():id_(SYS_VAR_INVALID), name_(\"\"), data_type_(common::ObNullType), default_value_(\"\"), base_value_(\"\"), min_val_(\"\"), max_val_(\"\"), enum_names_(\"\"), info_(\"\"), flags_(ObSysVarFlag::NONE), alias_(\"\"), base_class_(\"\"), on_check_and_convert_func_(""), on_update_func_(""), to_select_obj_func_(""), to_show_str_func_(""), get_meta_type_func_(""), session_special_update_func_("") {}\n");
head_file.write("};\n");
head_file.write("\n");
head_file.write("class ObSysVariables\n");
@ -189,6 +190,7 @@ def make_head_file(pdir, head_file_name, sorted_list):
head_file.write(" static common::ObString get_name(int64_t i);\n");
head_file.write(" static common::ObObjType get_type(int64_t i);\n");
head_file.write(" static common::ObString get_value(int64_t i);\n");
head_file.write(" static common::ObString get_base_str_value(int64_t i);\n");
head_file.write(" static common::ObString get_min(int64_t i);\n");
head_file.write(" static common::ObString get_max(int64_t i);\n");
head_file.write(" static common::ObString get_info(int64_t i);\n");
@ -198,6 +200,7 @@ def make_head_file(pdir, head_file_name, sorted_list):
head_file.write(" static bool is_mysql_only(int64_t i);\n");
head_file.write(" static common::ObString get_alias(int64_t i);\n");
head_file.write(" static const common::ObObj &get_default_value(int64_t i);\n")
head_file.write(" static const common::ObObj &get_base_value(int64_t i);\n")
head_file.write(" static int64_t get_amount();\n");
head_file.write(" static int set_value(const char *name, const char * new_value);\n");
head_file.write(" static int set_value(const common::ObString &name, const common::ObString &new_value);\n");
@ -251,6 +254,8 @@ def make_cpp_file(pdir, cpp_file_name, sorted_list):
cpp_file.write("static ObSysVarFromJson ObSysVars[ObSysVarFactory::ALL_SYS_VARS_COUNT];\n")
cpp_file.write("static ObObj ObSysVarDefaultValues[ObSysVarFactory::ALL_SYS_VARS_COUNT];\n")
cpp_file.write("static ObArenaAllocator ObSysVarAllocator(ObModIds::OB_COMMON_SYS_VAR_DEFAULT_VALUE);\n")
cpp_file.write("static ObObj ObSysVarBaseValues[ObSysVarFactory::ALL_SYS_VARS_COUNT];\n")
cpp_file.write("static ObArenaAllocator ObBaseSysVarAllocator(ObModIds::OB_COMMON_SYS_VAR_DEFAULT_VALUE);\n")
cpp_file.write("static int64_t ObSysVarsIdToArrayIdx[ObSysVarFactory::OB_MAX_SYS_VAR_ID];\n")
cpp_file.write("// VarsInit中需要判断当前最大的SysVars对应的id,是否大于OB_MAX_SYS_VAR_ID\n")
cpp_file.write("// 如果大于OB_MAX_SYS_VAR_ID表示存在无效的SysVarsId\n")
@ -311,7 +316,8 @@ def make_cpp_file(pdir, cpp_file_name, sorted_list):
cpp_file.write("ObSysVarClassType ObSysVariables::get_sys_var_id(int64_t i){ return ObSysVars[i].id_;}\n")
cpp_file.write("ObString ObSysVariables::get_name(int64_t i){ return ObSysVars[i].name_;}\n")
cpp_file.write("ObObjType ObSysVariables::get_type(int64_t i){ return ObSysVars[i].data_type_;}\n")
cpp_file.write("ObString ObSysVariables::get_value(int64_t i){ return ObSysVars[i].value_;}\n")
cpp_file.write("ObString ObSysVariables::get_value(int64_t i){ return ObSysVars[i].default_value_;}\n")
cpp_file.write("ObString ObSysVariables::get_base_str_value(int64_t i){ return ObSysVars[i].base_value_;}\n")
cpp_file.write("ObString ObSysVariables::get_min(int64_t i){ return ObSysVars[i].min_val_;}\n")
cpp_file.write("ObString ObSysVariables::get_max(int64_t i){ return ObSysVars[i].max_val_;}\n")
cpp_file.write("ObString ObSysVariables::get_info(int64_t i){ return ObSysVars[i].info_;}\n")
@ -321,6 +327,7 @@ def make_cpp_file(pdir, cpp_file_name, sorted_list):
cpp_file.write("bool ObSysVariables::is_mysql_only(int64_t i){ return ObSysVars[i].flags_ & ObSysVarFlag::MYSQL_ONLY;}\n")
cpp_file.write("ObString ObSysVariables::get_alias(int64_t i){ return ObSysVars[i].alias_;}\n")
cpp_file.write("const ObObj &ObSysVariables::get_default_value(int64_t i){ return ObSysVarDefaultValues[i];}\n")
cpp_file.write("const ObObj &ObSysVariables::get_base_value(int64_t i){ return ObSysVarBaseValues[i];}\n")
cpp_file.write("int64_t ObSysVariables::get_amount(){ return var_amount;}\n")
cpp_file.write("\n")
cpp_file.write("int ObSysVariables::set_value(const char *name, const char * new_value)\n")
@ -335,7 +342,7 @@ def make_cpp_file(pdir, cpp_file_name, sorted_list):
cpp_file.write(" bool name_exist = false;\n")
cpp_file.write(" for (int64_t i = 0; OB_SUCC(ret) && false == name_exist && i < var_amount; ++i){\n")
cpp_file.write(" if (0 == ObSysVars[i].name_.compare(name)) {\n")
cpp_file.write(" ObSysVars[i].value_.assign_ptr(new_value.ptr(), new_value.length());\n")
cpp_file.write(" ObSysVars[i].default_value_.assign_ptr(new_value.ptr(), new_value.length());\n")
cpp_file.write(" name_exist = true;\n")
cpp_file.write(" }\n")
cpp_file.write(" }\n")
@ -353,6 +360,7 @@ int ObSysVariables::init_default_values()
int64_t sys_var_count = get_amount();
for (int64_t i = 0; OB_SUCC(ret) && i < sys_var_count; ++i) {
const ObString &sys_var_val_str = ObSysVariables::get_value(i);
const ObString &base_sys_var_val_str = ObSysVariables::get_base_str_value(i);
const ObObjType sys_var_type = ObSysVariables::get_type(i);
if (OB_UNLIKELY(sys_var_type == ObTimestampType)) {
ret = OB_ERR_UNEXPECTED;
@ -362,6 +370,10 @@ int ObSysVariables::init_default_values()
ObObj out_obj;
in_obj.set_varchar(sys_var_val_str);
in_obj.set_collation_type(CS_TYPE_UTF8MB4_GENERAL_CI);
ObObj base_in_obj;
ObObj base_out_obj;
base_in_obj.set_varchar(base_sys_var_val_str);
base_in_obj.set_collation_type(CS_TYPE_UTF8MB4_GENERAL_CI);
//varchar to others. so, no need to get collation from session
ObCastCtx cast_ctx(&ObSysVarAllocator,
NULL,
@ -369,16 +381,29 @@ int ObSysVariables::init_default_values()
CM_NONE,
CS_TYPE_INVALID,
NULL);
ObCastCtx fixed_cast_ctx(&ObBaseSysVarAllocator,
NULL,
0,
CM_NONE,
CS_TYPE_INVALID,
NULL);
if (OB_FAIL(ObObjCaster::to_type(sys_var_type, cast_ctx, in_obj, out_obj))) {
ObString sys_var_name = ObSysVariables::get_name(i);
LOG_WARN("fail to cast object",
K(ret), "cell", in_obj, "from_type", ob_obj_type_str(in_obj.get_type()),
"to_type", ob_obj_type_str(sys_var_type), K(sys_var_name), K(i));
} else if (OB_FAIL(ObObjCaster::to_type(sys_var_type, fixed_cast_ctx, base_in_obj, base_out_obj))) {
ObString sys_var_name = ObSysVariables::get_name(i);
LOG_WARN("fail to cast object",
K(ret), "cell", base_in_obj, "from_type", ob_obj_type_str(base_in_obj.get_type()),
"to_type", ob_obj_type_str(sys_var_type), K(sys_var_name), K(i));
} else {
if (ob_is_string_type(out_obj.get_type())) {
out_obj.set_collation_level(CS_LEVEL_SYSCONST);
base_out_obj.set_collation_level(CS_LEVEL_SYSCONST);
}
ObSysVarDefaultValues[i] = out_obj;
ObSysVarBaseValues[i] = base_out_obj;
}
}
}
@ -431,7 +456,7 @@ def write_sys_var_fac_class(wfile, sorted_list):
class ObSysVarFactory
{
public:
ObSysVarFactory();
ObSysVarFactory(const int64_t tenant_id = OB_SERVER_TENANT_ID);
virtual ~ObSysVarFactory();
void destroy();
int create_sys_var(ObSysVarClassType sys_var_id, ObBasicSysVar *&sys_var);
@ -782,8 +807,9 @@ const ObString ObSysVarFactory::get_sys_var_name_by_id(ObSysVarClassType sys_var
return sys_var_name;
}
ObSysVarFactory::ObSysVarFactory()
: allocator_(ObModIds::OB_COMMON_SYS_VAR_FAC), all_sys_vars_created_(false)
ObSysVarFactory::ObSysVarFactory(const int64_t tenant_id)
: allocator_(ObMemAttr(tenant_id, ObModIds::OB_COMMON_SYS_VAR_FAC)),
all_sys_vars_created_(false)
{
MEMSET(store_, 0, sizeof(store_));
MEMSET(store_buf_, 0, sizeof(store_buf_));

File diff suppressed because it is too large Load Diff

View File

@ -41,7 +41,8 @@ struct ObSysVarFromJson{
ObSysVarClassType id_;
common::ObString name_;
common::ObObjType data_type_;
common::ObString value_;
common::ObString default_value_; // used for init tenant
common::ObString base_value_; // used for session sync
common::ObString min_val_;
common::ObString max_val_;
common::ObString enum_names_;
@ -56,7 +57,7 @@ struct ObSysVarFromJson{
common::ObString get_meta_type_func_;
common::ObString session_special_update_func_;
ObSysVarFromJson():id_(SYS_VAR_INVALID), name_(""), data_type_(common::ObNullType), value_(""), min_val_(""), max_val_(""), enum_names_(""), info_(""), flags_(ObSysVarFlag::NONE), alias_(""), base_class_(""), on_check_and_convert_func_(), on_update_func_(), to_select_obj_func_(), to_show_str_func_(), get_meta_type_func_(), session_special_update_func_() {}
ObSysVarFromJson():id_(SYS_VAR_INVALID), name_(""), data_type_(common::ObNullType), default_value_(""), base_value_(""), min_val_(""), max_val_(""), enum_names_(""), info_(""), flags_(ObSysVarFlag::NONE), alias_(""), base_class_(""), on_check_and_convert_func_(), on_update_func_(), to_select_obj_func_(), to_show_str_func_(), get_meta_type_func_(), session_special_update_func_() {}
};
class ObSysVariables
@ -67,6 +68,7 @@ public:
static common::ObString get_name(int64_t i);
static common::ObObjType get_type(int64_t i);
static common::ObString get_value(int64_t i);
static common::ObString get_base_str_value(int64_t i);
static common::ObString get_min(int64_t i);
static common::ObString get_max(int64_t i);
static common::ObString get_info(int64_t i);
@ -76,6 +78,7 @@ public:
static bool is_mysql_only(int64_t i);
static common::ObString get_alias(int64_t i);
static const common::ObObj &get_default_value(int64_t i);
static const common::ObObj &get_base_value(int64_t i);
static int64_t get_amount();
static int set_value(const char *name, const char * new_value);
static int set_value(const common::ObString &name, const common::ObString &new_value);

File diff suppressed because it is too large Load Diff

View File

@ -965,7 +965,8 @@ ObBasicSysVar *ObBasicSessionInfo::get_sys_var(const int64_t idx)
return var;
}
int ObBasicSessionInfo::init_system_variables(const bool print_info_log, const bool is_sys_tenant)
int ObBasicSessionInfo::init_system_variables(const bool print_info_log, const bool is_sys_tenant,
bool is_deserialized)
{
int ret = OB_SUCCESS;
ObString name;
@ -989,7 +990,7 @@ int ObBasicSessionInfo::init_system_variables(const bool print_info_log, const b
// Note: 如果已经初始化过 base value,则下面的流程不会执行
var_type = ObSysVariables::get_type(i);
var_flag = ObSysVariables::get_flags(i);
value.set_varchar(ObSysVariables::get_value(i));
value.set_varchar(is_deserialized ? ObSysVariables::get_base_str_value(i) :ObSysVariables::get_value(i));
value.set_collation_type(ObCharset::get_system_collation());
min_val.set_varchar(ObSysVariables::get_min(i));
min_val.set_collation_type(ObCharset::get_system_collation());
@ -1091,12 +1092,12 @@ int ObBasicSessionInfo::update_query_sensitive_system_variable(ObSchemaGetterGua
return ret;
}
int ObBasicSessionInfo::load_default_sys_variable(const bool print_info_log, const bool is_sys_tenant)
int ObBasicSessionInfo::load_default_sys_variable(const bool print_info_log, const bool is_sys_tenant, bool is_deserialized)
{
int ret = OB_SUCCESS;
if (OB_FAIL(sys_var_fac_.create_all_sys_vars())) {
LOG_WARN("fail create all sys variables", K(ret));
} else if (OB_FAIL(init_system_variables(print_info_log, is_sys_tenant))) {
} else if (OB_FAIL(init_system_variables(print_info_log, is_sys_tenant, is_deserialized))) {
LOG_WARN("Init system variables failed !", K(ret));
}
return ret;
@ -3764,10 +3765,10 @@ int ObBasicSessionInfo::get_sync_sys_vars(ObIArray<ObSysVarClassType>
if (OB_FAIL(ObSysVarFactory::calc_sys_var_store_idx(ids.at(i), sys_var_idx))) {
LOG_WARN("fail to calc sys var store idx", K(i), K(sys_var_idx), K(ids.at(i)), K(ret));
} else {
if (!ObSysVariables::get_default_value(sys_var_idx).can_compare(
sys_vars_[sys_var_idx]->get_value())||ObSysVariables::get_default_value(sys_var_idx) !=
if (!ObSysVariables::get_base_value(sys_var_idx).can_compare(
sys_vars_[sys_var_idx]->get_value())||ObSysVariables::get_base_value(sys_var_idx) !=
sys_vars_[sys_var_idx]->get_value() ||
ObSysVariables::get_default_value(sys_var_idx).get_scale()
ObSysVariables::get_base_value(sys_var_idx).get_scale()
!= sys_vars_[sys_var_idx]->get_value().get_scale()) {
// need serialize delta vars
if (is_sync_sys_var(ids.at(i))){
@ -3778,14 +3779,14 @@ int ObBasicSessionInfo::get_sync_sys_vars(ObIArray<ObSysVarClassType>
} else {
LOG_TRACE("sys var need sync", K(sys_var_idx),
"val", sys_vars_[sys_var_idx]->get_value(),
"def", ObSysVariables::get_default_value(sys_var_idx),
"def", ObSysVariables::get_base_value(sys_var_idx),
K(sessid_), K(proxy_sessid_));
}
}
} else {
LOG_TRACE("sys var not need sync", K(sys_var_idx),
"val", sys_vars_[sys_var_idx]->get_value(),
"def", ObSysVariables::get_default_value(sys_var_idx),
"def", ObSysVariables::get_base_value(sys_var_idx),
K(sessid_), K(proxy_sessid_));
}
}
@ -3832,7 +3833,7 @@ int ObBasicSessionInfo::serialize_sync_sys_vars(ObIArray<ObSysVarClassType>
LOG_TRACE("serialize sys vars", K(sys_var_idx),
"name", ObSysVariables::get_name(sys_var_idx),
"val", sys_vars_[sys_var_idx]->get_value(),
"def", ObSysVariables::get_default_value(sys_var_idx),
"def", ObSysVariables::get_base_value(sys_var_idx),
K(sessid_), K(proxy_sessid_));
}
}
@ -3950,7 +3951,7 @@ int ObBasicSessionInfo::sync_default_sys_vars(SysVarIncInfo sys_var_inc_info_,
ret = OB_ERR_UNEXPECTED;
LOG_WARN("create sys var is NULL", K(ret));
} else if (FALSE_IT(sys_vars_[store_idx]->set_value(
ObSysVariables::get_default_value(store_idx)))) {
ObSysVariables::get_base_value(store_idx)))) {
// do nothing.
} else if (OB_FAIL(process_session_variable(sys_var_id, sys_vars_[store_idx]->get_value(),
false))) {
@ -4616,7 +4617,7 @@ int ObBasicSessionInfo::load_all_sys_vars_default()
{
int ret = OB_SUCCESS;
OZ (clean_all_sys_vars());
OZ (load_default_sys_variable(false, false));
OZ (load_default_sys_variable(false, false, true));
return ret;
}
@ -4667,10 +4668,10 @@ int ObBasicSessionInfo::load_all_sys_vars(const ObSysVariableSchema &sys_var_sch
if (sys_vars_[i]->is_influence_plan()) {
OZ (influence_plan_var_indexs_.push_back(i));
}
if (ObSysVariables::get_default_value(i) != sys_vars_[i]->get_value()) {
if (ObSysVariables::get_base_value(i) != sys_vars_[i]->get_value()) {
OZ (sys_var_inc_info_.add_sys_var_id(sys_var_id));
LOG_DEBUG("schema and def not identical", K(sys_var_id), "val", sys_vars_[i]->get_value(),
"def", ObSysVariables::get_default_value(i));
"def", ObSysVariables::get_base_value(i));
}
}
}

View File

@ -818,7 +818,8 @@ public:
const share::ObBasicSysVar *get_sys_var(const int64_t idx) const;
share::ObBasicSysVar *get_sys_var(const int64_t idx);
int64_t get_sys_var_count() const { return share::ObSysVarFactory::ALL_SYS_VARS_COUNT; }
int load_default_sys_variable(const bool print_info_log, const bool is_sys_tenant);
// deserialized scene need use base_value as baseline.
int load_default_sys_variable(const bool print_info_log, const bool is_sys_tenant, bool is_deserialized = false);
int load_default_configs_in_pc();
int update_query_sensitive_system_variable(share::schema::ObSchemaGetterGuard &schema_guard);
int process_variable_for_tenant(const common::ObString &var, common::ObObj &val);
@ -1364,8 +1365,8 @@ private:
common::ObObj *dest_val_ptr);
inline int store_query_string_(const ObString &stmt);
inline int set_session_state_(ObSQLSessionState state);
//写入系统变量的默认值
int init_system_variables(const bool print_info_log, const bool is_sys_tenant);
//写入系统变量的默认值, deserialized scene need use base_value as baseline.
int init_system_variables(const bool print_info_log, const bool is_sys_tenant, bool is_deserialized = false);
protected:
//============注意:下面的成员变量使用时,需要考虑并发控制================================
struct MultiThreadData