Skip to content

Commit d80b751

Browse files
authored
DL: delete full files for when subscribed to a datastore per config (#16850)
1 parent 3caa075 commit d80b751

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

chia/data_layer/data_layer.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,17 @@ async def get_downloader(self, tree_id: bytes32, url: str) -> Optional[PluginRem
513513
self.log.error(f"get_downloader could not get response: {type(e).__name__}: {e}")
514514
return None
515515

516-
async def clean_old_full_tree_files(
517-
self, foldername: Path, tree_id: bytes32, full_tree_first_publish_generation: int
518-
) -> None:
516+
async def clean_old_full_tree_files(self, tree_id: bytes32) -> None:
517+
singleton_record: Optional[SingletonRecord] = await self.wallet_rpc.dl_latest_singleton(tree_id, True)
518+
if singleton_record is None:
519+
return
520+
await self._update_confirmation_status(tree_id=tree_id)
521+
522+
root = await self.data_store.get_tree_root(tree_id=tree_id)
523+
latest_generation = root.generation
524+
full_tree_first_publish_generation = max(0, latest_generation - self.maximum_full_file_count + 1)
525+
foldername = self.server_files_location
526+
519527
for generation in range(full_tree_first_publish_generation - 1, 0, -1):
520528
root = await self.data_store.get_tree_root(tree_id=tree_id, generation=generation)
521529
file_exists = delete_full_file_if_exists(foldername, tree_id, root)
@@ -576,11 +584,6 @@ async def upload_files(self, tree_id: bytes32) -> None:
576584
self.log.error(
577585
f"Failed to upload files to, will retry later: {uploader} : {res_json}"
578586
)
579-
await self.clean_old_full_tree_files(
580-
self.server_files_location,
581-
tree_id,
582-
full_tree_first_publish_generation,
583-
)
584587
except Exception as e:
585588
self.log.error(f"Exception uploading files, will retry later: tree id {tree_id}")
586589
self.log.debug(f"Failed to upload files, cleaning local files: {type(e).__name__}: {e}")
@@ -740,6 +743,7 @@ async def periodically_manage_data(self) -> None:
740743
await self.update_subscriptions_from_wallet(subscription.tree_id)
741744
await self.fetch_and_validate(subscription.tree_id)
742745
await self.upload_files(subscription.tree_id)
746+
await self.clean_old_full_tree_files(subscription.tree_id)
743747
except Exception as e:
744748
self.log.error(f"Exception while fetching data: {type(e)} {e} {traceback.format_exc()}.")
745749

0 commit comments

Comments
 (0)