storage: each runtime database connection keeps a page cache sized for its role, read back at open

This commit is contained in:
2026-10-21 21:40:05 +02:00
parent 8f2794533b
commit c2eac8d486
6 changed files with 161 additions and 8 deletions
+27
View File
@@ -335,10 +335,14 @@ pub const DataDir = struct {
/// Returns the whole `OpenResult`, recreate reason and aside name included:
/// the composition root records a recreate as a one-shot diagnostics event,
/// and the aside name is what tells an operator where the old file went.
///
/// The connection is the query-log writer's, made a runtime connection
/// once the schema step is done.
pub fn openQuerylogDb(self: *const DataDir, io: std.Io) !querylog_schema.OpenResult {
var opened = try querylog_schema.open(io, std.Io.Dir.cwd(), self.querylog_db_path);
errdefer opened.database.close();
try self.restrictQuerylogPermissions(io);
try db.initRuntimeConnection(&opened.database, .querylog_writer);
return opened;
}
@@ -352,6 +356,29 @@ pub const DataDir = struct {
return querylog_schema.reopen(io, std.Io.Dir.cwd(), self.querylog_db_path);
}
/// The server's own `config.db` connection: migrated to the current schema,
/// then made a runtime connection. CLI commands migrate through
/// `openConfigDb` and keep SQLite's default cache.
pub fn openMigratedConfigDb(self: *const DataDir, io: std.Io) !db.Db {
var database = try self.openConfigDb(io);
errdefer database.close();
_ = try migrations.migrate(&database);
try db.initRuntimeConnection(&database, .config);
return database;
}
/// A further connection for the running server, its page cache sized for
/// `role`. A query-log role requires the file `openQuerylogDb` established.
pub fn openRuntimeDb(self: *const DataDir, io: std.Io, role: db.Role) !db.Db {
var database = switch (role) {
.config => try self.openConfigDb(io),
.querylog_writer, .querylog_retention, .querylog_reader => try self.reopenQuerylogDb(io),
};
errdefer database.close();
try db.initRuntimeConnection(&database, role);
return database;
}
/// A sidecar that does not exist yet is not a failure: `-wal` and `-shm`
/// appear when SQLite first writes, and the next call catches them.
fn restrictQuerylogPermissions(self: *const DataDir, io: std.Io) !void {