]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/snap_schedule: restart old schedules
authorMilind Changire <mchangir@redhat.com>
Mon, 28 Feb 2022 06:26:09 +0000 (11:56 +0530)
committerVenky Shankar <vshankar@redhat.com>
Fri, 15 Apr 2022 17:09:40 +0000 (22:39 +0530)
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 <mchangir@redhat.com>
(cherry picked from commit dca7fdb600932d712280dd91a4eb63a17a8800e3)

src/pybind/mgr/snap_schedule/fs/schedule.py
src/pybind/mgr/snap_schedule/fs/schedule_client.py

index 7fad53fe8bc560e9840c51e2c9b58f82f3537d65..773a0694af9ae39f1d314070977b4a100ec7f3b8 100644 (file)
@@ -8,7 +8,7 @@ import json
 import logging
 import re
 import sqlite3
-from typing import Tuple, Any
+from typing import Tuple, Any, List
 
 log = logging.getLogger(__name__)
 
@@ -233,6 +233,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(?, ?, ?, ?);'''
index fceaca60e5391b92cb6d9135b867690afb0c276a..08a55cd5c791d46d20a8e45eba5f076d28bb4137 100644 (file)
@@ -134,8 +134,6 @@ class SnapSchedClient(CephfsClient):
 
     def __init__(self, mgr):
         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
@@ -145,6 +143,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):
         return self.mgr.get_module_option('allow_m_granularity')