From 0faf339c7c9fe58fad92f8e77eb48ef9d2614c26 Mon Sep 17 00:00:00 2001 From: ZigSmith Date: Tue, 15 Jun 2021 16:01:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AEenable=5Fdouble=5Fwrite?= =?UTF-8?q?=E5=92=8Cenable=5Fincremental=5Fcheckpoint=E7=9A=84=E5=80=BC?= =?UTF-8?q?=E7=A1=AE=E5=AE=9A=E5=9C=A8=E5=90=AF=E5=8A=A8=E9=98=B6=E6=AE=B5?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E6=98=AF=E5=90=A6=E4=BF=9D=E7=95=99=E5=8F=8C?= =?UTF-8?q?=E5=86=99=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../storage/access/transam/double_write.cpp | 68 +++++++++++-------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/src/gausskernel/storage/access/transam/double_write.cpp b/src/gausskernel/storage/access/transam/double_write.cpp index 9a55ef815..4f380fb01 100644 --- a/src/gausskernel/storage/access/transam/double_write.cpp +++ b/src/gausskernel/storage/access/transam/double_write.cpp @@ -841,7 +841,7 @@ static void dw_free_resource(knl_g_dw_context *cxt) cxt->closed = 1; } -void dw_file_check_and_rebuild() +bool dw_file_check_and_rebuild() { if (file_exists(DW_BUILD_FILE_NAME)) { ereport(LOG, (errmodule(MOD_DW), errmsg("Double write initializing after build"))); @@ -873,7 +873,9 @@ void dw_file_check_and_rebuild() } /* Create the DW file. */ - dw_bootstrap(); + if (dw_enabled()) { + dw_bootstrap(); + } /* Remove the DW build file. */ if (unlink(DW_BUILD_FILE_NAME) != 0) { @@ -882,26 +884,28 @@ void dw_file_check_and_rebuild() } } - if (!file_exists(DW_FILE_NAME)) { - ereport(PANIC, (errcode_for_file_access(), errmodule(MOD_DW), errmsg("batch flush DW file does not exist"))); + if (!file_exists(DW_FILE_NAME) && dw_enabled()) { + /* Create the batch file. */ + dw_generate_batch_file(); } if (t_thrd.proc->workingVersionNum >= DW_SUPPORT_SINGLE_FLUSH_VERSION) { - if (!file_exists(SINGLE_DW_FILE_NAME)) { - ereport(PANIC, (errcode_for_file_access(), - errmodule(MOD_DW), errmsg("single flush DW file does not exist"))); + if (!file_exists(SINGLE_DW_FILE_NAME) && dw_enabled()) { + /* Create the single file. */ + dw_generate_single_file(); } } else { if (!file_exists(SINGLE_DW_FILE_NAME)) { ereport(LOG, (errmodule(MOD_DW), errmsg("first upgrade to DW_SUPPORT_SINGLE_FLUSH_VERSION, need init the single file"))); - dw_generate_single_file(); } else { (void)unlink(SINGLE_DW_FILE_NAME); - dw_generate_single_file(); } + /* Create the single file if need.*/ + if (dw_enabled()) + dw_generate_single_file(); } - + return file_exists(DW_FILE_NAME) && file_exists(SINGLE_DW_FILE_NAME); } const void init_dw_single_flush_map() @@ -1014,38 +1018,46 @@ void dw_init(bool shut_down) old_mem_cxt = MemoryContextSwitchTo(mem_cxt); - dw_file_check_and_rebuild(); + bool do_recovery = dw_file_check_and_rebuild(); ereport(LOG, (errmodule(MOD_DW), errmsg("Double Write init"))); - dw_cxt_init_batch(); - dw_cxt_init_single(); + if (do_recovery) { + dw_cxt_init_batch(); + dw_cxt_init_single(); - /* recovery batch flush dw file */ - (void)LWLockAcquire(batch_cxt->flush_lock, LW_EXCLUSIVE); - dw_recover_file_head(batch_cxt, false); + /* recovery batch flush dw file */ + (void)LWLockAcquire(batch_cxt->flush_lock, LW_EXCLUSIVE); + dw_recover_file_head(batch_cxt, false); - dw_recover_partial_write(batch_cxt); - LWLockRelease(batch_cxt->flush_lock); + dw_recover_partial_write(batch_cxt); + LWLockRelease(batch_cxt->flush_lock); - /* recovery single flush dw file */ - (void)LWLockAcquire(single_cxt->flush_lock, LW_EXCLUSIVE); - dw_recover_file_head(single_cxt, true); - if (!shut_down) { - dw_recovery_partial_write_single(); + /* recovery single flush dw file */ + (void)LWLockAcquire(single_cxt->flush_lock, LW_EXCLUSIVE); + dw_recover_file_head(single_cxt, true); + if (!shut_down) { + dw_recovery_partial_write_single(); + } + /* reset the file after the recovery is complete */ + dw_force_reset_single_file(); + LWLockRelease(single_cxt->flush_lock); } - /* reset the file after the recovery is complete */ - dw_force_reset_single_file(); - LWLockRelease(single_cxt->flush_lock); /* * After recovering partially written pages (if any), we will un-initialize, if the double write is disabled. */ if (!dw_enabled()) { - dw_free_resource(batch_cxt); - dw_free_resource(single_cxt); + if (do_recovery) { + dw_free_resource(batch_cxt); + dw_free_resource(single_cxt); + } (void)MemoryContextSwitchTo(old_mem_cxt); MemoryContextDelete(g_instance.dw_batch_cxt.mem_cxt); ereport(LOG, (errmodule(MOD_DW), errmsg("Double write exit after recovering partial write"))); + + /* remove double file if not needed */ + (void)unlink(DW_FILE_NAME); + (void)unlink(SINGLE_DW_FILE_NAME); } else { (void)MemoryContextSwitchTo(old_mem_cxt); }