support max_connections and max_user_connections

This commit is contained in:
st0
2021-08-19 17:11:52 +08:00
committed by wangzelin.wzl
parent 4a1adf11e8
commit 88a8862b77
52 changed files with 22189 additions and 24112 deletions

View File

@ -143,7 +143,8 @@ ObSQLSessionInfo::ObSQLSessionInfo()
prelock_(false),
proxy_version_(0),
min_proxy_version_ps_(0),
is_ignore_stmt_(false)
is_ignore_stmt_(false),
got_conn_res_(false)
{}
ObSQLSessionInfo::~ObSQLSessionInfo()
@ -1269,3 +1270,60 @@ int ObSQLSessionInfo::ps_use_stream_result_set(bool& use_stream)
}
return ret;
}
int ObSQLSessionInfo::on_user_connect(schema::ObSessionPrivInfo& priv_info, const ObUserInfo* user_info)
{
int ret = OB_SUCCESS;
ObConnectResourceMgr* conn_res_mgr = GCTX.conn_res_mgr_;
if (get_is_deserialized()) {
// do nothing
} else if (OB_ISNULL(conn_res_mgr) || OB_ISNULL(user_info)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("connect resource mgr or user info is null", K(ret), K(conn_res_mgr));
} else {
const ObPrivSet& priv = priv_info.user_priv_set_;
const ObString& user_name = priv_info.user_name_;
const uint64_t tenant_id = priv_info.tenant_id_;
const uint64_t user_id = priv_info.user_id_;
uint64_t max_connections_per_hour = user_info->get_max_connections();
uint64_t max_user_connections = user_info->get_max_user_connections();
uint64_t max_tenant_connections = 0;
if (OB_FAIL(get_sys_variable(SYS_VAR_MAX_CONNECTIONS, max_tenant_connections))) {
LOG_WARN("get system variable SYS_VAR_MAX_CONNECTIONS failed", K(ret));
} else if (0 == max_user_connections) {
if (OB_FAIL(get_sys_variable(SYS_VAR_MAX_USER_CONNECTIONS, max_user_connections))) {
LOG_WARN("get system variable SYS_VAR_MAX_USER_CONNECTIONS failed", K(ret));
}
} else {
ObObj val;
val.set_uint64(max_user_connections);
if (OB_FAIL(update_sys_variable(SYS_VAR_MAX_USER_CONNECTIONS, val))) {
LOG_WARN("set system variable SYS_VAR_MAX_USER_CONNECTIONS failed", K(ret), K(val));
}
}
if (OB_SUCC(ret) && OB_FAIL(conn_res_mgr->on_user_connect(tenant_id,
user_id,
priv,
user_name,
max_connections_per_hour,
max_user_connections,
max_tenant_connections,
*this))) {
LOG_WARN("create user connection failed", K(ret));
}
}
return ret;
}
int ObSQLSessionInfo::on_user_disconnect()
{
int ret = OB_SUCCESS;
ObConnectResourceMgr* conn_res_mgr = GCTX.conn_res_mgr_;
if (OB_ISNULL(conn_res_mgr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("connect resource mgr is null", K(ret));
} else if (OB_FAIL(conn_res_mgr->on_user_disconnect(*this))) {
LOG_WARN("user disconnect failed", K(ret));
}
return ret;
}