From 120e056a9469dcf5ac449bb8fcb3547bc4f06d12 Mon Sep 17 00:00:00 2001 From: xue_meng_en <1836611252@qq.com> Date: Fri, 5 Feb 2021 10:55:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=9C=A8=E7=BA=BF=E6=89=A9?= =?UTF-8?q?=E5=AE=B9=E5=86=85=E6=A0=B8=E9=80=82=E9=85=8D=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/gs_guc/pg_guc.cpp | 65 +++++++++++++++++++ src/common/backend/utils/misc/guc.cpp | 22 +++++++ .../process/postmaster/postmaster.cpp | 7 ++ 3 files changed, 94 insertions(+) diff --git a/src/bin/gs_guc/pg_guc.cpp b/src/bin/gs_guc/pg_guc.cpp index ac9b08647..8b26280b2 100644 --- a/src/bin/gs_guc/pg_guc.cpp +++ b/src/bin/gs_guc/pg_guc.cpp @@ -1023,6 +1023,64 @@ append_string_info(char **optLines, const char *newContext) return optLinesResult; } +static bool IsLastNotNullReplconninfo(char** optLines, char* replconninfoX) +{ + int notNullReplconninfoNums = 0; + bool isReplconninfoXNull = true; + bool matchReplconninfoX = false; + char* p = NULL; + + for (int i = 0; optLines != NULL && optLines[i] != NULL; i++) { + p = optLines[i]; + /* Skip all the blanks at the begin of the optLine */ + while (p != NULL && isspace((unsigned char)*p)) { + ++p; + } + if (p == NULL) { + continue; + } + if (*p == '#') { + ++p; + while (p != NULL && isspace((unsigned char)*p)) { + ++p; + } + if (p != NULL && strncmp(p, replconninfoX, strlen(replconninfoX)) == 0) { + return false; + } + continue; + } + if (p != NULL && strncmp(p, "replconninfo", strlen("replconninfo")) == 0) { + if (strncmp(p, replconninfoX, strlen(replconninfoX)) == 0) { + matchReplconninfoX = true; + } + p += strlen(replconninfoX); + /* Skip all the blanks between the param and '=' */ + while (p != NULL && isspace((unsigned char)*p)) { + p++; + } + /* Skip '=' */ + if (p != NULL && *p == '=') { + p++; + } + /* Skip all the blanks between the '=' and value */ + while (p != NULL && isspace((unsigned char)*p)) { + p++; + } + if (p != NULL && strncmp(p, "''", strlen("''")) != 0 && + strncmp(p, "''", strlen("\"\"")) != 0) { + ++notNullReplconninfoNums; + if (matchReplconninfoX) { + isReplconninfoXNull = false; + } + } + } + } + if (notNullReplconninfoNums == 1 && !isReplconninfoXNull) { + return true; + } + return false; +} + /* * @@GaussDB@@ * Brief : @@ -1114,6 +1172,13 @@ do_gucset(const char *action_type, const char *data_dir) } } + if (strncmp(config_param[i], "replconninfo", strlen("replconninfo")) == 0 && + config_value[i] != NULL && strncmp(config_value[i], "''", strlen("''") && + IsLastNotNullReplconninfo(opt_lines, config_param[i])) { + write_stderr("\nWARNING: This is the last valid replConnInfo, once set to null, " + "the host role will be changed to Normal if the local_role is primary now.\n"); + } + /* find the line where guc parameter in */ lines_index = find_gucoption(opt_lines, config_param[i], NULL, NULL, &optvalue_off, &optvalue_len); /* get the type of gs_guc execution */ diff --git a/src/common/backend/utils/misc/guc.cpp b/src/common/backend/utils/misc/guc.cpp index 29c677e7b..0cf98f2c2 100644 --- a/src/common/backend/utils/misc/guc.cpp +++ b/src/common/backend/utils/misc/guc.cpp @@ -17654,6 +17654,22 @@ static bool check_replconninfo(char** newval, void** extra, GucSource source) return true; } +/* + * @@GaussDB@@ + * Brief : Determine if all eight replconninfos are empty. + * Description : + * Notes : + */ +static inline bool GetReplCurArrayIsNull() +{ + for (int i = 1; i < MAX_REPLNODE_NUM; i++) { + if (t_thrd.postmaster_cxt.ReplConnArray[i] != NULL) { + return false; + } + } + return true; +} + /* * @@GaussDB@@ * Brief : Parse replconninfo1. @@ -17675,6 +17691,12 @@ static void assign_replconninfo1(const char* newval, void* extra) if (u_sess->attr.attr_storage.ReplConnInfoArr[1] != NULL && newval != NULL && strcmp(u_sess->attr.attr_storage.ReplConnInfoArr[1], newval) != 0) { t_thrd.postmaster_cxt.ReplConnChanged[1] = true; + // perceive single --> primary_standby + if (t_thrd.postmaster_cxt.HaShmData != NULL && + t_thrd.postmaster_cxt.HaShmData->current_mode == NORMAL_MODE && + !GetReplCurArrayIsNull()) { + t_thrd.postmaster_cxt.HaShmData->current_mode = PRIMARY_MODE; + } } } diff --git a/src/gausskernel/process/postmaster/postmaster.cpp b/src/gausskernel/process/postmaster/postmaster.cpp index cb1224ace..d25ae836e 100755 --- a/src/gausskernel/process/postmaster/postmaster.cpp +++ b/src/gausskernel/process/postmaster/postmaster.cpp @@ -9496,6 +9496,13 @@ static void check_and_reset_ha_listen_port(void) signal_child(g_instance.pid_cxt.RemoteServicePID, SIGTERM); ListenSocketRegulation(); + + if (t_thrd.postmaster_cxt.HaShmData != NULL && + t_thrd.postmaster_cxt.HaShmData->repl_list_num == 0 && + t_thrd.postmaster_cxt.HaShmData->current_mode == PRIMARY_MODE) { + t_thrd.postmaster_cxt.HaShmData->current_mode = NORMAL_MODE; + SetServerMode(NORMAL_MODE); + } } return;