【bugfix】修复非实时构建场景,reform开始是有startup线程残留,导致数据库core的问题

This commit is contained in:
congzhou2603
2024-05-17 17:44:33 +08:00
committed by yaoxin
parent 2f8e3bdade
commit f8c51c94bd
6 changed files with 13 additions and 8 deletions

View File

@ -1834,6 +1834,7 @@ static void CBReformStartNotify(void *db_handle, dms_reform_start_context_t *rs_
ereport(LOG, (errmsg("[SS Reform] starts, pmState=%d, SSClusterState=%d, demotion=%d-%d, rec=%d",
pmState, g_instance.dms_cxt.SSClusterState, g_instance.demotion,
t_thrd.walsender_cxt.WalSndCtl->demotion, t_thrd.xlog_cxt.InRecovery)));
SSHandleStartupWhenReformStart(rs_cxt);
ss_reform_info_t *reform_info = &g_instance.dms_cxt.SSReformInfo;
reform_info->is_hashmap_constructed = false;
reform_info->reform_type = rs_cxt->reform_type;
@ -1852,7 +1853,6 @@ static void CBReformStartNotify(void *db_handle, dms_reform_start_context_t *rs_
SSXminInfoPrepare();
reform_info->reform_ver = reform_info->reform_start_time;
reform_info->in_reform = true;
SSHandleStartupWhenReformStart();
char reform_type_str[reform_type_str_len] = {0};
ReformTypeToString(reform_info->reform_type, reform_type_str);
ereport(LOG, (errmodule(MOD_DMS),
@ -1912,6 +1912,7 @@ static int CBReformDoneNotify(void *db_handle)
g_instance.dms_cxt.dms_status = (dms_status_t)DMS_STATUS_IN;
SendPostmasterSignal(PMSIGNAL_DMS_REFORM_DONE);
g_instance.dms_cxt.SSClusterState = NODESTATE_NORMAL;
g_instance.dms_cxt.SSRecoveryInfo.realtime_build_in_reform = false;
g_instance.dms_cxt.SSReformInfo.in_reform = false;
return GS_SUCCESS;
}

View File

@ -620,22 +620,23 @@ void SSWaitStartupExit(bool send_signal)
}
}
void SSHandleStartupWhenReformStart()
void SSHandleStartupWhenReformStart(dms_reform_start_context_t *rs_cxt)
{
if (g_instance.pid_cxt.StartupPID == 0) {
return;
}
if (ENABLE_ONDEMAND_RECOVERY && ENABLE_ONDEMAND_REALTIME_BUILD) {
if (SS_PERFORMING_SWITCHOVER && SS_REFORM_PARTNER) {
if (rs_cxt->reform_type == DMS_REFORM_TYPE_FOR_SWITCHOVER_OPENGAUSS &&
rs_cxt->role != DMS_ROLE_REFORMER) {
g_instance.dms_cxt.SSRecoveryInfo.realtime_build_in_reform = true;
ereport(LOG, (errmodule(MOD_DMS),
errmsg("[SS reform][On-demand] reform start phase, ondemand realtime build is enabled during switchover .")));
errmsg("[SS reform][On-demand] reform start phase, stop ondemand realtime build before switchover.")));
SSWaitStartupExit(true);
return;
} else {
ereport(LOG, (errmodule(MOD_DMS),
errmsg("[SS reform][On-demand] start phase, ondemand realtime build is enable "
"ondemand realtime build is enabled during startup, no need wait startup thread exit .")));
errmsg("[SS reform][On-demand] start phase, ondemand realtime build is enable, no need wait startup thread exit.")));
return;
}
}

View File

@ -3960,7 +3960,8 @@ static int ServerLoop(void)
* after reform.
*/
if (ENABLE_ONDEMAND_REALTIME_BUILD && SS_ONDEMAND_REALTIME_BUILD_DISABLED &&
SS_NORMAL_STANDBY && SS_CLUSTER_ONDEMAND_NORMAL && pmState == PM_RUN) {
SS_NORMAL_STANDBY && SS_CLUSTER_ONDEMAND_NORMAL && pmState == PM_RUN &&
!g_instance.dms_cxt.SSRecoveryInfo.realtime_build_in_reform) {
if (g_instance.pid_cxt.StartupPID == 0) {
g_instance.dms_cxt.SSRecoveryInfo.ondemand_realtime_build_status = READY_TO_BUILD;
g_instance.pid_cxt.StartupPID = initialize_util_thread(STARTUP);

View File

@ -213,6 +213,7 @@ static void knl_g_dms_init(knl_g_dms_context *dms_cxt)
dms_cxt->SSRecoveryInfo.disaster_cluster_promoting = false;
dms_cxt->SSRecoveryInfo.dorado_sharestorage_inited = false;
dms_cxt->SSRecoveryInfo.ondemand_recovery_pause_status = NOT_PAUSE;
dms_cxt->SSRecoveryInfo.in_ondemand_recovery = false;
dms_cxt->log_timezone = NULL;
pg_atomic_init_u32(&dms_cxt->inDmsThreShmemInitCnt, 0);
pg_atomic_init_u32(&dms_cxt->inProcExitCnt, 0);

View File

@ -148,6 +148,7 @@ typedef struct ss_recovery_info {
bool dorado_sharestorage_inited; // used in dorado mode
bool disaster_cluster_promoting; // standby cluster is promoting
volatile ondemand_recovery_pause_status_t ondemand_recovery_pause_status;
bool realtime_build_in_reform; // used to avoid starting realtime build during reform
} ss_recovery_info_t;
typedef struct ondemand_htab_ctrl {

View File

@ -61,4 +61,4 @@ void SSGrantDSSWritePermission(void);
bool SSPrimaryRestartScenario();
bool SSBackendNeedExitScenario();
void SSWaitStartupExit(bool send_signal = true);
void SSHandleStartupWhenReformStart();
void SSHandleStartupWhenReformStart(dms_reform_start_context_t *rs_cxt);