do not consider pending blobs on disk space query

This commit is contained in:
Victor Shyba 2022-06-08 11:08:42 -03:00 committed by Lex Berezhny
parent 3c28d869f4
commit 582f79ba1c
2 changed files with 11 additions and 4 deletions

View file

@ -449,7 +449,7 @@ class SQLiteStorage(SQLiteMixin):
return await self.db.execute_fetchall( return await self.db.execute_fetchall(
"select blob.blob_hash, blob.blob_length, blob.added_on " "select blob.blob_hash, blob.blob_length, blob.added_on "
"from blob left join stream_blob using (blob_hash) " "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", "order by blob.blob_length desc, blob.added_on asc",
(is_mine,) (is_mine,)
) )
@ -463,7 +463,8 @@ class SQLiteStorage(SQLiteMixin):
content_blobs = await self.db.execute_fetchall( content_blobs = await self.db.execute_fetchall(
"select blob.blob_hash, blob.blob_length, blob.added_on " "select blob.blob_hash, blob.blob_length, blob.added_on "
"from blob join stream_blob using (blob_hash) cross join stream using (stream_hash)" "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,) (is_mine,)
) )
return content_blobs + sd_blobs return content_blobs + sd_blobs
@ -480,7 +481,8 @@ class SQLiteStorage(SQLiteMixin):
coalesce(sum(case when coalesce(sum(case when
is_mine=1 is_mine=1
then blob_length else 0 end), 0) as private_storage 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 { return {
'network_storage': network_size, 'network_storage': network_size,

View file

@ -599,13 +599,18 @@ class DiskSpaceManagement(CommandTestCase):
self.assertTrue(blobs2.issubset(blobs)) self.assertTrue(blobs2.issubset(blobs))
self.assertFalse(blobs3.issubset(blobs)) self.assertFalse(blobs3.issubset(blobs))
self.assertTrue(blobs4.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) # 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")) 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_file_delete(delete_all=True)
await self.daemon.jsonrpc_get("foo4", save_file=False) 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")) self.assertLess(0, await self.daemon.storage.run_and_return_one_or_none("select min(added_on) from blob"))
class TestBackgroundDownloaderComponent(CommandTestCase): class TestBackgroundDownloaderComponent(CommandTestCase):
async def get_blobs_from_sd_blob(self, sd_blob): async def get_blobs_from_sd_blob(self, sd_blob):
descriptor = await StreamDescriptor.from_stream_descriptor_blob( descriptor = await StreamDescriptor.from_stream_descriptor_blob(