From: Ilya Dryomov Date: Fri, 17 Jun 2022 08:28:55 +0000 (+0200) Subject: mgr/rbd_support: refresh schedule queue immediately after delay elapses X-Git-Tag: v18.0.0~653^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=ef3edd399adc99f3ff2acf580727d3dd5439d862;p=ceph.git mgr/rbd_support: refresh schedule queue immediately after delay elapses The existing logic often leads to refresh_pools() and refresh_images() being invoked after a 120 second delay instead of after an intended 60 second delay. Signed-off-by: Ilya Dryomov --- diff --git a/src/pybind/mgr/rbd_support/mirror_snapshot_schedule.py b/src/pybind/mgr/rbd_support/mirror_snapshot_schedule.py index 013b210266bd9..ffcd357d2ed17 100644 --- a/src/pybind/mgr/rbd_support/mirror_snapshot_schedule.py +++ b/src/pybind/mgr/rbd_support/mirror_snapshot_schedule.py @@ -446,6 +446,7 @@ class MirrorSnapshotScheduleHandler: MODULE_OPTION_NAME = "mirror_snapshot_schedule" MODULE_OPTION_NAME_MAX_CONCURRENT_SNAP_CREATE = "max_concurrent_snap_create" SCHEDULE_OID = "rbd_mirror_snapshot_schedule" + REFRESH_DELAY_SECONDS = 60.0 lock = Lock() condition = Condition(lock) @@ -470,11 +471,11 @@ class MirrorSnapshotScheduleHandler: try: self.log.info("MirrorSnapshotScheduleHandler: starting") while True: - self.refresh_images() + refresh_delay = self.refresh_images() with self.lock: (image_spec, wait_time) = self.dequeue() if not image_spec: - self.condition.wait(min(wait_time, 60)) + self.condition.wait(min(wait_time, refresh_delay)) continue pool_id, namespace, image_id = image_spec self.create_snapshot_requests.add(pool_id, namespace, image_id) @@ -502,9 +503,10 @@ class MirrorSnapshotScheduleHandler: with self.lock: self.schedules = schedules - def refresh_images(self) -> None: - if (datetime.now() - self.last_refresh_images).seconds < 60: - return + def refresh_images(self) -> float: + elapsed = (datetime.now() - self.last_refresh_images).total_seconds() + if elapsed < self.REFRESH_DELAY_SECONDS: + return self.REFRESH_DELAY_SECONDS - elapsed self.log.debug("MirrorSnapshotScheduleHandler: refresh_images") @@ -517,7 +519,7 @@ class MirrorSnapshotScheduleHandler: self.images = {} self.queue = {} self.last_refresh_images = datetime.now() - return + return self.REFRESH_DELAY_SECONDS epoch = int(datetime.now().strftime('%s')) images: Dict[str, Dict[str, Dict[str, str]]] = {} @@ -535,6 +537,7 @@ class MirrorSnapshotScheduleHandler: self.watchers.unregister_stale(epoch) self.last_refresh_images = datetime.now() + return self.REFRESH_DELAY_SECONDS def load_pool_images(self, ioctx: rados.Ioctx, diff --git a/src/pybind/mgr/rbd_support/trash_purge_schedule.py b/src/pybind/mgr/rbd_support/trash_purge_schedule.py index 3b4d906837617..1cb87d8a82cf0 100644 --- a/src/pybind/mgr/rbd_support/trash_purge_schedule.py +++ b/src/pybind/mgr/rbd_support/trash_purge_schedule.py @@ -16,6 +16,7 @@ from .schedule import LevelSpec, Interval, StartTime, Schedule, Schedules class TrashPurgeScheduleHandler: MODULE_OPTION_NAME = "trash_purge_schedule" SCHEDULE_OID = "rbd_trash_purge_schedule" + REFRESH_DELAY_SECONDS = 60.0 lock = Lock() condition = Condition(lock) @@ -35,11 +36,11 @@ class TrashPurgeScheduleHandler: try: self.log.info("TrashPurgeScheduleHandler: starting") while True: - self.refresh_pools() + refresh_delay = self.refresh_pools() with self.lock: (ns_spec, wait_time) = self.dequeue() if not ns_spec: - self.condition.wait(min(wait_time, 60)) + self.condition.wait(min(wait_time, refresh_delay)) continue pool_id, namespace = ns_spec self.trash_purge(pool_id, namespace) @@ -74,9 +75,10 @@ class TrashPurgeScheduleHandler: with self.lock: self.schedules = schedules - def refresh_pools(self) -> None: - if (datetime.now() - self.last_refresh_pools).seconds < 60: - return + def refresh_pools(self) -> float: + elapsed = (datetime.now() - self.last_refresh_pools).total_seconds() + if elapsed < self.REFRESH_DELAY_SECONDS: + return self.REFRESH_DELAY_SECONDS - elapsed self.log.debug("TrashPurgeScheduleHandler: refresh_pools") @@ -88,7 +90,7 @@ class TrashPurgeScheduleHandler: self.pools = {} self.queue = {} self.last_refresh_pools = datetime.now() - return + return self.REFRESH_DELAY_SECONDS pools: Dict[str, Dict[str, str]] = {} @@ -104,6 +106,7 @@ class TrashPurgeScheduleHandler: self.pools = pools self.last_refresh_pools = datetime.now() + return self.REFRESH_DELAY_SECONDS def load_pool(self, ioctx: rados.Ioctx, pools: Dict[str, Dict[str, str]]) -> None: pool_id = str(ioctx.get_pool_id())