]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pybind/mgr/snap_schedule: use ceph VFS
authorPatrick Donnelly <pdonnell@redhat.com>
Thu, 28 Jan 2021 23:13:51 +0000 (15:13 -0800)
committerPatrick Donnelly <pdonnell@redhat.com>
Fri, 19 Mar 2021 15:52:56 +0000 (08:52 -0700)
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>
src/pybind/mgr/snap_schedule/fs/schedule_client.py

index 84950d399249f318791fe0059e74345548470fe2..779bdc9b75a582a3fbb9ed58554023076e35d47e 100644 (file)
@@ -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,