From 41d595f9a96d27809b80f8f64aa532f7b2b5772f Mon Sep 17 00:00:00 2001 From: chenxiaobin19 <1025221611@qq.com> Date: Mon, 27 Sep 2021 15:53:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E5=90=88commit=20f60dd06e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../storage/replication/syncrep.cpp | 17 ++++------ src/lib/config/cm_config.cpp | 34 ++++++++----------- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/gausskernel/storage/replication/syncrep.cpp b/src/gausskernel/storage/replication/syncrep.cpp index a49e335c5..cef484513 100755 --- a/src/gausskernel/storage/replication/syncrep.cpp +++ b/src/gausskernel/storage/replication/syncrep.cpp @@ -1772,6 +1772,7 @@ int init_gauss_cluster_config(void) if (g_nodeHeader.node <= 0) { free(g_node); + g_node = nullptr; return 1; } @@ -1784,12 +1785,14 @@ int init_gauss_cluster_config(void) if (NULL == g_currentNode) { free(g_node); + g_node = nullptr; return 1; } if (get_dynamic_dn_role() != 0) { // failed to get dynamic dn role free(g_node); + g_node = nullptr; return 1; } @@ -1810,7 +1813,6 @@ bool check_synchronous_standby_names(char **newval, void **extra, GucSource sour SyncRepConfigData *pconf = NULL; syncrep_scanner_yyscan_t yyscanner; char* data_dir = t_thrd.proc_cxt.DataDir; - uint32 idx; char* p = NULL; /* Reset communication variables to ensure a fresh start */ @@ -1845,20 +1847,15 @@ bool check_synchronous_standby_names(char **newval, void **extra, GucSource sour // The sync number must less or equals to the number of standby node names. return false; } - /* get current cluster information from cluster_staic_config */ - if (strcmp(u_sess->attr.attr_common.application_name, "gsql") == 0 && has_static_config() - && 0 == init_gauss_cluster_config()) { - for (idx = 0; idx < g_node_num; idx++) { - if (g_currentNode->node == g_node[idx].node) { - g_local_node_idx = idx; - break; - } + if (t_thrd.role == WORKER && strcmp(u_sess->attr.attr_common.application_name, "gsql") == 0 + && has_static_config()) { + if (0 != init_gauss_cluster_config()) { + goto pass; } } else { goto pass; } - g_local_node_name = g_node[g_local_node_idx].nodeName; p = pconf->member_names; for (int i = 1; i <= pconf->nmembers; i++) { diff --git a/src/lib/config/cm_config.cpp b/src/lib/config/cm_config.cpp index 8a2f6f802..8a7c9f635 100644 --- a/src/lib/config/cm_config.cpp +++ b/src/lib/config/cm_config.cpp @@ -294,11 +294,6 @@ int read_config_file(const char* file_path, int* err_no, bool inReload, int mall FREAD(&g_nodeHeader.nodeCount, 1, sizeof(uint32), fd); FREAD(&g_nodeHeader.node, 1, sizeof(uint32), fd); - if (g_node != NULL && !inReload) { - free(g_node); - g_node = NULL; - } - if (g_nodeHeader.nodeCount > CM_NODE_MAXNUM || g_nodeHeader.nodeCount == 0) { fclose(fd); return READ_FILE_ERROR; @@ -308,14 +303,16 @@ int read_config_file(const char* file_path, int* err_no, bool inReload, int mall goto read_failed; if (!inReload) { - if (mallocByNodeNum == MALLOC_BY_NODE_NUM) { - g_node = (staticNodeConfig*)malloc(sizeof(staticNodeConfig) * g_nodeHeader.nodeCount); - } else { - g_node = (staticNodeConfig*)malloc(sizeof(staticNodeConfig) * CM_NODE_MAXNUM); - } if (g_node == NULL) { - fclose(fd); - return OUT_OF_MEMORY; + if (mallocByNodeNum == MALLOC_BY_NODE_NUM) { + g_node = (staticNodeConfig*)malloc(sizeof(staticNodeConfig) * g_nodeHeader.nodeCount); + } else { + g_node = (staticNodeConfig*)malloc(sizeof(staticNodeConfig) * CM_NODE_MAXNUM); + } + if (g_node == NULL) { + fclose(fd); + return OUT_OF_MEMORY; + } } /* g_node size may be larger than SECUREC_STRING_MAX_LEN in large cluster.*/ @@ -816,15 +813,12 @@ int read_lc_config_file(const char* file_path, int* err_no) return READ_FILE_ERROR; } - if (g_node != NULL) { - free(g_node); - g_node = NULL; - } - - g_node = (staticNodeConfig*)malloc(sizeof(staticNodeConfig) * g_node_num); if (g_node == NULL) { - fclose(fd); - return OUT_OF_MEMORY; + g_node = (staticNodeConfig*)malloc(sizeof(staticNodeConfig) * g_node_num); + if (g_node == NULL) { + fclose(fd); + return OUT_OF_MEMORY; + } } for (ii = 0; ii < g_node_num; ii++) {