!695 支持在线扩容内核适配修改

Merge pull request !695 from 薛蒙恩/1.1.0
This commit is contained in:
opengauss-bot 2021-02-08 09:39:22 +08:00 committed by Gitee
commit 2d38c78bb8
3 changed files with 105 additions and 0 deletions

View File

@ -1023,6 +1023,74 @@ append_string_info(char **optLines, const char *newContext)
return optLinesResult;
}
/*******************************************************************************
Function : IsLastNotNullReplconninfo
Description : determine if replconninfoX which is being set is the last one valid replconninfo
Input : optLines - postgres.conf info before changing
replconninfoX - replconninfo param name which is being set, eg "replconninfo1"
Output : None
Return : bool
*******************************************************************************/
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;
}
/* replconninfoX must be invalid if it is commented*/
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;
}
}
}
}
/* return true if replconninfoX which is being set is the last one valid replconninfo */
if (notNullReplconninfoNums == 1 && !isReplconninfoXNull) {
return true;
}
return false;
}
/*
* @@GaussDB@@
* Brief :
@ -1114,6 +1182,14 @@ do_gucset(const char *action_type, const char *data_dir)
}
}
/* Give a warning if the last valid replconninfo is set to a invalid value currently */
if (strncmp(config_param[i], "replconninfo", strlen("replconninfo")) == 0 &&
config_value[i] != NULL && (strlen(config_value[i]) == 0 || strncmp(config_value[i], "''", strlen("''")) == 0) &&
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 */

View File

@ -17699,6 +17699,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.
@ -17720,6 +17736,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;
}
}
}

View File

@ -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;