From 8355065f085c5cbbccff7061538c0ac34d148bdf Mon Sep 17 00:00:00 2001 From: yjlee Date: Mon, 30 Sep 2024 12:56:34 +0900 Subject: [PATCH 1/5] Destroy temp file in tempcache when temp volume is full --- src/storage/disk_manager.c | 4 ++-- src/storage/file_manager.c | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/storage/disk_manager.c b/src/storage/disk_manager.c index 05dbf66a44..3e4ccb31a0 100644 --- a/src/storage/disk_manager.c +++ b/src/storage/disk_manager.c @@ -4276,8 +4276,8 @@ disk_reserve_sectors (THREAD_ENTRY * thread_p, DB_VOLPURPOSE purpose, VOLID voli log_sysop_abort (thread_p); if (error_code == ER_INTERRUPTED /* interrupted error */ - || error_code == ER_IO_MOUNT_FAIL || error_code == ER_IO_FORMAT_OUT_OF_SPACE || error_code == ER_IO_WRITE - || error_code == ER_BO_CANNOT_CREATE_VOL /* IO errors */ ) + || error_code == ER_IO_MOUNT_FAIL || error_code == ER_IO_FORMAT_OUT_OF_SPACE || error_code == ER_IO_WRITE || error_code == ER_BO_CANNOT_CREATE_VOL /* IO errors */ + || error_code == ER_BO_MAXTEMP_SPACE_HAS_BEEN_EXCEEDED /* temp volume is full */ ) { /* this is expected. */ return error_code; diff --git a/src/storage/file_manager.c b/src/storage/file_manager.c index 39fa648ded..19df88bc14 100644 --- a/src/storage/file_manager.c +++ b/src/storage/file_manager.c @@ -8535,12 +8535,46 @@ file_temp_alloc (THREAD_ENTRY * thread_p, PAGE_PTR page_fhead, FILE_ALLOC_TYPE a { /* expand file by one sector */ FILE_PARTIAL_SECTOR partsect_new = FILE_PARTIAL_SECTOR_INITIALIZER; - + retry: /* reserve a sector */ error_code = disk_reserve_sectors (thread_p, DB_TEMPORARY_DATA_PURPOSE, fhead->volid_last_expand, 1, &partsect_new.vsid); if (error_code != NO_ERROR) { + if (error_code == ER_BO_MAXTEMP_SPACE_HAS_BEEN_EXCEEDED) + { + file_tempcache_lock (); + if (file_Tempcache.ncached_numerable > 0) + { + if (file_destroy (thread_p, &file_Tempcache.cached_numerable->vfid, true) != NO_ERROR) + { + file_tempcache_unlock (); + assert_release (false); + goto exit; + } + file_Tempcache.cached_numerable = file_Tempcache.cached_numerable->next; + file_Tempcache.ncached_numerable--; + + file_tempcache_unlock (); + goto retry; + } + else if (file_Tempcache.ncached_not_numerable > 0) + { + if (file_destroy (thread_p, &file_Tempcache.cached_not_numerable->vfid, true) != NO_ERROR) + { + file_tempcache_unlock (); + assert_release (false); + goto exit; + } + file_Tempcache.cached_not_numerable = file_Tempcache.cached_not_numerable->next; + file_Tempcache.ncached_not_numerable--; + + file_tempcache_unlock (); + goto retry; + } + file_tempcache_unlock (); + } + assert_release (false); goto exit; } From c26c95ce13f02f7dc332be52a2da9f8ab80c20fd Mon Sep 17 00:00:00 2001 From: yjlee Date: Mon, 30 Sep 2024 13:26:58 +0900 Subject: [PATCH 2/5] Delete assertion --- src/storage/disk_manager.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/storage/disk_manager.c b/src/storage/disk_manager.c index 3e4ccb31a0..598794a1a4 100644 --- a/src/storage/disk_manager.c +++ b/src/storage/disk_manager.c @@ -4361,7 +4361,6 @@ disk_reserve_from_cache (THREAD_ENTRY * thread_p, DISK_RESERVE_CONTEXT * context >= disk_Temp_max_sects) { /* too much temporary space */ - assert (false); er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_BO_MAXTEMP_SPACE_HAS_BEEN_EXCEEDED, 1, disk_Temp_max_sects); disk_cache_unlock_reserve_for_purpose (context->purpose); return ER_BO_MAXTEMP_SPACE_HAS_BEEN_EXCEEDED; From 9cd46088d587ba245e2ddf71c8a705bf5d54b46c Mon Sep 17 00:00:00 2001 From: yjlee Date: Fri, 4 Oct 2024 13:21:09 +0900 Subject: [PATCH 3/5] Destroy non numerable temp file first --- src/storage/file_manager.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/storage/file_manager.c b/src/storage/file_manager.c index 19df88bc14..951c8a35c4 100644 --- a/src/storage/file_manager.c +++ b/src/storage/file_manager.c @@ -8544,30 +8544,30 @@ file_temp_alloc (THREAD_ENTRY * thread_p, PAGE_PTR page_fhead, FILE_ALLOC_TYPE a if (error_code == ER_BO_MAXTEMP_SPACE_HAS_BEEN_EXCEEDED) { file_tempcache_lock (); - if (file_Tempcache.ncached_numerable > 0) + if (file_Tempcache.ncached_not_numerable > 0) { - if (file_destroy (thread_p, &file_Tempcache.cached_numerable->vfid, true) != NO_ERROR) + if (file_destroy (thread_p, &file_Tempcache.cached_not_numerable->vfid, true) != NO_ERROR) { file_tempcache_unlock (); assert_release (false); goto exit; } - file_Tempcache.cached_numerable = file_Tempcache.cached_numerable->next; - file_Tempcache.ncached_numerable--; + file_Tempcache.cached_not_numerable = file_Tempcache.cached_not_numerable->next; + file_Tempcache.ncached_not_numerable--; file_tempcache_unlock (); goto retry; } - else if (file_Tempcache.ncached_not_numerable > 0) + else if (file_Tempcache.ncached_numerable > 0) { - if (file_destroy (thread_p, &file_Tempcache.cached_not_numerable->vfid, true) != NO_ERROR) + if (file_destroy (thread_p, &file_Tempcache.cached_numerable->vfid, true) != NO_ERROR) { file_tempcache_unlock (); assert_release (false); goto exit; } - file_Tempcache.cached_not_numerable = file_Tempcache.cached_not_numerable->next; - file_Tempcache.ncached_not_numerable--; + file_Tempcache.cached_numerable = file_Tempcache.cached_numerable->next; + file_Tempcache.ncached_numerable--; file_tempcache_unlock (); goto retry; From 33804838662c18e8c0121a83c92b5db7d73d900a Mon Sep 17 00:00:00 2001 From: yjlee Date: Fri, 11 Oct 2024 16:47:48 +0900 Subject: [PATCH 4/5] Create file_tempcache_find_victim_and_destroy function --- src/storage/file_manager.c | 73 +++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/src/storage/file_manager.c b/src/storage/file_manager.c index 951c8a35c4..d90ec38a14 100644 --- a/src/storage/file_manager.c +++ b/src/storage/file_manager.c @@ -798,6 +798,7 @@ STATIC_INLINE FILE_TEMPCACHE_ENTRY *file_tempcache_pop_tran_file (THREAD_ENTRY * STATIC_INLINE void file_tempcache_push_tran_file (THREAD_ENTRY * thread_p, FILE_TEMPCACHE_ENTRY * entry) __attribute__ ((ALWAYS_INLINE)); STATIC_INLINE void file_tempcache_dump (FILE * fp) __attribute__ ((ALWAYS_INLINE)); +STATIC_INLINE bool file_tempcache_find_victim_and_destroy (THREAD_ENTRY * thread_p, bool is_numerable); /************************************************************************/ /* File tracker section */ @@ -8544,37 +8545,21 @@ file_temp_alloc (THREAD_ENTRY * thread_p, PAGE_PTR page_fhead, FILE_ALLOC_TYPE a if (error_code == ER_BO_MAXTEMP_SPACE_HAS_BEEN_EXCEEDED) { file_tempcache_lock (); - if (file_Tempcache.ncached_not_numerable > 0) - { - if (file_destroy (thread_p, &file_Tempcache.cached_not_numerable->vfid, true) != NO_ERROR) - { - file_tempcache_unlock (); - assert_release (false); - goto exit; - } - file_Tempcache.cached_not_numerable = file_Tempcache.cached_not_numerable->next; - file_Tempcache.ncached_not_numerable--; + if (file_tempcache_find_victim_and_destroy (thread_p, FILE_IS_NUMERABLE (fhead))) + { file_tempcache_unlock (); goto retry; } - else if (file_Tempcache.ncached_numerable > 0) - { - if (file_destroy (thread_p, &file_Tempcache.cached_numerable->vfid, true) != NO_ERROR) - { - file_tempcache_unlock (); - assert_release (false); - goto exit; - } - file_Tempcache.cached_numerable = file_Tempcache.cached_numerable->next; - file_Tempcache.ncached_numerable--; + if (file_tempcache_find_victim_and_destroy (thread_p, !FILE_IS_NUMERABLE (fhead))) + { file_tempcache_unlock (); goto retry; } + file_tempcache_unlock (); } - assert_release (false); goto exit; } @@ -9640,6 +9625,52 @@ file_tempcache_dump (FILE * fp) * manages its own list freely. */ } +/* + * file_tempcache_find_victim_and_destroy () - find a victim temp file from tempcache and destroy it + * + * return : true if a temp file was destroyed, false otherwise + * thread_p (in) : thread entry + * is_numerable (in) : true if numerable file is to be destroyed, false otherwise + */ +STATIC_INLINE bool +file_tempcache_find_victim_and_destroy (THREAD_ENTRY * thread_p, bool is_numerable) +{ + if (is_numerable) + { + if (file_Tempcache.ncached_numerable > 0) + { + if (file_destroy (thread_p, &file_Tempcache.cached_numerable->vfid, true) != NO_ERROR) + { + assert (false); + return false; + } + + file_Tempcache.cached_numerable = file_Tempcache.cached_numerable->next; + file_Tempcache.ncached_numerable--; + return true; + } + + return false; + } + else + { + if (file_Tempcache.ncached_not_numerable > 0) + { + if (file_destroy (thread_p, &file_Tempcache.cached_not_numerable->vfid, true) != NO_ERROR) + { + assert (false); + return false; + } + + file_Tempcache.cached_not_numerable = file_Tempcache.cached_not_numerable->next; + file_Tempcache.ncached_not_numerable--; + return true; + } + + return false; + } +} + /************************************************************************/ /* File tracker section */ /************************************************************************/ From 930c35599b47f9ce06c03cce06a2c686e278274e Mon Sep 17 00:00:00 2001 From: yjlee Date: Mon, 14 Oct 2024 11:27:38 +0900 Subject: [PATCH 5/5] Retire tempcache entry that is destroyed --- src/storage/file_manager.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/storage/file_manager.c b/src/storage/file_manager.c index d90ec38a14..3896e917a8 100644 --- a/src/storage/file_manager.c +++ b/src/storage/file_manager.c @@ -8544,21 +8544,14 @@ file_temp_alloc (THREAD_ENTRY * thread_p, PAGE_PTR page_fhead, FILE_ALLOC_TYPE a { if (error_code == ER_BO_MAXTEMP_SPACE_HAS_BEEN_EXCEEDED) { - file_tempcache_lock (); - if (file_tempcache_find_victim_and_destroy (thread_p, FILE_IS_NUMERABLE (fhead))) { - file_tempcache_unlock (); goto retry; } - if (file_tempcache_find_victim_and_destroy (thread_p, !FILE_IS_NUMERABLE (fhead))) { - file_tempcache_unlock (); goto retry; } - - file_tempcache_unlock (); } assert_release (false); goto exit; @@ -9635,38 +9628,55 @@ file_tempcache_dump (FILE * fp) STATIC_INLINE bool file_tempcache_find_victim_and_destroy (THREAD_ENTRY * thread_p, bool is_numerable) { + FILE_TEMPCACHE_ENTRY *victim; + + file_tempcache_lock (); if (is_numerable) { if (file_Tempcache.ncached_numerable > 0) { - if (file_destroy (thread_p, &file_Tempcache.cached_numerable->vfid, true) != NO_ERROR) + victim = file_Tempcache.cached_numerable; + + if (file_destroy (thread_p, &victim->vfid, true) != NO_ERROR) { + file_tempcache_unlock (); assert (false); return false; } - file_Tempcache.cached_numerable = file_Tempcache.cached_numerable->next; + file_Tempcache.cached_numerable = victim->next; file_Tempcache.ncached_numerable--; + file_tempcache_unlock (); + + file_tempcache_retire_entry (victim); return true; } + file_tempcache_unlock (); return false; } else { if (file_Tempcache.ncached_not_numerable > 0) { - if (file_destroy (thread_p, &file_Tempcache.cached_not_numerable->vfid, true) != NO_ERROR) + victim = file_Tempcache.cached_not_numerable; + + if (file_destroy (thread_p, &victim->vfid, true) != NO_ERROR) { + file_tempcache_unlock (); assert (false); return false; } - file_Tempcache.cached_not_numerable = file_Tempcache.cached_not_numerable->next; + file_Tempcache.cached_not_numerable = victim->next; file_Tempcache.ncached_not_numerable--; + file_tempcache_unlock (); + + file_tempcache_retire_entry (victim); return true; } + file_tempcache_unlock (); return false; } }