From: Milind Changire Date: Thu, 9 Nov 2023 07:08:48 +0000 (+0530) Subject: mds/snap_schedule: add subvolume group column management X-Git-Tag: v19.1.0~528^2~7 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=ffa197c03159e2acb7c3892f09a1ed616b9c1cd8;p=ceph.git mds/snap_schedule: add subvolume group column management Signed-off-by: Milind Changire --- diff --git a/src/pybind/mgr/snap_schedule/fs/schedule.py b/src/pybind/mgr/snap_schedule/fs/schedule.py index 3538fe501ddb2..ba4390939bf75 100644 --- a/src/pybind/mgr/snap_schedule/fs/schedule.py +++ b/src/pybind/mgr/snap_schedule/fs/schedule.py @@ -89,6 +89,7 @@ class Schedule(object): rel_path: str, start: Optional[str] = None, subvol: Optional[str] = None, + group: Optional[str] = None, retention_policy: str = '{}', created: Optional[str] = None, first: Optional[str] = None, @@ -100,6 +101,7 @@ class Schedule(object): ) -> None: self.fs = fs_name self.subvol = subvol + self.group = group self.path = path self.rel_path = rel_path self.schedule = schedule @@ -145,6 +147,7 @@ class Schedule(object): cast(str, table_row['rel_path']), cast(str, table_row['start']), cast(str, table_row['subvol']), + cast(str, table_row['group_name']), cast(str, table_row['retention']), cast(str, table_row['created']), cast(str, table_row['first']), @@ -200,7 +203,7 @@ class Schedule(object): ORDER BY until;''' PROTO_GET_SCHEDULES = '''SELECT - s.path, s.subvol, s.rel_path, sm.active, + s.path, s.subvol, s.group_name, s.rel_path, sm.active, sm.schedule, s.retention, sm.start, sm.first, sm.last, sm.last_pruned, sm.created, sm.created_count, sm.pruned_count FROM schedules s @@ -255,8 +258,8 @@ class Schedule(object): return [cls._from_db_row(row, fs) for row in c.fetchall()] INSERT_SCHEDULE = '''INSERT INTO - schedules(path, subvol, retention, rel_path) - Values(?, ?, ?, ?);''' + schedules(path, subvol, group_name, retention, rel_path) + Values(?, ?, ?, ?, ?);''' INSERT_SCHEDULE_META = '''INSERT INTO schedules_meta(schedule_id, start, created, repeat, schedule, active) @@ -270,6 +273,7 @@ class Schedule(object): c = db.execute(self.INSERT_SCHEDULE, (self.path, self.subvol, + self.group, json.dumps(self.retention), self.rel_path,)) sched_id = c.lastrowid diff --git a/src/pybind/mgr/snap_schedule/fs/schedule_client.py b/src/pybind/mgr/snap_schedule/fs/schedule_client.py index ec3d32fb44384..8b199b632c322 100644 --- a/src/pybind/mgr/snap_schedule/fs/schedule_client.py +++ b/src/pybind/mgr/snap_schedule/fs/schedule_client.py @@ -180,6 +180,41 @@ class SnapSchedClient(CephfsClient): def dump_on_update(self) -> None: return self.mgr.get_module_option('dump_on_update') + def _create_snap_schedule_kv_db(self, db: sqlite3.Connection) -> None: + SQL = """ + CREATE TABLE IF NOT EXISTS SnapScheduleModuleKV ( + key TEXT PRIMARY KEY, + value NOT NULL + ) WITHOUT ROWID; + INSERT OR IGNORE INTO SnapScheduleModuleKV (key, value) VALUES ('__snap_schedule_db_version', 1); + """ + db.executescript(SQL) + + def _get_snap_schedule_db_version(self, db: sqlite3.Connection) -> int: + SQL = """ + SELECT value + FROM SnapScheduleModuleKV + WHERE key = '__snap_schedule_db_version'; + """ + cur = db.execute(SQL) + row = cur.fetchone() + assert row is not None + return int(row[0]) + + # add all upgrades here + def _upgrade_snap_schedule_db_schema(self, db: sqlite3.Connection) -> None: + # add a column to hold the subvolume group name + if self._get_snap_schedule_db_version(db) < 2: + SQL = """ + ALTER TABLE schedules + ADD COLUMN group_name TEXT; + """ + db.executescript(SQL) + + # bump up the snap-schedule db version to 2 + SQL = "UPDATE OR ROLLBACK SnapScheduleModuleKV SET value = ? WHERE key = '__snap_schedule_db_version';" + db.execute(SQL, (2,)) + def get_schedule_db(self, fs: str) -> DBConnectionManager: dbinfo = None self.conn_lock.acquire() @@ -206,6 +241,8 @@ class SnapSchedClient(CephfsClient): except rados.ObjectNotFound: log.debug(f'No legacy schedule DB found in {fs}') db.executescript(Schedule.CREATE_TABLES) + self._create_snap_schedule_kv_db(db) + self._upgrade_snap_schedule_db_schema(db) self.sqlite_connections[fs] = DBInfo(fs, db) dbinfo = self.sqlite_connections[fs] self.conn_lock.release() @@ -370,7 +407,8 @@ class SnapSchedClient(CephfsClient): def store_snap_schedule(self, fs: str, path_: str, args: Tuple[str, str, str, str, - Optional[str], Optional[str]]) -> None: + Optional[str], Optional[str], + Optional[str]]) -> None: sched = Schedule(*args) log.debug(f'repeat is {sched.repeat}') if sched.parse_schedule(sched.schedule)[1] == 'm' and not self.allow_minute_snaps: