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

This commit is contained in:
xue_meng_en 2021-02-05 10:55:52 +08:00
parent 5aab3b6668
commit 120e056a94
3 changed files with 94 additions and 0 deletions

View File

@ -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 */

View File

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

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;