From acd5a1e07e79ba5d5c998619ed9dd7433736802e Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Fri, 17 Oct 2014 16:13:32 -0400 Subject: [PATCH] Only garbage collect storage when it might result in something. Return the count of the removed images to fulfill the contract expected by some callers. --- data/model/legacy.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/data/model/legacy.py b/data/model/legacy.py index 791ad3944..12f344681 100644 --- a/data/model/legacy.py +++ b/data/model/legacy.py @@ -1394,6 +1394,13 @@ def garbage_collect_repository(namespace_name, repository_name): logger.info('Cleaning up unreferenced images: %s', to_remove) Image.delete().where(Image.id << list(to_remove)).execute() + if len(storage_id_whitelist) > 0: + garbage_collect_storage(storage_id_whitelist) + + return len(to_remove) + + +def garbage_collect_storage(storage_id_whitelist): # We are going to make the conscious decision to not delete image storage inside the transaction # This may end up producing garbage in s3, trading off for higher availability in the database def placements_query_to_paths_set(placements_query): @@ -1411,6 +1418,7 @@ def garbage_collect_repository(namespace_name, repository_name): .group_by(ImageStorage) .having((fn.Count(Image.id) == 0) & (fn.Count(DerivedImageStorage.id) == 0))) + logger.debug('Garbage collecting storage from candidates: %s', storage_id_whitelist) with config.app_config['DB_TRANSACTION_FACTORY'](db): # Find out which derived storages will be removed, and add them to the whitelist orphaned_from_candidates = orphaned_storage_query(ImageStorage.select(), storage_id_whitelist)