From e253f685382efd7fa82849fb5eb4ad803099ca73 Mon Sep 17 00:00:00 2001 From: Venky Shankar Date: Sun, 1 Aug 2021 10:21:46 -0400 Subject: [PATCH] mgr/mirroring: throttle directory reassigment to mirror daemons This is to avoid over-shuffling directories when lots of mirror daemons come and go. Signed-off-by: Venky Shankar --- src/pybind/mgr/mirroring/fs/dir_map/policy.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/mirroring/fs/dir_map/policy.py b/src/pybind/mgr/mirroring/fs/dir_map/policy.py index 608a92bf541..aef90b55fe5 100644 --- a/src/pybind/mgr/mirroring/fs/dir_map/policy.py +++ b/src/pybind/mgr/mirroring/fs/dir_map/policy.py @@ -27,6 +27,10 @@ class DirectoryState: f' purging={self.purging}]' class Policy: + # number of seconds after which a directory can be reshuffled + # to other mirror daemon instances. + DIR_SHUFFLE_THROTTLE_INTERVAL = 300 + def __init__(self): self.dir_states = {} self.instance_to_dir_map = {} @@ -54,7 +58,8 @@ class Policy: """ log.debug(f'can_shuffle_dir: {dir_path}') dir_state = self.dir_states[dir_path] - return StateTransition.is_idle(dir_state.state) + return StateTransition.is_idle(dir_state.state) and \ + (time.time() - dir_state['mapped_time']) > Policy.DIR_SHUFFLE_THROTTLE_INTERVAL def set_state(self, dir_state, state, ignore_current_state=False): if not ignore_current_state and dir_state.state == state: -- 2.39.5