Skip to content

Commit f14f60a

Browse files
committed
Merge PR ceph#53999 into main
* refs/pull/53999/head: PendingReleaseNotes: support for subvolumes and subvolume groups in snap_schedule snap_schedule/tests: fix db upgrade issue qa: add yaml for on demand subvol version testing qa: add test cases for testing --subvol and --group arguments mgr/volumes: conditionalize subvolume upgrade mgr/volumes: ensure correct init of v1 subvol mgr/snap_schedule: add subvol and subvol group arguments to cli mds/snap_schedule: add subvolume group column management mgr/volumes: add remote helper methods to fetch subvolume info Reviewed-by: Venky Shankar <[email protected]>
2 parents 9d6c888 + b3ff5f7 commit f14f60a

File tree

16 files changed

+692
-54
lines changed

16 files changed

+692
-54
lines changed

PendingReleaseNotes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ CephFS: Disallow delegating preallocated inode ranges to clients. Config
103103
module is now available. Users may run `ceph balancer status detail` to see more
104104
details about which PGs were updated in the balancer's last optimization.
105105
See https://docs.ceph.com/en/latest/rados/operations/balancer/ for more information.
106+
* CephFS: Full support for subvolumes and subvolume groups is now available
107+
for snap_schedule Manager module.
106108

107109
>=18.0.0
108110

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
overrides:
2+
subvolume_version: 1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
overrides:
2+
subvolume_version: 2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../.qa
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.qa/cephfs/overrides/subvol_versions/create_subvol_version_v1.yaml
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.qa/cephfs/overrides/subvol_versions/create_subvol_version_v2.yaml

qa/tasks/cephfs/test_snap_schedules.py

Lines changed: 459 additions & 22 deletions
Large diffs are not rendered by default.

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def __init__(self,
8989
rel_path: str,
9090
start: Optional[str] = None,
9191
subvol: Optional[str] = None,
92+
group: Optional[str] = None,
9293
retention_policy: str = '{}',
9394
created: Optional[str] = None,
9495
first: Optional[str] = None,
@@ -100,6 +101,7 @@ def __init__(self,
100101
) -> None:
101102
self.fs = fs_name
102103
self.subvol = subvol
104+
self.group = group
103105
self.path = path
104106
self.rel_path = rel_path
105107
self.schedule = schedule
@@ -145,6 +147,7 @@ def _from_db_row(cls, table_row: TableRowT, fs: str) -> 'Schedule':
145147
cast(str, table_row['rel_path']),
146148
cast(str, table_row['start']),
147149
cast(str, table_row['subvol']),
150+
cast(str, table_row['group_name']),
148151
cast(str, table_row['retention']),
149152
cast(str, table_row['created']),
150153
cast(str, table_row['first']),
@@ -200,7 +203,7 @@ def json_list(self) -> str:
200203
ORDER BY until;'''
201204

202205
PROTO_GET_SCHEDULES = '''SELECT
203-
s.path, s.subvol, s.rel_path, sm.active,
206+
s.path, s.subvol, s.group_name, s.rel_path, sm.active,
204207
sm.schedule, s.retention, sm.start, sm.first, sm.last,
205208
sm.last_pruned, sm.created, sm.created_count, sm.pruned_count
206209
FROM schedules s
@@ -255,8 +258,8 @@ def list_all_schedules(cls,
255258
return [cls._from_db_row(row, fs) for row in c.fetchall()]
256259

257260
INSERT_SCHEDULE = '''INSERT INTO
258-
schedules(path, subvol, retention, rel_path)
259-
Values(?, ?, ?, ?);'''
261+
schedules(path, subvol, group_name, retention, rel_path)
262+
Values(?, ?, ?, ?, ?);'''
260263
INSERT_SCHEDULE_META = '''INSERT INTO
261264
schedules_meta(schedule_id, start, created, repeat, schedule,
262265
active)
@@ -270,6 +273,7 @@ def store_schedule(self, db: sqlite3.Connection) -> None:
270273
c = db.execute(self.INSERT_SCHEDULE,
271274
(self.path,
272275
self.subvol,
276+
self.group,
273277
json.dumps(self.retention),
274278
self.rel_path,))
275279
sched_id = c.lastrowid

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,41 @@ def allow_minute_snaps(self) -> None:
180180
def dump_on_update(self) -> None:
181181
return self.mgr.get_module_option('dump_on_update')
182182

183+
def _create_snap_schedule_kv_db(self, db: sqlite3.Connection) -> None:
184+
SQL = """
185+
CREATE TABLE IF NOT EXISTS SnapScheduleModuleKV (
186+
key TEXT PRIMARY KEY,
187+
value NOT NULL
188+
) WITHOUT ROWID;
189+
INSERT OR IGNORE INTO SnapScheduleModuleKV (key, value) VALUES ('__snap_schedule_db_version', 1);
190+
"""
191+
db.executescript(SQL)
192+
193+
def _get_snap_schedule_db_version(self, db: sqlite3.Connection) -> int:
194+
SQL = """
195+
SELECT value
196+
FROM SnapScheduleModuleKV
197+
WHERE key = '__snap_schedule_db_version';
198+
"""
199+
cur = db.execute(SQL)
200+
row = cur.fetchone()
201+
assert row is not None
202+
return int(row[0])
203+
204+
# add all upgrades here
205+
def _upgrade_snap_schedule_db_schema(self, db: sqlite3.Connection) -> None:
206+
# add a column to hold the subvolume group name
207+
if self._get_snap_schedule_db_version(db) < 2:
208+
SQL = """
209+
ALTER TABLE schedules
210+
ADD COLUMN group_name TEXT;
211+
"""
212+
db.executescript(SQL)
213+
214+
# bump up the snap-schedule db version to 2
215+
SQL = "UPDATE OR ROLLBACK SnapScheduleModuleKV SET value = ? WHERE key = '__snap_schedule_db_version';"
216+
db.execute(SQL, (2,))
217+
183218
def get_schedule_db(self, fs: str) -> DBConnectionManager:
184219
dbinfo = None
185220
self.conn_lock.acquire()
@@ -206,6 +241,8 @@ def get_schedule_db(self, fs: str) -> DBConnectionManager:
206241
except rados.ObjectNotFound:
207242
log.debug(f'No legacy schedule DB found in {fs}')
208243
db.executescript(Schedule.CREATE_TABLES)
244+
self._create_snap_schedule_kv_db(db)
245+
self._upgrade_snap_schedule_db_schema(db)
209246
self.sqlite_connections[fs] = DBInfo(fs, db)
210247
dbinfo = self.sqlite_connections[fs]
211248
self.conn_lock.release()
@@ -370,7 +407,8 @@ def list_snap_schedules(self,
370407
def store_snap_schedule(self,
371408
fs: str, path_: str,
372409
args: Tuple[str, str, str, str,
373-
Optional[str], Optional[str]]) -> None:
410+
Optional[str], Optional[str],
411+
Optional[str]]) -> None:
374412
sched = Schedule(*args)
375413
log.debug(f'repeat is {sched.repeat}')
376414
if sched.parse_schedule(sched.schedule)[1] == 'm' and not self.allow_minute_snaps:

0 commit comments

Comments
 (0)