!1990 修复多个客户端同时连接到B数据库时,出现并发创建dolphin插件导致连接失败的问题

Merge pull request !1990 from pengjiong/array
This commit is contained in:
opengauss-bot
2022-07-30 02:45:53 +00:00
committed by Gitee
5 changed files with 34 additions and 18 deletions

View File

@ -7142,6 +7142,29 @@ void RemoveTempNamespace()
}
}
#ifndef ENABLE_MULTIPLE_NODES
void LoadSqlPlugin()
{
if (u_sess->proc_cxt.MyDatabaseId != InvalidOid && DB_IS_CMPT(B_FORMAT)) {
if (!u_sess->attr.attr_sql.dolphin) {
/* recheck and load dolphin within lock */
pthread_mutex_lock(&g_instance.loadPluginLock[DB_CMPT_B]);
u_sess->attr.attr_sql.dolphin = CheckIfExtensionExists("dolphin");
if (!u_sess->attr.attr_sql.dolphin) {
LoadDolphinIfNeeded();
} else {
InitBSqlPluginHookIfNeeded();
}
pthread_mutex_unlock(&g_instance.loadPluginLock[DB_CMPT_B]);
} else {
InitBSqlPluginHookIfNeeded();
}
} else if (u_sess->proc_cxt.MyDatabaseId != InvalidOid && DB_IS_CMPT(A_FORMAT) && u_sess->attr.attr_sql.whale) {
InitASqlPluginHookIfNeeded();
}
}
#endif
/* ----------------------------------------------------------------
* PostgresMain
* openGauss main loop -- all backends, interactive or otherwise start here
@ -7599,15 +7622,7 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam
init_set_params_htab();
#ifndef ENABLE_MULTIPLE_NODES
if (u_sess->proc_cxt.MyDatabaseId != InvalidOid && DB_IS_CMPT(B_FORMAT)) {
if (!u_sess->attr.attr_sql.dolphin) {
LoadDolphinIfNeeded();
} else {
InitBSqlPluginHookIfNeeded();
}
} else if (u_sess->proc_cxt.MyDatabaseId != InvalidOid && DB_IS_CMPT(A_FORMAT) && u_sess->attr.attr_sql.whale) {
InitASqlPluginHookIfNeeded();
}
LoadSqlPlugin();
#endif
/*

View File

@ -838,6 +838,11 @@ void knl_instance_init()
knl_g_csn_barrier_init(&g_instance.csn_barrier_cxt);
knl_g_audit_init(&g_instance.audit_cxt);
knl_plugin_vec_func_init(&g_instance.plugin_vec_func_cxt);
#ifndef ENABLE_MULTIPLE_NODES
for (int i = 0; i < DB_CMPT_MAX; i++) {
pthread_mutex_init(&g_instance.loadPluginLock[i], NULL);
}
#endif
}
void add_numa_alloc_info(void* numaAddr, size_t length)

View File

@ -854,15 +854,7 @@ static bool InitSession(knl_session_context* session)
SetProcessingMode(NormalProcessing);
#ifndef ENABLE_MULTIPLE_NODES
if (u_sess->proc_cxt.MyDatabaseId != InvalidOid && DB_IS_CMPT(B_FORMAT)) {
if (!u_sess->attr.attr_sql.dolphin) {
LoadDolphinIfNeeded();
} else {
InitBSqlPluginHookIfNeeded();
}
} else if (u_sess->proc_cxt.MyDatabaseId != InvalidOid && DB_IS_CMPT(A_FORMAT) && u_sess->attr.attr_sql.whale) {
InitASqlPluginHookIfNeeded();
}
LoadSqlPlugin();
#endif
init_session_share_memory();

View File

@ -1232,6 +1232,7 @@ typedef struct knl_instance_context {
void *raw_parser_hook[DB_CMPT_MAX];
void *plsql_parser_hook[DB_CMPT_MAX];
char *llvmIrFilePath[DB_CMPT_MAX];
pthread_mutex_t loadPluginLock[DB_CMPT_MAX];
#endif
pg_atomic_uint32 extensionNum;
knl_g_audit_context audit_cxt;

View File

@ -1001,6 +1001,9 @@ void log_disconnections(int code, Datum arg);
void cleanGPCPlanProcExit(int code, Datum arg);
void ResetInterruptCxt();
#ifndef ENABLE_MULTIPLE_NODES
void LoadSqlPlugin();
#endif
#define MSG_A_REPEAT_NUM_MAX 1024
#define OVERRIDE_STACK_LENGTH_MAX 1024