pub struct Engine { /* private fields */ }Expand description
The server’s engine, built once from the codecs and the schema by the
Server, which hands it out for what a host asks of it:
the triggers and indexes it needs (Engine::triggers,
Engine::indexes), and how far along every
replica is (status).
Implementations§
Source§impl Engine
impl Engine
Sourcepub async fn triggers<P: Sync + 'static>(
conn: &mut Conn,
codecs: &[Codec<P>],
replicas: Replicas,
) -> Result<String, Error>
pub async fn triggers<P: Sync + 'static>( conn: &mut Conn, codecs: &[Codec<P>], replicas: Replicas, ) -> Result<String, Error>
The statements that create every trigger the server needs for
codecs, one per line, read off the database conn is on: what a
host with migrations writes in the migration that creates the tables —
after every step of the engine’s schema (migration) — and what
Server::install runs. A mirrored table
notes every write that changes a column it does not leave to the
replicas, and refuses a truncate; a group table notes every write.
Server::new refuses to start while one is
missing or differs.
A trigger as printed fires in every session but one whose
session_replication_role is replica — a logical replication
subscription applying changes, a restore told to disable triggers —
and what such a session writes is never noted. Where one writes
mirrored tables, make their triggers ENABLE ALWAYS: the engine takes
a trigger enabled always as well as one enabled as printed, and
refuses one disabled, or enabled for replication sessions only.
use magic_sync::plan::{Engine, Replicas};
const REGISTERS: Replicas = Replicas::new("shop.registers", "registers").live("active");
let mut conn = pool.acquire().await?;
println!("{}", Engine::triggers(&mut conn, &codecs, REGISTERS).await?);§Errors
Error::Database when the database fails, and Error::Misuse when
the engine’s schema is missing or at another version, or a declaration
is one the schema cannot honour.
Sourcepub async fn indexes<P: Sync + 'static>(
conn: &mut Conn,
codecs: &[Codec<P>],
replicas: Replicas,
) -> Result<String, Error>
pub async fn indexes<P: Sync + 'static>( conn: &mut Conn, codecs: &[Codec<P>], replicas: Replicas, ) -> Result<String, Error>
The statements that create every index the planner’s lookups need
for codecs and the database conn is on does not have, one per
line: what a host with migrations writes beside the triggers
(Engine::triggers), and what
Server::install runs. The
planner finds rows by the columns that point at a mirrored table’s
rows, a row’s replica or partition, and a group’s members and
assignments — on a large table, a lookup no index serves reads the
whole table on every pass. An index that leads with those columns,
in any order, serves; Server::new
refuses to start while one is missing.
§Errors
As Engine::triggers.
Source§impl Engine
impl Engine
Sourcepub async fn progress(
&self,
conn: &mut Conn,
scope: Scope<'_>,
) -> Result<Progress, Error>
pub async fn progress( &self, conn: &mut Conn, scope: Scope<'_>, ) -> Result<Progress, Error>
How far each replica of scope is from holding what it should, per
table, counted from what each has acknowledged applying — never from
what was merely sent. See TableProgress. It counts the rows each
replica should hold: ask it for the replicas a person is looking at.
§Errors
Error::Database when the database fails; Error::Misuse when
called inside a transaction weaker than REPEATABLE READ, or for a
Scope::Partition when the replicas have no partition.
Sourcepub async fn row_progress(
&self,
conn: &mut Conn,
scope: Scope<'_>,
table: &str,
key: &str,
) -> Result<RowProgress, Error>
pub async fn row_progress( &self, conn: &mut Conn, scope: Scope<'_>, table: &str, key: &str, ) -> Result<RowProgress, Error>
Where one row stands on every replica of scope that holds it,
should, or is owed it. key is the row’s key as text, in the form
Row::key_text writes: the parts of a key of
several columns joined by |, a uuid lowercase and hyphenated.
§Errors
As the other reads, and besides: Error::Misuse when table is not
mirrored, Error::Malformed when key is not a key of it.
Sourcepub async fn overview(
&self,
conn: &mut Conn,
scope: Scope<'_>,
limit: u32,
) -> Result<Overview, Error>
pub async fn overview( &self, conn: &mut Conn, scope: Scope<'_>, limit: u32, ) -> Result<Overview, Error>
Everything a dashboard shows first, over scope: the engine’s health
with up to limit entries of each list, how many replicas are in each
state with up to limit of them worst first, and each table’s state.
§Errors
Error::Database when the database fails; Error::Misuse when
called inside a transaction weaker than REPEATABLE READ, or for a
Scope::Partition when the replicas have no partition.
Sourcepub async fn listing(
&self,
conn: &mut Conn,
scope: Scope<'_>,
state: Option<ReplicaState>,
page: Page,
) -> Result<Listing, Error>
pub async fn listing( &self, conn: &mut Conn, scope: Scope<'_>, state: Option<ReplicaState>, page: Page, ) -> Result<Listing, Error>
The replicas of scope in state (every one, when None), worst
first: the page of them asked for. Worst first is by state, then
the longest silent, then by id.
§Errors
Error::Database when the database fails; Error::Misuse when
called inside a transaction weaker than REPEATABLE READ, or for a
Scope::Partition when the replicas have no partition.
Sourcepub async fn wishes(
&self,
conn: &mut Conn,
scope: Scope<'_>,
state: Option<WishState>,
page: Page,
) -> Result<WishListing, Error>
pub async fn wishes( &self, conn: &mut Conn, scope: Scope<'_>, state: Option<WishState>, page: Page, ) -> Result<WishListing, Error>
The wishes of the settings of scope’s replicas in state (every
one, when None): the page of them asked for, those that need
attention first — refused, superseded, waiting, pending, then the
ones carried out — each the latest wished first.
§Errors
Error::Database when the database fails; Error::Misuse when
called inside a transaction weaker than REPEATABLE READ, or for a
Scope::Partition when the replicas have no partition.
Sourcepub async fn health(
&self,
conn: &mut Conn,
scope: Scope<'_>,
limit: u32,
) -> Result<Health, Error>
pub async fn health( &self, conn: &mut Conn, scope: Scope<'_>, limit: u32, ) -> Result<Health, Error>
What the engine is waiting on over scope, with up to limit
entries of each list.
§Errors
Error::Database when the database fails; Error::Misuse when
called inside a transaction weaker than REPEATABLE READ, or for a
Scope::Partition when the replicas have no partition.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Engine
impl RefUnwindSafe for Engine
impl Send for Engine
impl Sync for Engine
impl Unpin for Engine
impl UnsafeUnpin for Engine
impl UnwindSafe for Engine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more