Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-23620] Destroy temp file in tempcache when temp volume is full #5524

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/storage/disk_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
77 changes: 76 additions & 1 deletion src/storage/file_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -8535,12 +8536,23 @@ 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)
{
if (file_tempcache_find_victim_and_destroy (thread_p, FILE_IS_NUMERABLE (fhead)))
{
goto retry;
}
if (file_tempcache_find_victim_and_destroy (thread_p, !FILE_IS_NUMERABLE (fhead)))
{
goto retry;
}
}
assert_release (false);
goto exit;
}
Expand Down Expand Up @@ -9606,6 +9618,69 @@ 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)
{
FILE_TEMPCACHE_ENTRY *victim;

file_tempcache_lock ();
if (is_numerable)
{
if (file_Tempcache.ncached_numerable > 0)
{
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 = 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)
{
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 = victim->next;
file_Tempcache.ncached_not_numerable--;
file_tempcache_unlock ();

file_tempcache_retire_entry (victim);
return true;
}

file_tempcache_unlock ();
return false;
}
}

/************************************************************************/
/* File tracker section */
/************************************************************************/
Expand Down
Loading