Fixed a bug in disk free space calculation

This commit is contained in:
Takeshi Nakatani
2021-07-17 10:17:38 +00:00
committed by Andrew Gaul
parent 7890989cbb
commit 199b3d4709
3 changed files with 18 additions and 6 deletions

View File

@ -1557,7 +1557,7 @@ int FdEntity::RowFlushMixMultipart(PseudoFdInfo* pseudo_obj, const char* tpath)
// Start uploading
// If there is no loading all of the area, loading all area.
off_t restsize = pagelist.GetTotalUnloadedPageSize();
off_t restsize = pagelist.GetTotalUnloadedPageSize(/* start */ 0, /* size = all */ 0, MIN_MULTIPART_SIZE);
// Check rest size and free disk space
if(0 < restsize && !ReserveDiskSpace(restsize)){
@ -1974,7 +1974,7 @@ ssize_t FdEntity::WriteMixMultipart(PseudoFdInfo* pseudo_obj, const char* bytes,
if(!pseudo_obj->IsUploading()){
// check disk space
off_t restsize = pagelist.GetTotalUnloadedPageSize(0, start) + size;
off_t restsize = pagelist.GetTotalUnloadedPageSize(0, start, MIN_MULTIPART_SIZE) + size;
if(ReserveDiskSpace(restsize)){
// enough disk space
FdManager::FreeReservedDiskSpace(restsize);

View File

@ -509,10 +509,20 @@ bool PageList::FindUnloadedPage(off_t start, off_t& resstart, off_t& ressize) co
return false;
}
off_t PageList::GetTotalUnloadedPageSize(off_t start, off_t size) const
// [NOTE]
// Accumulates the range of unload that is smaller than the Limit size.
// If you want to integrate all unload ranges, set the limit size to 0.
//
off_t PageList::GetTotalUnloadedPageSize(off_t start, off_t size, off_t limit_size) const
{
off_t restsize = 0;
// If size is 0, it means loading to end.
if(0 == size){
if(start < Size()){
size = Size() - start;
}
}
off_t next = start + size;
off_t restsize = 0;
for(fdpage_list_t::const_iterator iter = pages.begin(); iter != pages.end(); ++iter){
if(iter->next() <= start){
continue;
@ -537,7 +547,9 @@ off_t PageList::GetTotalUnloadedPageSize(off_t start, off_t size) const
tmpsize = next - iter->offset;
}
}
restsize += tmpsize;
if(0 == limit_size || tmpsize < limit_size){
restsize += tmpsize;
}
}
return restsize;
}

View File

@ -106,7 +106,7 @@ class PageList
bool IsPageLoaded(off_t start = 0, off_t size = 0) const; // size=0 is checking to end of list
bool SetPageLoadedStatus(off_t start, off_t size, PageList::page_status pstatus = PAGE_LOADED, bool is_compress = true);
bool FindUnloadedPage(off_t start, off_t& resstart, off_t& ressize) const;
off_t GetTotalUnloadedPageSize(off_t start = 0, off_t size = 0) const; // size=0 is checking to end of list
off_t GetTotalUnloadedPageSize(off_t start = 0, off_t size = 0, off_t limit_size = 0) const; // size=0 is checking to end of list
size_t GetUnloadedPages(fdpage_list_t& unloaded_list, off_t start = 0, off_t size = 0) const; // size=0 is checking to end of list
bool GetPageListsForMultipartUpload(fdpage_list_t& dlpages, fdpage_list_t& mixuppages, off_t max_partsize);
bool GetNoDataPageLists(fdpage_list_t& nodata_pages, off_t start = 0, size_t size = 0);