@ -841,7 +841,7 @@ static void dw_free_resource(knl_g_dw_context *cxt)
|
|||||||
cxt->closed = 1;
|
cxt->closed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dw_file_check_and_rebuild()
|
bool dw_file_check_and_rebuild()
|
||||||
{
|
{
|
||||||
if (file_exists(DW_BUILD_FILE_NAME)) {
|
if (file_exists(DW_BUILD_FILE_NAME)) {
|
||||||
ereport(LOG, (errmodule(MOD_DW), errmsg("Double write initializing after build")));
|
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. */
|
/* Create the DW file. */
|
||||||
dw_bootstrap();
|
if (dw_enabled()) {
|
||||||
|
dw_bootstrap();
|
||||||
|
}
|
||||||
|
|
||||||
/* Remove the DW build file. */
|
/* Remove the DW build file. */
|
||||||
if (unlink(DW_BUILD_FILE_NAME) != 0) {
|
if (unlink(DW_BUILD_FILE_NAME) != 0) {
|
||||||
@ -882,26 +884,28 @@ void dw_file_check_and_rebuild()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_exists(DW_FILE_NAME)) {
|
if (!file_exists(DW_FILE_NAME) && dw_enabled()) {
|
||||||
ereport(PANIC, (errcode_for_file_access(), errmodule(MOD_DW), errmsg("batch flush DW file does not exist")));
|
/* Create the batch file. */
|
||||||
|
dw_generate_batch_file();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t_thrd.proc->workingVersionNum >= DW_SUPPORT_SINGLE_FLUSH_VERSION) {
|
if (t_thrd.proc->workingVersionNum >= DW_SUPPORT_SINGLE_FLUSH_VERSION) {
|
||||||
if (!file_exists(SINGLE_DW_FILE_NAME)) {
|
if (!file_exists(SINGLE_DW_FILE_NAME) && dw_enabled()) {
|
||||||
ereport(PANIC, (errcode_for_file_access(),
|
/* Create the single file. */
|
||||||
errmodule(MOD_DW), errmsg("single flush DW file does not exist")));
|
dw_generate_single_file();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!file_exists(SINGLE_DW_FILE_NAME)) {
|
if (!file_exists(SINGLE_DW_FILE_NAME)) {
|
||||||
ereport(LOG, (errmodule(MOD_DW),
|
ereport(LOG, (errmodule(MOD_DW),
|
||||||
errmsg("first upgrade to DW_SUPPORT_SINGLE_FLUSH_VERSION, need init the single file")));
|
errmsg("first upgrade to DW_SUPPORT_SINGLE_FLUSH_VERSION, need init the single file")));
|
||||||
dw_generate_single_file();
|
|
||||||
} else {
|
} else {
|
||||||
(void)unlink(SINGLE_DW_FILE_NAME);
|
(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()
|
const void init_dw_single_flush_map()
|
||||||
@ -1014,38 +1018,46 @@ void dw_init(bool shut_down)
|
|||||||
|
|
||||||
old_mem_cxt = MemoryContextSwitchTo(mem_cxt);
|
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")));
|
ereport(LOG, (errmodule(MOD_DW), errmsg("Double Write init")));
|
||||||
|
|
||||||
dw_cxt_init_batch();
|
if (do_recovery) {
|
||||||
dw_cxt_init_single();
|
dw_cxt_init_batch();
|
||||||
|
dw_cxt_init_single();
|
||||||
|
|
||||||
/* recovery batch flush dw file */
|
/* recovery batch flush dw file */
|
||||||
(void)LWLockAcquire(batch_cxt->flush_lock, LW_EXCLUSIVE);
|
(void)LWLockAcquire(batch_cxt->flush_lock, LW_EXCLUSIVE);
|
||||||
dw_recover_file_head(batch_cxt, false);
|
dw_recover_file_head(batch_cxt, false);
|
||||||
|
|
||||||
dw_recover_partial_write(batch_cxt);
|
dw_recover_partial_write(batch_cxt);
|
||||||
LWLockRelease(batch_cxt->flush_lock);
|
LWLockRelease(batch_cxt->flush_lock);
|
||||||
|
|
||||||
/* recovery single flush dw file */
|
/* recovery single flush dw file */
|
||||||
(void)LWLockAcquire(single_cxt->flush_lock, LW_EXCLUSIVE);
|
(void)LWLockAcquire(single_cxt->flush_lock, LW_EXCLUSIVE);
|
||||||
dw_recover_file_head(single_cxt, true);
|
dw_recover_file_head(single_cxt, true);
|
||||||
if (!shut_down) {
|
if (!shut_down) {
|
||||||
dw_recovery_partial_write_single();
|
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.
|
* After recovering partially written pages (if any), we will un-initialize, if the double write is disabled.
|
||||||
*/
|
*/
|
||||||
if (!dw_enabled()) {
|
if (!dw_enabled()) {
|
||||||
dw_free_resource(batch_cxt);
|
if (do_recovery) {
|
||||||
dw_free_resource(single_cxt);
|
dw_free_resource(batch_cxt);
|
||||||
|
dw_free_resource(single_cxt);
|
||||||
|
}
|
||||||
(void)MemoryContextSwitchTo(old_mem_cxt);
|
(void)MemoryContextSwitchTo(old_mem_cxt);
|
||||||
MemoryContextDelete(g_instance.dw_batch_cxt.mem_cxt);
|
MemoryContextDelete(g_instance.dw_batch_cxt.mem_cxt);
|
||||||
ereport(LOG, (errmodule(MOD_DW), errmsg("Double write exit after recovering partial write")));
|
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 {
|
} else {
|
||||||
(void)MemoryContextSwitchTo(old_mem_cxt);
|
(void)MemoryContextSwitchTo(old_mem_cxt);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user