fix free space calculation, test it and give a margin of 10mb before starting so it doesnt insist when full
This commit is contained in:
parent
510b44ca92
commit
3a83052f2e
3 changed files with 6 additions and 3 deletions
|
@ -15,9 +15,9 @@ class DiskSpaceManager:
|
|||
self.task = None
|
||||
self.analytics = analytics
|
||||
|
||||
async def get_free_space_bytes(self, is_network_blob=False):
|
||||
async def get_free_space_mb(self, is_network_blob=False):
|
||||
limit_mb = self.config.network_storage_limit if is_network_blob else self.config.blob_storage_limit
|
||||
return max(0, limit_mb*1024*1024 - (await self.get_space_used_mb(is_network_blob)))
|
||||
return max(0, limit_mb - (await self.get_space_used_mb(is_network_blob)))
|
||||
|
||||
async def get_space_used_bytes(self, is_network_blob=False):
|
||||
return await self.db.get_stored_blob_disk_usage(is_network_blob=is_network_blob)
|
||||
|
|
|
@ -403,11 +403,12 @@ class BackgroundDownloaderComponent(Component):
|
|||
|
||||
async def get_status(self):
|
||||
return {'running': self.task is not None and not self.task.done(),
|
||||
'available_free_space': await self.space_manager.get_free_space_mb(True),
|
||||
'ongoing_download': self.is_busy}
|
||||
|
||||
async def loop(self):
|
||||
while True:
|
||||
if not self.is_busy and await self.space_manager.get_free_space_bytes(True) > 0:
|
||||
if not self.is_busy and await self.space_manager.get_free_space_mb(True) > 10:
|
||||
blob_hash = self.dht_node.last_requested_blob_hash
|
||||
if blob_hash:
|
||||
self.ongoing_download = asyncio.create_task(self.background_downloader.download_blobs(blob_hash))
|
||||
|
|
|
@ -629,6 +629,8 @@ class TestProactiveDownloaderComponent(CommandTestCase):
|
|||
await self.assertBlobs(content2)
|
||||
self.assertEqual('0', (await self.status())['disk_space']['space_used'])
|
||||
self.assertEqual('16', (await self.status())['disk_space']['network_seeding_space_used'])
|
||||
self.daemon.conf.network_storage_limit = 100
|
||||
self.assertEqual(84, (await self.status())['background_downloader']['available_free_space'])
|
||||
|
||||
# tests that an attempt to download something that isn't a sd blob will download the single blob and stop
|
||||
blobs = await self.get_blobs_from_sd_blob(self.reflector.blob_manager.get_blob(content1))
|
||||
|
|
Loading…
Reference in a new issue