Merge "Clean up caches periodically"

This commit is contained in:
Zuul 2021-09-24 00:21:07 +00:00 committed by Gerrit Code Review
commit 143449d3db
4 changed files with 23 additions and 0 deletions

View File

@ -72,6 +72,7 @@ from ironic.conductor import utils
from ironic.conductor import verify
from ironic.conf import CONF
from ironic.drivers import base as drivers_base
from ironic.drivers.modules import image_cache
from ironic import objects
from ironic.objects import base as objects_base
from ironic.objects import fields
@ -100,6 +101,12 @@ class ConductorManager(base_manager.BaseConductorManager):
super(ConductorManager, self).__init__(host, topic)
self.power_state_sync_count = collections.defaultdict(int)
@METRICS.timer('ConductorManager._clean_up_caches')
@periodics.periodic(spacing=CONF.conductor.cache_clean_up_interval,
enabled=CONF.conductor.cache_clean_up_interval > 0)
def _clean_up_caches(self, context):
image_cache.clean_up_all()
@METRICS.timer('ConductorManager.create_node')
# No need to add these since they are subclasses of InvalidParameterValue:
# InterfaceNotFoundInEntrypoint

View File

@ -59,6 +59,10 @@ opts = [
min=0,
help=_('Interval between checks of orphaned allocations, '
'in seconds. Set to 0 to disable checks.')),
cfg.IntOpt('cache_clean_up_interval',
default=3600, min=0,
help=_('Interval between cleaning up image caches, in seconds. '
'Set to 0 to disable periodic clean-up.')),
cfg.IntOpt('deploy_callback_timeout',
default=1800,
min=0,

View File

@ -393,6 +393,13 @@ def clean_up_caches(ctx, directory, images_info):
_clean_up_caches(directory, total_size)
def clean_up_all():
"""Clean up all entries from all caches."""
caches_to_clean = [x[1]() for x in _cache_cleanup_list]
for cache in caches_to_clean:
cache.clean_up()
def cleanup(priority):
"""Decorator method for adding cleanup priority to a class."""
def _add_property_to_class_func(cls):

View File

@ -0,0 +1,5 @@
---
features:
- |
All image caches are now cleaned up periodically, not only when used.
Set ``[conductor]cache_clean_up_interval`` to tune the interval or disable.