magic_sync 0.1.0

Keeps partial copies of PostgreSQL tables on SQLite replicas — offline-first, by comparing what each replica holds with what it should hold
Documentation
// This file is @generated by prost-build.
/// A row's key: its parts as text, in primary key order — a uuid part
/// lowercase and hyphenated, an integer part decimal.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Key {
    #[prost(string, repeated, tag = "1")]
    pub parts: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
}
/// Everything the server sends a replica: one message, whichever it is.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ToReplica {
    /// The version of the protocol the server speaks. A replica that receives a
    /// later one than its own does not act on it, and does not acknowledge it.
    #[prost(uint32, tag = "1")]
    pub protocol: u32,
    #[prost(oneof = "to_replica::Body", tags = "2, 3, 4")]
    pub body: ::core::option::Option<to_replica::Body>,
}
/// Nested message and enum types in `ToReplica`.
pub mod to_replica {
    #[derive(Clone, PartialEq, ::prost::Oneof)]
    pub enum Body {
        #[prost(message, tag = "2")]
        Down(super::Down),
        #[prost(message, tag = "3")]
        EndSnapshot(super::EndSnapshot),
        #[prost(message, tag = "4")]
        Filed(super::Filed),
    }
}
/// One table's part of a message: rows to hold, then rows to let go.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Table {
    #[prost(string, tag = "1")]
    pub table: ::prost::alloc::string::String,
    /// Rows to hold, each encoded as the table's own row.
    #[prost(bytes = "vec", repeated, tag = "2")]
    pub upserts: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec<u8>>,
    /// Rows to let go of.
    #[prost(message, repeated, tag = "3")]
    pub deletes: ::prost::alloc::vec::Vec<Key>,
    /// The key of each upsert, in the same order, one per upsert: a side that
    /// cannot read a row can still say which one it was.
    #[prost(message, repeated, tag = "4")]
    pub keys: ::prost::alloc::vec::Vec<Key>,
    /// Up only: the replica re-states these rows, of a setting or answers to
    /// wishes, as it holds them now (PROTOCOL.md section 7) — the server takes
    /// them whatever their version.
    #[prost(bool, tag = "5")]
    pub restated: bool,
    /// Down only, in a snapshot: the rows of a setting the server records this
    /// replica holding (PROTOCOL.md section 4.2) — the replica deletes, as its
    /// own write, each it does not hold.
    #[prost(message, repeated, tag = "6")]
    pub recorded: ::prost::alloc::vec::Vec<Key>,
}
/// Server to replica: rows to hold and rows to let go, in the order given —
/// parents' upserts first, children's deletes first — applied in one
/// transaction.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Down {
    /// Set while the replica is provisioned from scratch: it remembers every
    /// row the snapshot names, and lets go of the rest when the snapshot ends.
    #[prost(string, tag = "1")]
    pub snapshot_id: ::prost::alloc::string::String,
    #[prost(message, repeated, tag = "2")]
    pub tables: ::prost::alloc::vec::Vec<Table>,
    /// Rises with every message the server sends, from 1 to 2^63 - 1: a replica
    /// applies nothing at or below the last it applied from the same epoch.
    #[prost(uint64, tag = "3")]
    pub sequence: u64,
    /// The server installation the sequence is from, a uuid.
    #[prost(string, tag = "4")]
    pub epoch: ::prost::alloc::string::String,
    /// The sequence of the message sent this replica before this one, in this
    /// epoch: a replica that did not apply that one missed it. 0 only on the
    /// message that begins a snapshot, which follows nothing.
    #[prost(uint64, tag = "5")]
    pub previous: u64,
    /// A number of this message's own, drawn at random from 1 to 2^63 - 1: a
    /// server restored from an older copy numbers its messages again, and
    /// draws other nonces for them.
    #[prost(uint64, tag = "6")]
    pub nonce: u64,
    /// The nonce of the message `previous` names: the one this follows is that
    /// sequence with that nonce. 0 when `previous` is 0.
    #[prost(uint64, tag = "7")]
    pub previous_nonce: u64,
    /// The server's seal on this message for this replica, opaque to it: the
    /// replica gives it back as it came when it says it applied the message.
    #[prost(bytes = "vec", tag = "8")]
    pub mac: ::prost::alloc::vec::Vec<u8>,
}
/// Server to replica: a snapshot is complete. Every row of `tables` the
/// replica holds and the snapshot did not name goes, children first: in
/// reverse of the order `tables` lists them.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct EndSnapshot {
    #[prost(string, tag = "1")]
    pub snapshot_id: ::prost::alloc::string::String,
    #[prost(string, repeated, tag = "2")]
    pub tables: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
    /// As Down's.
    #[prost(uint64, tag = "3")]
    pub sequence: u64,
    /// As Down's.
    #[prost(string, tag = "4")]
    pub epoch: ::prost::alloc::string::String,
    /// As Down's: 0 when it ends a snapshot of nothing, which it begins.
    #[prost(uint64, tag = "5")]
    pub previous: u64,
    /// As Down's.
    #[prost(uint64, tag = "6")]
    pub nonce: u64,
    #[prost(uint64, tag = "7")]
    pub previous_nonce: u64,
    #[prost(bytes = "vec", tag = "8")]
    pub mac: ::prost::alloc::vec::Vec<u8>,
}
/// Server to replica: these uploads are filed, or kept to be filed once they
/// can be. The notes they carried are done.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Filed {
    #[prost(uint64, repeated, tag = "1")]
    pub uploads: ::prost::alloc::vec::Vec<u64>,
}
/// Replica to server: rows it wrote, rows it could not take, what it holds,
/// and the last message it applied. The transport says which replica sent it.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Up {
    #[prost(message, repeated, tag = "2")]
    pub tables: ::prost::alloc::vec::Vec<Table>,
    #[prost(message, repeated, tag = "3")]
    pub rejected: ::prost::alloc::vec::Vec<Rejected>,
    /// What the replica holds of each table sent down, to compare with what the
    /// server records it holds.
    #[prost(message, repeated, tag = "4")]
    pub digests: ::prost::alloc::vec::Vec<Digest>,
    /// The last message the replica applied: its epoch, sequence, nonce and
    /// mac, as the message carried them. Set on the first lane when the server
    /// has not heard of it, and always with digests, which are only comparable
    /// once the replica applied every message recorded for it, and with a gap.
    #[prost(string, tag = "5")]
    pub epoch: ::prost::alloc::string::String,
    #[prost(uint64, tag = "6")]
    pub sequence: u64,
    #[prost(uint64, tag = "11")]
    pub nonce: u64,
    #[prost(bytes = "vec", tag = "12")]
    pub mac: ::prost::alloc::vec::Vec<u8>,
    /// The number of this upload, when it carries rows: a fresh one on every
    /// send, drawn at random from 1 to 2^63 - 1, so no answer meant for another
    /// replica, or for this one before a restore, names it. The server answers
    /// with Filed once it filed it.
    #[prost(uint64, repeated, tag = "7")]
    pub uploads: ::prost::alloc::vec::Vec<u64>,
    /// The version of the protocol the replica speaks.
    #[prost(uint32, tag = "8")]
    pub protocol: u32,
    /// What the replica wrote that the server has not filed, when it says: on
    /// the first lane, when it changed. Absent: it did not say this time.
    #[prost(message, optional, tag = "9")]
    pub backlog: ::core::option::Option<Backlog>,
    /// It missed a message: the sequence of the newest one that arrived not
    /// following the last it applied, and that it therefore did not apply. 0:
    /// none. Said on the first lane, with the last applied, until a snapshot
    /// begins, and told again whenever it grows; the server answers with a
    /// snapshot, unless one that began after this sequence is on its way.
    #[prost(uint64, tag = "10")]
    pub gap: u64,
}
/// What a replica wrote that the server has not filed yet.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Backlog {
    #[prost(message, repeated, tag = "1")]
    pub tables: ::prost::alloc::vec::Vec<TableBacklog>,
}
/// One table's part of a backlog.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct TableBacklog {
    #[prost(string, tag = "1")]
    pub table: ::prost::alloc::string::String,
    /// Rows not sent yet.
    #[prost(uint64, tag = "2")]
    pub unsent: u64,
    /// Rows sent the server has not said it filed.
    #[prost(uint64, tag = "3")]
    pub unfiled: u64,
    /// Rows that cannot go up as they are — larger than a message, refused by
    /// the transport, of a table or a key this build cannot read — kept until
    /// the replica runs again.
    #[prost(uint64, tag = "4")]
    pub set_aside: u64,
}
/// A row a replica could not take, or could not let go of, and why. The key
/// is required.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Rejected {
    #[prost(string, tag = "1")]
    pub table: ::prost::alloc::string::String,
    #[prost(message, optional, tag = "2")]
    pub key: ::core::option::Option<Key>,
    #[prost(string, tag = "3")]
    pub reason: ::prost::alloc::string::String,
    /// The message whose row, or delete, the replica refused: the server
    /// ignores a rejection of a message other than the last one that carried
    /// the row, or of another epoch.
    #[prost(string, tag = "4")]
    pub epoch: ::prost::alloc::string::String,
    #[prost(uint64, tag = "5")]
    pub sequence: u64,
    /// The replica did not take the row because it deleted it, a row of its
    /// own, and the server has not filed the delete: no fault of the row's,
    /// nothing a fix cures. The server sends the row again, should it keep it.
    #[prost(bool, tag = "6")]
    pub held_back: bool,
}
/// What a replica holds of one table: how many rows, and a fingerprint of
/// their keys. Rows it retired, or rejected, are left out.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Digest {
    #[prost(string, tag = "1")]
    pub table: ::prost::alloc::string::String,
    #[prost(uint64, tag = "2")]
    pub count: u64,
    #[prost(uint64, tag = "3")]
    pub fingerprint: u64,
}
/// A row of the engine's table `sync_wishes`, which travels as any table
/// written on both sides does: down in a `Down`'s tables, up in an `Up`'s. It
/// is what the server wants one setting of the replica to hold: a row of a
/// table the replica owns, whose desired columns the server may wish other
/// values (PROTOCOL.md 4.5). The server owns the first fields; the replica the
/// answer, which the server never sends down.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Wish {
    /// A uuid: the row's key.
    #[prost(string, tag = "1")]
    pub id: ::prost::alloc::string::String,
    /// The setting's table, and its row's key.
    #[prost(string, tag = "3")]
    pub table: ::prost::alloc::string::String,
    #[prost(message, optional, tag = "4")]
    pub key: ::core::option::Option<Key>,
    /// The row as wished, encoded as the setting's table's own row: the replica
    /// takes its desired columns, and compares its version when `if_unchanged`.
    #[prost(bytes = "vec", tag = "5")]
    pub wanted: ::prost::alloc::vec::Vec<u8>,
    /// Drawn at random for every wish, from 1 to 2^63 - 1: an answer is of the
    /// wish whose version it names.
    #[prost(uint64, tag = "6")]
    pub version: u64,
    /// Carried out only while the replica holds the version `wanted` carries.
    #[prost(bool, tag = "7")]
    pub if_unchanged: bool,
    /// The server's words on it: who asked, why.
    #[prost(string, tag = "8")]
    pub note: ::prost::alloc::string::String,
    /// The replica's answer: the version it answers, 0 for none yet.
    #[prost(uint64, tag = "9")]
    pub answered: u64,
    /// "applied", "refused", "superseded" or "waiting"; empty with no answer.
    #[prost(string, tag = "10")]
    pub outcome: ::prost::alloc::string::String,
    #[prost(string, tag = "11")]
    pub reason: ::prost::alloc::string::String,
    /// When it answered, RFC 3339, by the replica's clock.
    #[prost(string, tag = "12")]
    pub answered_at: ::prost::alloc::string::String,
}