Skip to content

Commit

Permalink
do not consider pending blobs on disk space query
Browse files Browse the repository at this point in the history
  • Loading branch information
shyba authored and eukreign committed Jun 8, 2022
1 parent 3c28d86 commit 582f79b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lbry/extras/daemon/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ async def get_stored_blobs(self, is_mine: bool, is_network_blob=False):
return await self.db.execute_fetchall(
"select blob.blob_hash, blob.blob_length, blob.added_on "
"from blob left join stream_blob using (blob_hash) "
"where stream_blob.stream_hash is null and blob.is_mine=? "
"where stream_blob.stream_hash is null and blob.is_mine=? and blob.status='finished'"
"order by blob.blob_length desc, blob.added_on asc",
(is_mine,)
)
Expand All @@ -463,7 +463,8 @@ async def get_stored_blobs(self, is_mine: bool, is_network_blob=False):
content_blobs = await self.db.execute_fetchall(
"select blob.blob_hash, blob.blob_length, blob.added_on "
"from blob join stream_blob using (blob_hash) cross join stream using (stream_hash)"
"cross join file using (stream_hash) where blob.is_mine=? order by blob.added_on asc, blob.blob_length asc",
"cross join file using (stream_hash)"
"where blob.is_mine=? and blob.status='finished' order by blob.added_on asc, blob.blob_length asc",
(is_mine,)
)
return content_blobs + sd_blobs
Expand All @@ -480,7 +481,8 @@ async def get_stored_blob_disk_usage(self):
coalesce(sum(case when
is_mine=1
then blob_length else 0 end), 0) as private_storage
from blob left join stream_blob using (blob_hash) where blob_hash not in (select sd_hash from stream)
from blob left join stream_blob using (blob_hash)
where blob_hash not in (select sd_hash from stream) and blob.status="finished"
""")
return {
'network_storage': network_size,
Expand Down
7 changes: 6 additions & 1 deletion tests/integration/datanetwork/test_file_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,13 +599,18 @@ async def test_file_management(self):
self.assertTrue(blobs2.issubset(blobs))
self.assertFalse(blobs3.issubset(blobs))
self.assertTrue(blobs4.issubset(blobs))
# check that pending blobs are not accounted (#3617)
await self.daemon.storage.db.execute_fetchall("update blob set status='pending'")
await self.blob_clean() # just to refresh caches, has no effect
self.assertEqual(0, (await self.status())['disk_space']['total_used_mb'])
self.assertEqual(0, (await self.status())['disk_space']['content_blobs_storage_used_mb'])
self.assertEqual(0, (await self.status())['disk_space']['published_blobs_storage_used_mb'])
# check that added_on gets set on downloads (was a bug)
self.assertLess(0, await self.daemon.storage.run_and_return_one_or_none("select min(added_on) from blob"))
await self.daemon.jsonrpc_file_delete(delete_all=True)
await self.daemon.jsonrpc_get("foo4", save_file=False)
self.assertLess(0, await self.daemon.storage.run_and_return_one_or_none("select min(added_on) from blob"))


class TestBackgroundDownloaderComponent(CommandTestCase):
async def get_blobs_from_sd_blob(self, sd_blob):
descriptor = await StreamDescriptor.from_stream_descriptor_blob(
Expand Down

0 comments on commit 582f79b

Please sign in to comment.