Skip to main content

Engine

Struct Engine 

Source
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

Source

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.

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl Debug for Engine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more