diff --git a/src/gausskernel/process/tcop/postgres.cpp b/src/gausskernel/process/tcop/postgres.cpp index a597b291f..94d64ce06 100755 --- a/src/gausskernel/process/tcop/postgres.cpp +++ b/src/gausskernel/process/tcop/postgres.cpp @@ -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 /* diff --git a/src/gausskernel/process/threadpool/knl_instance.cpp b/src/gausskernel/process/threadpool/knl_instance.cpp index efa1979ab..731406621 100755 --- a/src/gausskernel/process/threadpool/knl_instance.cpp +++ b/src/gausskernel/process/threadpool/knl_instance.cpp @@ -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) diff --git a/src/gausskernel/process/threadpool/threadpool_worker.cpp b/src/gausskernel/process/threadpool/threadpool_worker.cpp index b2be2a44c..44cd0042f 100644 --- a/src/gausskernel/process/threadpool/threadpool_worker.cpp +++ b/src/gausskernel/process/threadpool/threadpool_worker.cpp @@ -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(); diff --git a/src/include/knl/knl_instance.h b/src/include/knl/knl_instance.h index 555e82a8f..7a64d309b 100755 --- a/src/include/knl/knl_instance.h +++ b/src/include/knl/knl_instance.h @@ -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; diff --git a/src/include/postgres.h b/src/include/postgres.h index af42226e0..c9e0fd35b 100644 --- a/src/include/postgres.h +++ b/src/include/postgres.h @@ -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