From: Milind Changire Date: Mon, 28 Feb 2022 06:26:09 +0000 (+0530) Subject: mgr/snap_schedule: restart old schedules X-Git-Tag: v17.2.0~12^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a2dbf943a26bb85c70a58f466efdd54470be4621;p=ceph.git mgr/snap_schedule: restart old schedules Old schedules were not picked up from database when mgr was restarted. Restart old schedules on mgr restart. Fixes: https://tracker.ceph.com/issues/54052 Signed-off-by: Milind Changire (cherry picked from commit dca7fdb600932d712280dd91a4eb63a17a8800e3) --- diff --git a/src/pybind/mgr/snap_schedule/fs/schedule.py b/src/pybind/mgr/snap_schedule/fs/schedule.py index eb347367a64..d0c9f1098b4 100644 --- a/src/pybind/mgr/snap_schedule/fs/schedule.py +++ b/src/pybind/mgr/snap_schedule/fs/schedule.py @@ -241,6 +241,14 @@ class Schedule(object): (f'{path}',)) return [cls._from_db_row(row, fs) for row in c.fetchall()] + @classmethod + def list_all_schedules(cls, + db: sqlite3.Connection, + fs: str) -> List['Schedule']: + with db: + c = db.execute(cls.PROTO_GET_SCHEDULES + " path LIKE '%'") + return [cls._from_db_row(row, fs) for row in c.fetchall()] + INSERT_SCHEDULE = '''INSERT INTO schedules(path, subvol, retention, rel_path) Values(?, ?, ?, ?);''' diff --git a/src/pybind/mgr/snap_schedule/fs/schedule_client.py b/src/pybind/mgr/snap_schedule/fs/schedule_client.py index cf1ba78aac7..a22f658dffe 100644 --- a/src/pybind/mgr/snap_schedule/fs/schedule_client.py +++ b/src/pybind/mgr/snap_schedule/fs/schedule_client.py @@ -144,8 +144,6 @@ class SnapSchedClient(CephfsClient): def __init__(self, mgr: Any) -> None: super(SnapSchedClient, self).__init__(mgr) - # TODO maybe iterate over all fs instance in fsmap and load snap dbs? - # # Each db connection is now guarded by a Lock; this is required to # avoid concurrent DB transactions when more than one paths in a # file-system are scheduled at the same interval eg. 1h; without the @@ -155,6 +153,14 @@ class SnapSchedClient(CephfsClient): self.active_timers: Dict[Tuple[str, str], List[Timer]] = {} self.conn_lock: Lock = Lock() # lock to protect add/lookup db connections + # restart old schedules + for fs_name in self.get_all_filesystems(): + with self.get_schedule_db(fs_name) as conn_mgr: + db = conn_mgr.dbinfo.db + sched_list = Schedule.list_all_schedules(db, fs_name) + for sched in sched_list: + self.refresh_snap_timers(fs_name, sched.path, db) + @property def allow_minute_snaps(self) -> None: return self.mgr.get_module_option('allow_m_granularity')