separated network seeding space metrics

This commit is contained in:
Victor Shyba 2021-10-22 00:32:04 -03:00
parent 2ceec7c3d4
commit 95703b3af5
4 changed files with 19 additions and 11 deletions

View file

@ -15,11 +15,11 @@ class DiskSpaceManager:
self.task = None self.task = None
self.analytics = analytics self.analytics = analytics
async def get_space_used_bytes(self): async def get_space_used_bytes(self, is_network_blob=False):
return await self.db.get_stored_blob_disk_usage() return await self.db.get_stored_blob_disk_usage(is_orphan_blob=is_network_blob)
async def get_space_used_mb(self): async def get_space_used_mb(self, is_network_blob=False):
return int(await self.get_space_used_bytes()/1024.0/1024.0) return int(await self.get_space_used_bytes(is_network_blob)/1024.0/1024.0)
async def clean(self): async def clean(self):
space_used_bytes = await self.get_space_used_bytes() space_used_bytes = await self.get_space_used_bytes()

View file

@ -450,9 +450,10 @@ class DiskSpaceComponent(Component):
if self.disk_space_manager: if self.disk_space_manager:
return { return {
'space_used': str(await self.disk_space_manager.get_space_used_mb()), 'space_used': str(await self.disk_space_manager.get_space_used_mb()),
'network_seeding_space_used': str(await self.disk_space_manager.get_space_used_mb(True)),
'running': self.disk_space_manager.running, 'running': self.disk_space_manager.running,
} }
return {'space_used': '0', 'running': False} return {'space_used': '0', 'network_seeding_space_used': '0', 'running': False}
async def start(self): async def start(self):
db = self.component_manager.get_component(DATABASE_COMPONENT) db = self.component_manager.get_component(DATABASE_COMPONENT)

View file

@ -453,11 +453,14 @@ class SQLiteStorage(SQLiteMixin):
) )
return normal_blobs + sd_blobs return normal_blobs + sd_blobs
async def get_stored_blob_disk_usage(self, is_mine: Optional[bool] = None): async def get_stored_blob_disk_usage(self, is_mine: Optional[bool] = None, is_orphan_blob: bool = False):
if is_mine is None: sql = "select coalesce(sum(blob_length), 0) "
sql = "select coalesce(sum(blob_length), 0) from blob join stream_blob using (blob_hash)" if is_orphan_blob:
sql += "from blob left join stream_blob using (blob_hash) where stream_blob.stream_hash is null"
else: else:
sql = "select coalesce(sum(blob_length), 0) from blob join stream_blob using (blob_hash) where is_mine=?" sql += "from blob join stream_blob using (blob_hash)"
if is_mine is not None:
sql += f'{(" and " if is_orphan_blob else " where ")} is_mine=?'
args = (1 if is_mine else 0,) if is_mine is not None else () args = (1 if is_mine else 0,) if is_mine is not None else ()
return (await self.db.execute_fetchone(sql, args))[0] return (await self.db.execute_fetchone(sql, args))[0]

View file

@ -602,25 +602,29 @@ class TestProactiveDownloaderComponent(CommandTestCase):
self.assertEqual(0, len((await self.daemon.jsonrpc_blob_list())['items'])) self.assertEqual(0, len((await self.daemon.jsonrpc_blob_list())['items']))
async def test_ensure_download(self): async def test_ensure_download(self):
content1 = await self.stream_create('content1', '0.01', data=bytes([0] * (2 << 24))) content1 = await self.stream_create('content1', '0.01', data=bytes([0] * 32 * 1024 * 1024))
content1 = content1['outputs'][0]['value']['source']['sd_hash'] content1 = content1['outputs'][0]['value']['source']['sd_hash']
content2 = await self.stream_create('content2', '0.01', data=bytes([0] * (2 << 23))) content2 = await self.stream_create('content2', '0.01', data=bytes([0] * 16 * 1024 * 1024))
content2 = content2['outputs'][0]['value']['source']['sd_hash'] content2 = content2['outputs'][0]['value']['source']['sd_hash']
self.assertEqual('48', (await self.status())['disk_space']['space_used']) self.assertEqual('48', (await self.status())['disk_space']['space_used'])
proactive_downloader = self.daemon.component_manager.get_component(BACKGROUND_DOWNLOADER_COMPONENT) proactive_downloader = self.daemon.component_manager.get_component(BACKGROUND_DOWNLOADER_COMPONENT)
await self.clear() await self.clear()
self.assertEqual('0', (await self.status())['disk_space']['space_used']) self.assertEqual('0', (await self.status())['disk_space']['space_used'])
self.assertEqual('0', (await self.status())['disk_space']['network_seeding_space_used'])
await proactive_downloader.download_blobs(content1) await proactive_downloader.download_blobs(content1)
await self.assertBlobs(content1) await self.assertBlobs(content1)
self.assertEqual('0', (await self.status())['disk_space']['space_used']) self.assertEqual('0', (await self.status())['disk_space']['space_used'])
self.assertEqual('32', (await self.status())['disk_space']['network_seeding_space_used'])
await proactive_downloader.download_blobs(content2) await proactive_downloader.download_blobs(content2)
await self.assertBlobs(content1, content2) await self.assertBlobs(content1, content2)
self.assertEqual('0', (await self.status())['disk_space']['space_used']) self.assertEqual('0', (await self.status())['disk_space']['space_used'])
self.assertEqual('48', (await self.status())['disk_space']['network_seeding_space_used'])
await self.clear() await self.clear()
await proactive_downloader.download_blobs(content2) await proactive_downloader.download_blobs(content2)
await self.assertBlobs(content2) await self.assertBlobs(content2)
self.assertEqual('0', (await self.status())['disk_space']['space_used']) self.assertEqual('0', (await self.status())['disk_space']['space_used'])
self.assertEqual('16', (await self.status())['disk_space']['network_seeding_space_used'])
# tests that an attempt to download something that isn't a sd blob will download the single blob and stop # 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)) blobs = await self.get_blobs_from_sd_blob(self.reflector.blob_manager.get_blob(content1))