repair gsc sub thread exit error issue

This commit is contained in:
justbk
2022-06-01 14:55:59 +08:00
parent 92be2cd901
commit baca937bd1
2 changed files with 36 additions and 21 deletions

View File

@ -298,6 +298,7 @@ void incre_ckpt_pagewriter_cxt_init()
g_instance.ckpt_cxt_ctl->CkptBufferIdsTail = 0;
g_instance.ckpt_cxt_ctl->CkptBufferIdsFlushPages = 0;
g_instance.ckpt_cxt_ctl->CkptBufferIdsCompletedPages = 0;
g_instance.ckpt_cxt_ctl->page_writer_sub_can_exit = false;
uint32 dirty_list_size = MAX_DIRTY_LIST_FLUSH_NUM / thread_num;
@ -1209,6 +1210,34 @@ void dw_upgrade_single()
return;
}
static void HandlePageWriterExit() {
/* Let the pagewriter sub thread exit, then main pagewriter thread exits */
if (t_thrd.pagewriter_cxt.shutdown_requested && g_instance.ckpt_cxt_ctl->page_writer_can_exit) {
g_instance.ckpt_cxt_ctl->page_writer_sub_can_exit = true;
pg_write_barrier();
/* Wake up the sub thread to exit*/
wakeup_sub_thread();
/*Wait until all the sub pagewriter thread exit then */
while (true) {
if (pg_atomic_read_u32(&g_instance.ckpt_cxt_ctl->current_page_writer_count) == 1) {
ereport(LOG,
(errmodule(MOD_INCRE_CKPT),
errmsg("pagewriter thread shut down, id is %d", t_thrd.pagewriter_cxt.pagewriter_id)));
/*
* From here on, elog(ERROR) should end with exit(1), not send
* control back to the sigsetjmp block above.
*/
u_sess->attr.attr_common.ExitOnAnyError = true;
/* Normal exit from the pagewriter is here */
proc_exit(0); /* done */
}
pg_usleep(MILLISECOND_TO_MICROSECOND);
}
}
}
static void HandlePageWriterMainInterrupts()
{
if (t_thrd.pagewriter_cxt.got_SIGHUP) {
@ -1223,24 +1252,6 @@ static void HandlePageWriterMainInterrupts()
PageWriterSyncWithAbsorption();
t_thrd.pagewriter_cxt.sync_retry = false;
}
/* main thread should finally exit. */
while (t_thrd.pagewriter_cxt.shutdown_requested && g_instance.ckpt_cxt_ctl->page_writer_can_exit) {
if (pg_atomic_read_u32(&g_instance.ckpt_cxt_ctl->current_page_writer_count) == 1) {
ereport(LOG,
(errmodule(MOD_INCRE_CKPT),
errmsg("pagewriter thread shut down, id is %d", t_thrd.pagewriter_cxt.pagewriter_id)));
/*
* From here on, elog(ERROR) should end with exit(1), not send
* control back to the sigsetjmp block above.
*/
u_sess->attr.attr_common.ExitOnAnyError = true;
/* Normal exit from the pagewriter is here */
proc_exit(0); /* done */
}
}
return;
}
static void ckpt_pagewriter_main_thread_loop(void)
@ -1263,7 +1274,7 @@ static void ckpt_pagewriter_main_thread_loop(void)
HandlePageWriterMainInterrupts();
candidate_num = get_curr_candidate_nums(false) + get_curr_candidate_nums(true);
if (candidate_num == 0 && !t_thrd.pagewriter_cxt.shutdown_requested) {
if (candidate_num == 0) {
/* wakeup sub thread scan the buffer pool, init the candidate list */
wakeup_sub_thread();
}
@ -1291,8 +1302,10 @@ static void ckpt_pagewriter_main_thread_loop(void)
/* pagewriter thread flush dirty page */
calculate_max_flush_num();
ckpt_pagewriter_main_thread_flush_dirty_page();
return;
}
/* Control all the pagewriter threads to exit*/
HandlePageWriterExit();
return;
}
@ -1341,7 +1354,8 @@ static void ckpt_pagewriter_sub_thread_loop()
int thread_id = t_thrd.pagewriter_cxt.pagewriter_id;
WritebackContextInit(&wb_context, &t_thrd.pagewriter_cxt.page_writer_after);
if (t_thrd.pagewriter_cxt.shutdown_requested && g_instance.ckpt_cxt_ctl->page_writer_can_exit) {
pg_read_barrier();
if (g_instance.ckpt_cxt_ctl->page_writer_sub_can_exit) {
ereport(LOG,
(errmodule(MOD_INCRE_CKPT),
errmsg("pagewriter thread shut down, id is %d", t_thrd.pagewriter_cxt.pagewriter_id)));

View File

@ -505,6 +505,7 @@ typedef struct knl_g_ckpt_context {
/* Pagewriter thread need wait shutdown checkpoint finish */
volatile bool page_writer_can_exit;
volatile bool page_writer_sub_can_exit;
/* pagewriter thread view information */
uint64 page_writer_actual_flush;