summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/snap_schedule/fs/schedule_client.py
diff options
context:
space:
mode:
authorPatrick Donnelly <pdonnell@redhat.com>2021-01-29 00:13:51 +0100
committerPatrick Donnelly <pdonnell@redhat.com>2021-03-19 16:52:56 +0100
commitde8b110f9f78f151a0812e983094ec04571ec1fe (patch)
tree8cf6528a68b20ab7493faa887cb0cc3bde24e68b /src/pybind/mgr/snap_schedule/fs/schedule_client.py
parentpybind/mgr/snap_schedule: idempotentize table creation (diff)
downloadceph-de8b110f9f78f151a0812e983094ec04571ec1fe.tar.xz
ceph-de8b110f9f78f151a0812e983094ec04571ec1fe.zip
pybind/mgr/snap_schedule: use ceph VFS
Rather than storing the ASCII dump of the sqlite database in a single object, use the shiny new "ceph" VFS! Hurray, I'm useful! Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
Diffstat (limited to 'src/pybind/mgr/snap_schedule/fs/schedule_client.py')
-rw-r--r--src/pybind/mgr/snap_schedule/fs/schedule_client.py57
1 files changed, 22 insertions, 35 deletions
diff --git a/src/pybind/mgr/snap_schedule/fs/schedule_client.py b/src/pybind/mgr/snap_schedule/fs/schedule_client.py
index 84950d39924..779bdc9b75a 100644
--- a/src/pybind/mgr/snap_schedule/fs/schedule_client.py
+++ b/src/pybind/mgr/snap_schedule/fs/schedule_client.py
@@ -124,42 +124,30 @@ class SnapSchedClient(CephfsClient):
def get_schedule_db(self, fs: str) -> sqlite3.Connection:
if fs not in self.sqlite_connections:
- self.sqlite_connections[fs] = sqlite3.connect(
- ':memory:',
- check_same_thread=False)
- with self.sqlite_connections[fs] as con:
- con.row_factory = sqlite3.Row
- con.execute("PRAGMA FOREIGN_KEYS = 1")
- pool = self.get_metadata_pool(fs)
- assert pool, f'fs "{fs}" not found'
- with open_ioctx(self, pool) as ioctx:
- try:
- size, _mtime = ioctx.stat(SNAP_DB_OBJECT_NAME)
- db = ioctx.read(SNAP_DB_OBJECT_NAME,
- size).decode('utf-8')
- con.executescript(db)
- except rados.ObjectNotFound:
- log.debug((f'No schedule DB found in {fs}, '
- 'creating one.'))
- con.executescript(Schedule.CREATE_TABLES)
+ poolid = self.get_metadata_pool(fs)
+ assert poolid, f'fs "{fs}" not found'
+ uri = f"file:///*{poolid}:/{SNAP_DB_OBJECT_NAME}.db?vfs=ceph";
+ log.debug(f"using uri {uri}")
+ db = sqlite3.connect(uri, check_same_thread=False, uri=True)
+ db.execute('PRAGMA FOREIGN_KEYS = 1')
+ db.execute('PRAGMA JOURNAL_MODE = PERSIST')
+ db.execute('PRAGMA PAGE_SIZE = 65536')
+ db.execute('PRAGMA CACHE_SIZE = 256')
+ db.row_factory = sqlite3.Row
+ # check for legacy dump store
+ with open_ioctx(self, poolid) as ioctx:
+ try:
+ size, _mtime = ioctx.stat(SNAP_DB_OBJECT_NAME)
+ dump = ioctx.read(SNAP_DB_OBJECT_NAME, size).decode('utf-8')
+ db.executescript(dump)
+ ioctx.remove(SNAP_DB_OBJECT_NAME)
+ except rados.ObjectNotFound:
+ log.debug(f'No legacy schedule DB found in {fs}')
+ db.executescript(Schedule.CREATE_TABLES)
+ self.sqlite_connections[fs] = db
+ return db
return self.sqlite_connections[fs]
- def store_schedule_db(self, fs: str) -> None:
- # only store db is it exists, otherwise nothing to do
- metadata_pool = self.get_metadata_pool(fs)
- if not metadata_pool:
- raise CephfsConnectionException(
- -errno.ENOENT, "Filesystem {} does not exist".format(fs))
- if fs in self.sqlite_connections:
- db_content = []
- db = self.sqlite_connections[fs]
- with db:
- for row in db.iterdump():
- db_content.append(row)
- with open_ioctx(self, metadata_pool) as ioctx:
- ioctx.write_full(SNAP_DB_OBJECT_NAME,
- '\n'.join(db_content).encode('utf-8'))
-
def _is_allowed_repeat(self, exec_row: Dict[str, str], path: str) -> bool:
if Schedule.parse_schedule(exec_row['schedule'])[1] == 'M':
if self.allow_minute_snaps:
@@ -293,7 +281,6 @@ class SnapSchedClient(CephfsClient):
log.debug(f'attempting to add schedule {sched}')
db = self.get_schedule_db(fs)
sched.store_schedule(db)
- self.store_schedule_db(sched.fs)
@updates_schedule_db
def rm_snap_schedule(self,