pub struct Database<P: Policy> { /* private fields */ }Expand description
One database’s connections and upkeep threads.
Implementations§
Source§impl<P: Policy> Database<P>
impl<P: Policy> Database<P>
Sourcepub fn checkpoints(&self) -> bool
pub fn checkpoints(&self) -> bool
Whether one of the database’s own threads checkpoints its WAL.
Sourcepub fn fault_checkpoints(
&self,
fault: impl FnMut() -> Result<(), PolicyError<P>> + Send + 'static,
)
pub fn fault_checkpoints( &self, fault: impl FnMut() -> Result<(), PolicyError<P>> + Send + 'static, )
Run fault as each checkpoint takes the writer.
Sourcepub fn after_checkpoint_copies(&self, step: impl FnMut() + Send + 'static)
pub fn after_checkpoint_copies(&self, step: impl FnMut() + Send + 'static)
A checkpoint copies the WAL in passes while writes go on. Run step
after each pass’s copy returns, before the pass syncs.
Sourcepub fn report_checkpoints(&self) -> UnboundedReceiver<WalCheckpoint>
pub fn report_checkpoints(&self) -> UnboundedReceiver<WalCheckpoint>
Return a receiver that gets what each later checkpoint does at its last step. The checkpointer sends it while the checkpoint still holds the writer.
Sourcepub fn checkpoint_now(&self) -> Result<(), PolicyError<P>>
pub fn checkpoint_now(&self) -> Result<(), PolicyError<P>>
Run one wake’s checkpoint now, on the checkpointer’s connection.
Sourcepub fn report_statistics_runs(&self) -> UnboundedReceiver<()>
pub fn report_statistics_runs(&self) -> UnboundedReceiver<()>
Return a receiver that gets a message after each later run of the planner’s statistics commits.
Sourcepub fn observe_next_reader_wait(&self) -> Receiver<()> ⓘ
pub fn observe_next_reader_wait(&self) -> Receiver<()> ⓘ
Return a receiver that gets a message when the next caller waits for a reader.
Sourcepub fn each_reader(&self, visit: impl FnMut(&mut HostSql<P>))
pub fn each_reader(&self, visit: impl FnMut(&mut HostSql<P>))
Run visit on each reader in turn, under its own lock.
Sourcepub fn each_connection(&self, visit: impl FnMut(&HostSql<P>))
pub fn each_connection(&self, visit: impl FnMut(&HostSql<P>))
Run visit on every connection the database holds open, one at a
time, each under its own lock: the readers, the upkeep threads’
connections and the writer.
Source§impl<P: Policy> Database<P>
impl<P: Policy> Database<P>
Sourcepub fn open_with<T, E: From<PolicyError<P>>>(
path: &Path,
handle: Handle<P::Failure>,
options: Options<'_, P>,
prepare: impl FnOnce(&mut HostSql<P>) -> Result<T, E>,
) -> Result<(Self, T), E>
pub fn open_with<T, E: From<PolicyError<P>>>( path: &Path, handle: Handle<P::Failure>, options: Options<'_, P>, prepare: impl FnOnce(&mut HostSql<P>) -> Result<T, E>, ) -> Result<(Self, T), E>
Open the database at path: its writer, switched to WAL, then
prepare on the writer (or on the first reader, as options asks)
before the database serves anything; then the statistics, commit
capture, upkeep threads and readers options asks for. Every
connection then serves handle, which their failures fail.
Sourcepub fn host<T>(&self, run: impl FnOnce(&mut HostSql<P>) -> T) -> T
pub fn host<T>(&self, run: impl FnOnce(&mut HostSql<P>) -> T) -> T
Run run on the writer, once no other call holds it.
Sourcepub fn reader(&self) -> Reader<'_, P>
pub fn reader(&self) -> Reader<'_, P>
An idle reader, once one is free; it stays the caller’s until the lease drops.
Sourcepub fn checkpointed_size(&self) -> CheckpointedSize
pub fn checkpointed_size(&self) -> CheckpointedSize
A view of the main database file’s size in bytes after the latest
checkpoint, which wakes when a later checkpoint changes the size.
Before the first checkpoint, the watch holds the file’s size once the
commits open_with ran ended. The writer and the checkpointer send the
size after each checkpoint they run through
HostSql::wal_checkpoint: the checkpointer’s own, and the host’s on
the writer.
Two kinds of checkpoint send nothing. SQLite checkpoints the WAL as
the database closes, and nothing reads the watch after that, because
the watch closes with the database. SQLite’s own automatic
checkpoint, which runs inside a commit, sends nothing either; while
sqlive’s checkpointer runs, no connection of the database’s runs one.
Without the checkpointer, the writer runs one as its
wal_autocheckpoint asks.
Sourcepub fn close(self) -> Vec<PolicyError<P>> ⓘ
pub fn close(self) -> Vec<PolicyError<P>> ⓘ
Stop the upkeep threads; gather the planner’s statistics again if the database keeps them and its handle hasn’t failed; then close every connection. Closing goes on past each failure, and returns them all.