Skip to content

Commit

Permalink
fix and test case for blob_clean after disabling network storage
Browse files Browse the repository at this point in the history
  • Loading branch information
shyba committed Feb 11, 2022
1 parent c96d1d9 commit ac6072e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lbry/blob/disk_space_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,29 @@ async def clean(self):
await self._clean(True)

async def _clean(self, is_network_blob=False):
space_used_bytes = await self.get_space_used_bytes()
space_used_mb = await self.get_space_used_mb(cached=False)
if is_network_blob:
space_used_bytes = space_used_bytes['network_storage']
space_used_mb = space_used_mb['network_storage']
else:
space_used_bytes = space_used_bytes['content_storage'] + space_used_bytes['private_storage']
space_used_mb = space_used_mb['content_storage'] + space_used_mb['private_storage']
storage_limit_mb = self.config.network_storage_limit if is_network_blob else self.config.blob_storage_limit
storage_limit = storage_limit_mb*1024*1024 if storage_limit_mb else None
if self.analytics:
asyncio.create_task(
self.analytics.send_disk_space_used(space_used_bytes, storage_limit, is_network_blob)
self.analytics.send_disk_space_used(space_used_mb, storage_limit_mb, is_network_blob)
)
if not storage_limit:
return 0
delete = []
available = storage_limit - space_used_bytes
if available > 0:
available = storage_limit_mb - space_used_mb
if storage_limit_mb == 0 if not is_network_blob else available >= 0:
return 0
for blob_hash, file_size, _ in await self.db.get_stored_blobs(is_mine=False, is_network_blob=is_network_blob):
delete.append(blob_hash)
available += file_size
if available > 0:
available += int(file_size/1024.0/1024.0)
if available >= 0:
break
if delete:
await self.db.stop_all_files()
await self.blob_manager.delete_blobs(delete, delete_from_db=True)
self._used_space_bytes = None
return len(delete)

async def cleaning_loop(self):
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/datanetwork/test_file_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ async def test_download(self):
self.assertEqual(0, (await self.status())['disk_space']['content_blobs_storage_used_mb'])

background_downloader = BackgroundDownloader(self.daemon.conf, self.daemon.storage, self.daemon.blob_manager)
self.daemon.conf.network_storage_limit = 32
await self.clear()
await self.blob_clean()
self.assertEqual(0, (await self.status())['disk_space']['total_used_mb'])
Expand All @@ -625,6 +626,7 @@ async def test_download(self):
await self.blob_clean()
self.assertEqual(0, (await self.status())['disk_space']['content_blobs_storage_used_mb'])
self.assertEqual(32, (await self.status())['disk_space']['seed_blobs_storage_used_mb'])
self.daemon.conf.network_storage_limit = 48
await background_downloader.download_blobs(content2)
await self.assertBlobs(content1, content2)
await self.blob_clean()
Expand Down Expand Up @@ -654,3 +656,7 @@ async def test_download(self):
self.daemon.conf.blob_storage_limit = 1
await self.blob_clean()
await self.assertBlobs(content1, no_files=False)

self.daemon.conf.network_storage_limit = 0
await self.blob_clean()
self.assertEqual(0, (await self.status())['disk_space']['seed_blobs_storage_used_mb'])

0 comments on commit ac6072e

Please sign in to comment.