Struct SqliteEventStore
pub struct SqliteEventStore { /* private fields */ }event-store only.Expand description
A SQLite-backed event store.
The connection lives behind a Mutex because [rusqlite::Connection] is
Send but not Sync: without the mutex, &SqliteEventStore would
not be Send, and every future in the SendEventStore flavour captures
&self. The mutex is what buys Self: Sync, and Self: Sync is what makes
the Send flavour implementable at all. It also means this adapter
serialises its writers by construction — that is the shape it is here to
represent, not an accident.
The Arc is not for sharing the store; it is so that a
SqliteReadStream can outlive the &self borrow that produced it, which
it must, because read is not async and hands the stream back to the
caller.
Implementations§
§impl SqliteEventStore
impl SqliteEventStore
pub const MAX_EVENT_DATA_LEN: usize = 1_048_576
pub const MAX_EVENT_DATA_LEN: usize = 1_048_576
The largest data payload this store accepts, in bytes of
Event::data — not of an encoded row, and not of data and
metadata together.
A fact about this adapter, not a trade: SQLite’s own ceiling is near a gigabyte, and this is the number below it that keeps the conformance suite runnable, because the rule that checks a ceiling allocates it plus one byte twice per run. It is sixteen times VT-21’s 65,536-byte floor.
pub const MAX_TAGS_PER_EVENT: usize = 128
pub const MAX_TAGS_PER_EVENT: usize = 128
The largest number of tags on one event this store accepts.
Twice VT-22’s floor of 64. Every tag costs a row in event_tag and an
upsert in tag_cardinality, both inside the write transaction, so the
number is bounded by lock hold time rather than by storage.
pub const MAX_EVENTS_PER_BATCH: usize = 256
pub const MAX_EVENTS_PER_BATCH: usize = 256
The largest number of events this store accepts in one append.
Twice VT-24’s floor of 128. At this ceiling with
MAX_TAGS_PER_EVENT tags on every event, a
single multi-row tag insert would bind 98,304 of SQLite’s 32,766 bound
parameters — which is why the insert is chunked to the parameter budget
and the transaction is not.
pub const MAX_PAGE_BYTES_PER_STATEMENT: usize
pub const MAX_PAGE_BYTES_PER_STATEMENT: usize
How many bytes of event payload one statement of a page may accumulate before it stops taking rows.
A row is not a bounded quantity, and the row budget could not say so.
Each row of a page owns its data, up to
MAX_EVENT_DATA_LEN, and its metadata,
which check_ceilings does not bound at all — so a page bounded only in
rows is bounded, in bytes, by SQLite’s own near-gigabyte blob limit
rather than by anything this crate states. Measured rather than argued:
one page of 512 events at the data ceiling peaked at 537,036,800 live
bytes — 512.2 MiB — in one buffer before a single row reached the
caller
(experiments/one-connection-latency/results/raw/ceiling-residency.txt).
Per statement, which is what the name says and what the bound is. A
wide query is several statements merged, so the honest ceiling on one
page’s payload residency is this number times
planned_statement_count — computable
by a caller, which is the point of it being public, and stated here
rather than left to be discovered. The alternative, one budget shared
across the page, was rejected: the first statement would spend it and
every later one would be cut to a single row, which turns a wide query
into a page-per-event replay.
It is checked after the row is taken, so a page always makes
progress. That is not hypothetical tidiness: metadata is unbounded, so
one row can exceed this on its own, and a page that refused it would
stall the read forever.
Eight maximal payloads. It is a fact this adapter states, in the
sense MAX_EVENT_DATA_LEN is one, and not a
measured optimum: it is large enough that a page of maximal events still
carries eight of them, and small enough that a page’s cost is stated in
megabytes. Whether the pair of budgets should be stated by the adapter at
all or asked of the caller is a decision this constant does not make;
the brief is staged in .kb/_intake/.
pub const MAX_QUERY_ARMS_PER_STATEMENT: usize = 400
pub const MAX_QUERY_ARMS_PER_STATEMENT: usize = 400
How many index arms one prepared statement carries before the query is split across several.
SQLite compiles a UNION of n arms as one compound SELECT, and
SQLITE_MAX_COMPOUND_SELECT defaults to 500 terms. A Query bounds
nothing by design — the specification requires every store to evaluate at
least 128 items and puts no ceiling above that — so a wide query is
chunked and merged, never refused: there is no MAX_QUERY_ITEMS
anywhere in this crate and no QueryItems StoreLimit variant to report one
through, because a query-item refusal is not an append outcome.
The number is public so that a test can compute the boundary rather than guess at it: a merge that never executes is dead code behind a green suite, which is the failure mode this whole project exists to retire.
It is one of two axes, and it is not the one that binds first on a
query of wide items — see
MAX_QUERY_PARAMETERS_PER_STATEMENT.
pub const MAX_QUERY_PARAMETERS_PER_STATEMENT: usize = PARAMETER_BUDGET
pub const MAX_QUERY_PARAMETERS_PER_STATEMENT: usize = PARAMETER_BUDGET
How many bound parameters one query statement carries before the query is split across several.
SQLite’s SQLITE_MAX_VARIABLE_NUMBER is 32,766, and the translation binds
one parameter per tag and one per type of every item in a chunk. So this
and MAX_QUERY_ARMS_PER_STATEMENT
are independent axes rather than two spellings of one width: 400 items
of a single tag each is 400 arms and 400 parameters, while the same 400
items at MAX_TAGS_PER_EVENT tags apiece is
still 400 arms and 51,200 parameters. Partitioning on arms alone planned
that second query as one statement and prepare refused it with SQLite’s
own “too many SQL variables” — on the append path, inside
BEGIN IMMEDIATE, with the caller’s decision already made, which is the
timing VT-24 rejects by name.
The number is the same budget the multi-row tag insert has chunked to since the write path was written, and it sits below SQLite’s ceiling with headroom rather than at it, for the reason given where it is defined: a statement that binds one extra parameter per row should not be within rounding distance of the wall. A query is not a different kind of statement.
Public for the same reason the arm width is public — a test that has to
guess the boundary is a test that stops crossing it — and it is the
ceiling tests/wide_tags.rs computes its under, at and over cases from.
pub fn planned_statement_count(query: &Query) -> usize
pub fn planned_statement_count(query: &Query) -> usize
How many prepared statements one page of query will take.
Never zero: Query::all is one statement, straight to the event
table.
This is the seam a test uses to observe a wide query genuinely crossing
the boundary, so it is the same call the read path makes —
query_sql::page_statements, counted — never a second ceil(arms / width) that would go on reporting a boundary fetch_page had stopped
taking. It followed chunks until the read path stopped using it, and
moving it was not optional: the two partition identically today, so a
count left behind would have agreed by arithmetic rather than by
construction and gone on agreeing right up until it mattered.
It counts the real partition, which is both ceilings and not the arm
one alone. That changes what the number says for a query of wide items:
it used to report 1 for a plan of 51,200 bound parameters, a statement
that cannot be prepared. A caller sizing a query against this seam is
asking how many statements will run, not how many the arm arithmetic on
its own would allow.
Only the shape of the Window below reaches the count, never its
values — it is pub(crate), so this says its name rather than linking to
it: the partition prices the two bounds
every arm binds and the one budget every chunk binds, and is otherwise
indifferent to what lo, hi and budget hold. A default
Selectivity likewise orders tags inside an arm, never the partition.
pub fn new(connection: Connection) -> Result<Self, SqliteEventStoreError>
pub fn new(connection: Connection) -> Result<Self, SqliteEventStoreError>
Wraps an already-open connection onto an already-migrated database.
The caller is responsible for having applied the schema — use
open to have that done — and this constructor is
fallible because it is not merely taking the caller’s word for it: the
store carries the database’s incarnation, so it reads it back here. A
StoreId-less store would mint every EventId under a zero origin,
which has no error path and no observable symptom.
The connection is used as it is given. It is not reconfigured, so a
caller reaching this constructor directly should have opened it through
crate::connection::open_configured, or configured it deliberately.
A caller that may meet a file with no store yet, or one a build before
schema 2 wrote, wants open_on, which migrates it.
§Errors
SqliteEventStoreError::Sqliteif the database cannot be queried — which for an unmigrated database is the missingstore_metatable.SqliteEventStoreError::MissingIdentityif the schema is present and the incarnation row is not.SqliteEventStoreError::MalformedIdentityif that row is not the sixteen bytes aStoreIdis.SqliteEventStoreError::UnsupportedSchemaVersionif the file was written by a newer build.SqliteEventStoreError::SchemaNeedsMigrationif the file is at an older schema version — one a build before schema 2 wrote — whichnewdoes not migrate.
pub fn open(path: impl AsRef<Path>) -> Result<Self, SqliteEventStoreError>
pub fn open(path: impl AsRef<Path>) -> Result<Self, SqliteEventStoreError>
Opens (creating if absent) a store at path and applies the schema.
The connection is configured before anything is written to it — WAL, a
stated synchronous, and a finite busy timeout — through the one path
crate::connection::open_configured both stores in this crate share.
Migration is idempotent and safe under a concurrent open: re-opening an
already-migrated file adds no schema object and mints no second
incarnation.
§Errors
SqliteEventStoreError::Sqliteif the file cannot be opened or created — a missing directory, a permission refusal, a corrupt header — or if the schema cannot be applied. Nothing partially migrated is left behind: every statement runs inside one transaction.SqliteEventStoreError::UnsupportedSchemaVersionif the file was written by a build that knows a later migration. Operating on an unknown schema is how a later migration loses data.SqliteEventStoreError::MissingIdentityorSqliteEventStoreError::MalformedIdentityif the schema is present and its incarnation row is not readable. Silently minting a replacement is the worst available behaviour — it re-issuesEventIds under a new origin for events that already exist.
Examples found in repository?
98async fn run(path: &Path) -> Result<()> {
99 let events = SqliteEventStore::open(path)?;
100
101 the_version_that_shipped_first(&events).await?;
102 the_upgrade(&events).await?;
103 one_log_two_encodings(&events).await?;
104 one_fold_reads_both(&events).await?;
105
106 println!("\n== final log ==");
107 print_log(&events).await?;
108
109 Ok(())
110}More examples
52async fn run(path: &Path) -> Result<()> {
53 let events = SqliteEventStore::open(path)?;
54
55 the_boundary_is_a_query()?;
56 a_name_is_held_by_one_owner(&events).await?;
57 a_released_name_is_claimable_again(&events).await?;
58 a_plan_caps_what_an_owner_holds(&events).await?;
59 one_command_delivered_twice(&events).await?;
60
61 println!("\n== what the log actually says ==");
62 print_log(&events).await?;
63
64 Ok(())
65}153async fn run(path: &Path) -> Result<()> {
154 let events = SqliteEventStore::open(path)?;
155 let models = SqliteProjectionStore::open(path)?;
156 let app = open_configured(path)?;
157 app.execute_batch(READ_MODEL_DDL)?;
158
159 seed_the_log(&events).await?;
160 two_views_two_checkpoints(&events, &models, &app).await?;
161 a_third_view_added_late(&events, &models, &app).await?;
162 reset_and_rebuild(&events, &models, &app).await?;
163 one_poisoned_view(&events, &models).await?;
164
165 writeln!(io::stdout().lock(), "\n== final log ==")?;
166 print_log(&events).await?;
167
168 Ok(())
169}127async fn before_the_reopen(path: &Path) -> Result<()> {
128 let events = SqliteEventStore::open(path)?;
129 let models = SqliteProjectionStore::open(path)?;
130 let app = open_configured(path)?;
131 app.execute_batch(READ_MODEL_DDL)?;
132
133 println!("\n== opening two accounts ==");
134 open_account(&events, "a1").await?;
135 open_account(&events, "a2").await?;
136 println!(" a1 and a2 opened");
137
138 println!("\n== depositing 100 into a1 ==");
139 deposit(&events, "a1", 100).await?;
140 println!(" deposited");
141
142 println!("\n== transferring 40 from a1 to a2 ==");
143 transfer(&events, "a1", "a2", 40).await?;
144 println!(" transferred: one append, two events, both accounts checked");
145
146 println!("\n== transferring 500 from a1 to a2 ==");
147 match transfer(&events, "a1", "a2", 500).await {
148 Ok(()) => bail!("an overdrawn transfer should have been rejected"),
149 Err(err) => println!(" rejected: {err}"),
150 }
151
152 println!("\n== projecting balances into the same file ==");
153 let mut balances = Balances::new();
154 let chunk = Chunk::of(CHUNK.try_into()?);
155 let done = run_projection(&events, &models, &mut balances, &Json, chunk).await?;
156 println!(" applied {} event(s)", done.applied);
157 print_read_model(&app)?;
158
159 Ok(())
160}
161
162/// Everything after the reopen, against the same file.
163///
164/// Nothing is carried in from above but the path.
165async fn after_the_reopen(path: &Path) -> Result<()> {
166 println!("\n== everything above is dropped; reopening the same file ==");
167 let events = SqliteEventStore::open(path)?;
168 let models = SqliteProjectionStore::open(path)?;
169 let app = open_configured(path)?;
170 println!(" reopened");
171
172 println!("\n== the read model, straight off disk ==");
173 print_read_model(&app)?;
174
175 println!("\n== the same balances, folded again from the event log ==");
176 for account in ["a1", "a2"] {
177 let balance = fold_balance(&events, account).await?;
178 println!(" {account}: {}", balance.held);
179 }
180
181 println!("\n== the checkpoint survived too ==");
182 let mut balances = Balances::new();
183 let chunk = Chunk::of(CHUNK.try_into()?);
184 let done = run_projection(&events, &models, &mut balances, &Json, chunk).await?;
185 println!(
186 " re-running the projection applied {} event(s) — the log is not replayed",
187 done.applied
188 );
189
190 println!("\n== the reopened store is live, not merely readable ==");
191 transfer(&events, "a2", "a1", 15).await?;
192 let done = run_projection(&events, &models, &mut balances, &Json, chunk).await?;
193 println!(
194 " transferred 15 back, and the projection applied {} event(s)",
195 done.applied
196 );
197 print_read_model(&app)?;
198
199 println!("\n== final log ==");
200 print_log(&events).await?;
201
202 Ok(())
203}34pub(crate) async fn run(path: PathBuf) -> Result<()> {
35 ensure_schema(&path)?;
36
37 // Built inside the runtime for the reason the API gives: ADR-0022 §9
38 // captures the tokio handle at construction.
39 let events = SqliteEventStore::open(&path)?;
40 let models = SqliteProjectionStore::open(&path)?;
41 let mut view = SeatHolders::new();
42 let chunk = Chunk::of(CHUNK.try_into()?);
43
44 println!("runner started against {}", path.display());
45
46 loop {
47 match run_projection(&events, &models, &mut view, &Json, chunk).await {
48 Ok(progress) => {
49 if progress.applied > 0 {
50 println!(
51 "applied {} event(s), through {:?}",
52 progress.applied, progress.through
53 );
54 }
55 }
56 // A failure here is reported and retried rather than fatal. The
57 // most likely one by far is `SQLITE_BUSY` surviving the busy
58 // timeout while the API holds the write lock, and a runner that
59 // exited on it would turn a moment of contention into an operator
60 // page. A *decode* failure would be permanent and would spin —
61 // which is why `rebuilding-read-models` exists to show what a
62 // policy for that looks like, and why this one says out loud that
63 // it does not have one.
64 Err(err) => eprintln!("projection pass failed: {err}"),
65 }
66
67 tokio::time::sleep(IDLE).await;
68 }
69}55pub(crate) async fn run(path: PathBuf) -> Result<()> {
56 ensure_schema(&path)?;
57
58 // Both stores are built **inside** the runtime, and that is load-bearing
59 // rather than stylistic: ADR-0022 §9 captures the tokio handle at
60 // construction, so a store built before a runtime exists records `None` and
61 // every read fails with `SqliteEventStoreError::NoRuntime`.
62 let events = SqliteEventStore::open(&path)?;
63 let models = SqliteProjectionStore::open(&path)?;
64
65 // Opening the show is idempotent by refusal: a second process starting
66 // against the same file is told the show is already open, and that is the
67 // correct answer rather than an error to report.
68 drop(open_show(&events, CAPACITY).await);
69
70 let listener = TcpListener::bind(SocketAddr::from(([127, 0, 0, 1], 0))).await?;
71 // The first line of stdout, and a contract with the demo role. Rust's
72 // stdout is line-buffered, so this reaches the pipe before `accept` blocks.
73 println!("listening on {}", listener.local_addr()?);
74
75 // The runner process derives the same id from the same view: the name and
76 // a digest of its query (PS-25). Reading under the bare name would answer
77 // `202` for ever.
78 let checkpoint = checkpoint_id(&SeatHolders::new())?;
79 let state = Arc::new(State {
80 events,
81 models,
82 checkpoint,
83 path,
84 });
85
86 loop {
87 let (stream, _) = listener.accept().await?;
88 let state = Arc::clone(&state);
89 tokio::spawn(async move {
90 if let Err(err) = serve(&state, stream).await {
91 eprintln!("connection failed: {err}");
92 }
93 });
94 }
95}pub fn open_on(connection: Connection) -> Result<Self, SqliteEventStoreError>
pub fn open_on(connection: Connection) -> Result<Self, SqliteEventStoreError>
Applies the schema on a connection the caller opened, configured and keeps, and wraps it.
open without its configuration step. No pragma is
set: the journal mode, synchronous, the busy timeout and
user_version are left as the caller set them, so a file kept in
journal_mode = TRUNCATE — where WAL’s shared-memory file cannot live —
stays there. This crate’s schema version is a row in its own
store_meta table, never user_version, which stays the caller’s.
Use it in place of new when the file may not hold a
store yet: new reads an existing schema and refuses a file without
one. On a file that already holds a store it changes nothing and reads
the identity back, exactly as open does.
What open configures becomes the caller’s to choose. In
particular, with no busy timeout set, a write that meets a lock held by
another connection is refused at once rather than waited for.
§Errors
The connection is consumed, as new consumes it, and is
closed on any of these; a caller that retries opens it again.
SqliteEventStoreError::Sqliteif the schema cannot be applied. Nothing partially migrated is left behind: every statement runs inside one transaction.SqliteEventStoreError::UnsupportedSchemaVersionif the file was written by a newer build.SqliteEventStoreError::MissingIdentityorSqliteEventStoreError::MalformedIdentityif the schema is present and its incarnation row is not readable.
pub fn open_in_memory() -> Result<Self, SqliteEventStoreError>
pub fn open_in_memory() -> Result<Self, SqliteEventStoreError>
Opens a private in-memory store and applies the schema.
A convenience for a single-handle caller, and not what a
Fixture should reach for: a
private in-memory database is per-connection, so a second connect would
open a second, empty database rather than a second handle onto this one.
WAL has nothing to switch to here, so this connection runs under the
journal mode SQLite keeps for memory databases.
§Errors
Returns SqliteEventStoreError::Sqlite if SQLite refuses the
connection or the schema cannot be applied, and the identity errors
open documents.
pub const fn store_id(&self) -> StoreId
pub const fn store_id(&self) -> StoreId
The incarnation this store mints identities under.
The same value before and after a close-and-reopen of the file, which is
what makes reopened_store_does_not_reissue_an_event_id askable: with
the incarnation held fixed, the position is what must never repeat, and
AUTOINCREMENT is the mechanism.
Examples found in repository?
32 async fn read(dir: &Path, at: Place, show: &ShowId) -> Result<Self, StoryError> {
33 let site = Site::open(dir, at)?;
34 let log = site.log(at).await?;
35 Ok(Self {
36 store: site.events.store_id(),
37 ids: log.iter().map(|event| event.id).collect(),
38 refunds: log
39 .iter()
40 .filter(|event| event.event_type() == &SALE_REFUNDED)
41 .map(|event| event.id)
42 .collect(),
43 view: site.view(show)?,
44 })
45 }pub fn settings(&self) -> Result<ConnectionSettings, SqliteEventStoreError>
pub fn settings(&self) -> Result<ConnectionSettings, SqliteEventStoreError>
What this handle’s connection is actually running under.
The values are read off the live connection rather than restated from the constants that set them: SQLite silently accepts a pragma it does not recognise, so a statement that executed is not a setting that took.
§Errors
SqliteEventStoreError::ConnectionPoisonedif another thread panicked while holding the connection.SqliteEventStoreError::Sqliteif the connection cannot answer.
pub fn remint_identity(
path: impl AsRef<Path>,
) -> Result<StoreId, SqliteEventStoreError>
pub fn remint_identity( path: impl AsRef<Path>, ) -> Result<StoreId, SqliteEventStoreError>
Replaces the database’s persisted incarnation with a freshly minted one.
§When a deployment invokes this
After restoring this file from a backup, or after copying it. This adapter mints its incarnation once, at schema creation, and reads it back on every open — the mechanism VT-6 permits only for an adapter that can detect its state was restored or cloned, or whose deployment is documented to invoke a re-mint. A SQLite file copied from Friday’s backup is undetectable from inside SQLite, so this operation is the second half of that permission rather than a convenience: without it, mint-once here would not be legitimate and this adapter would owe a fresh incarnation on every open.
Two copies of one file that keep one incarnation are two stores minting
EventIds that collide — a failure with no error path and no
observable symptom until a replication peer sees the same identity twice.
Run it with nothing else holding the database open, and before the restored copy accepts its first append: events already in the file keep the origin they were stamped with, which is correct — they were written by the incarnation that is being retired.
§Errors
SqliteEventStoreError::Sqliteif the file cannot be opened, or if another connection holds the write lock for longer than the configured busy timeout.SqliteEventStoreError::UnsupportedSchemaVersionif the file was written by a newer build — a re-mint is refused rather than applied blind to a schema this build does not know.SqliteEventStoreError::MissingIdentityorSqliteEventStoreError::MalformedIdentityif the freshly written row cannot be read back, in which case nothing is committed.
pub fn remint_identity_on(
connection: &mut Connection,
) -> Result<StoreId, SqliteEventStoreError>
pub fn remint_identity_on( connection: &mut Connection, ) -> Result<StoreId, SqliteEventStoreError>
remint_identity on a connection the caller
opened, configured and keeps.
The same re-mint, under the same procedure — nothing else holding the
database open, and before the copy accepts its first append — for a
caller that cannot let the path form reconfigure its file. No pragma is
set: the journal mode, synchronous, the busy timeout and
user_version are left as the caller set them, so a file kept in
journal_mode = TRUNCATE stays there. The path form switches it to WAL.
The connection is borrowed rather than consumed because the natural next
step is new on it, which reads the fresh identity back.
A store already wrapping another connection onto this file goes on
holding the retired identity, and refuses its next append with
IdentityMoved.
The schema is applied first if the file has none, as
open_on applies it.
§Errors
SqliteEventStoreError::Sqliteif the schema cannot be applied or the write lock cannot be taken. With no busy timeout set on the connection, a lock held elsewhere is refused at once rather than waited for.SqliteEventStoreError::UnsupportedSchemaVersionif the file was written by a newer build.SqliteEventStoreError::MissingIdentityorSqliteEventStoreError::MalformedIdentityif the freshly written row cannot be read back, in which case nothing is committed.
Trait Implementations§
§impl Clone for SqliteEventStore
impl Clone for SqliteEventStore
§impl Debug for SqliteEventStore
impl Debug for SqliteEventStore
§impl SendEventStore for SqliteEventStore
impl SendEventStore for SqliteEventStore
§async fn append(
&self,
events: &[Event],
condition: Option<&AppendCondition>,
) -> Result<SequencePosition, AppendError<Self::Error>>
async fn append( &self, events: &[Event], condition: Option<&AppendCondition>, ) -> Result<SequencePosition, AppendError<Self::Error>>
Appends events, refusing the write if condition is violated.
The body is mostly order, and the order is the specification rather
than a style: two of its four steps decide what happens before any
SQL runs, and the fourth decides that everything remaining happens inside
exactly one BEGIN IMMEDIATE transaction — the write lock taken before
the condition is read and held to commit, so the snapshot the guard sees
is the snapshot the insert writes into and no second writer can fit
between the two halves.
A probe followed by an unrelated insert is the wrong implementation this whole port exists to reject: it passes every single-threaded rule forever, and fails only when two writers decide from the same state.
Returns the position assigned to the last event of this batch, in slice order — never the store head, which is a different number the moment another connection commits.
§Errors
Named by condition rather than by type:
- the batch was empty — decided first, before the condition is read, because rebuild the decision model and retry is not advice a caller can act on for an empty batch;
- one event’s
datawas larger thanMAX_EVENT_DATA_LEN, one event carried more tags thanMAX_TAGS_PER_EVENT, or the batch held more events thanMAX_EVENTS_PER_BATCH— each reported as a capacity refusal carrying the magnitude that exceeded it, never as a store failure and never by truncating, so that a caller can tell this will never fit here from the disk is full, retry; - a guard of the condition matched an event strictly after its boundary, in which case the transaction rolls back and the file is unchanged;
- the write lock was not acquired before the configured busy timeout
elapsed —
SQLITE_BUSYorSQLITE_LOCKEDfromBEGIN IMMEDIATE— which is reported asAppendError::Busy: contention, before any statement of this append ran, so nothing was written and deciding again is safe. It is neither a condition violation nor a store failure; - the driver failed in any other way, a busy code raised after
BEGIN IMMEDIATEsucceeded included, which isAppendError::Store; - another thread panicked while holding this store’s connection.
§async fn head(&self) -> Result<Option<SequencePosition>, Self::Error>
async fn head(&self) -> Result<Option<SequencePosition>, Self::Error>
The highest position any reader can currently observe, or None on an
empty store.
Asked of the database every time, and that is the whole of it. What
this must never become is a field the store caches and append updates:
one file backs several handles, so a second connection would then report
a head that predates the first connection’s commit — the stale head ES-30
exists to reject, and the defect a single-handle test cannot see.
§Errors
- another thread panicked while holding this store’s connection;
- the driver failed, or a stored position is not one the contract can represent.
§async fn contains_event_id(&self, id: EventId) -> Result<bool, Self::Error>
async fn contains_event_id(&self, id: EventId) -> Result<bool, Self::Error>
Whether this store already holds the event id names.
The probe seeks the UNIQUE (origin_store, origin_position) index
migration 1 created — one constraint serving two jobs: this lookup, and
the guard that keeps ingest from storing one event twice.
§Errors
- another thread panicked while holding this store’s connection;
- the driver failed.
§type Error = SqliteEventStoreError
type Error = SqliteEventStoreError
§fn read(
&self,
query: &Query,
options: ReadOptions,
) -> impl Stream<Item = Result<SequencedEvent, Self::Error>> + Send
fn read( &self, query: &Query, options: ReadOptions, ) -> impl Stream<Item = Result<SequencedEvent, Self::Error>> + Send
§impl SendIngestStore for SqliteEventStore
Available on crate feature sync only.
impl SendIngestStore for SqliteEventStore
sync only.§async fn store_id(&self) -> Result<StoreId, Self::Error>
async fn store_id(&self) -> Result<StoreId, Self::Error>
Never fails: the identity was read when the store was opened.
§type Error = SqliteEventStoreError
type Error = SqliteEventStoreError
§async fn ingest(
&self,
groups: &[IngestGroup<'_>],
) -> Result<Ingested, IngestError<Self::Error>>
async fn ingest( &self, groups: &[IngestGroup<'_>], ) -> Result<Ingested, IngestError<Self::Error>>
§impl SendWriteGroupStore for SqliteEventStore
Available on crate feature sync only.The log in the writes that made it (SY-39), from the columns migration 2
added: what a runner pushes from and a StoreSyncPeer serves a pull from.
The Send flavour, for the reason the impl above gives.
impl SendWriteGroupStore for SqliteEventStore
sync only.The log in the writes that made it (SY-39), from the columns migration 2
added: what a runner pushes from and a StoreSyncPeer serves a pull from.
The Send flavour, for the reason the impl above gives.
§type Error = SqliteEventStoreError
type Error = SqliteEventStoreError
§async fn read_groups(
&self,
after: Option<SequencePosition>,
max_events: NonZeroUsize,
) -> Result<GroupPage, Self::Error>
async fn read_groups( &self, after: Option<SequencePosition>, max_events: NonZeroUsize, ) -> Result<GroupPage, Self::Error>
Auto Trait Implementations§
impl Freeze for SqliteEventStore
impl RefUnwindSafe for SqliteEventStore
impl Send for SqliteEventStore
impl Sync for SqliteEventStore
impl Unpin for SqliteEventStore
impl UnsafeUnpin for SqliteEventStore
impl UnwindSafe for SqliteEventStore
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<TraitVariantBlanketType> EventStore for TraitVariantBlanketTypewhere
TraitVariantBlanketType: SendEventStore,
impl<TraitVariantBlanketType> EventStore for TraitVariantBlanketTypewhere
TraitVariantBlanketType: SendEventStore,
Source§type Error = <TraitVariantBlanketType as SendEventStore>::Error
type Error = <TraitVariantBlanketType as SendEventStore>::Error
Source§fn read(
&self,
query: &Query,
options: ReadOptions,
) -> impl Stream<Item = Result<SequencedEvent, <TraitVariantBlanketType as EventStore>::Error>>
fn read( &self, query: &Query, options: ReadOptions, ) -> impl Stream<Item = Result<SequencedEvent, <TraitVariantBlanketType as EventStore>::Error>>
Source§async fn append(
&self,
events: &[Event],
condition: Option<&AppendCondition>,
) -> Result<SequencePosition, AppendError<<TraitVariantBlanketType as EventStore>::Error>>
async fn append( &self, events: &[Event], condition: Option<&AppendCondition>, ) -> Result<SequencePosition, AppendError<<TraitVariantBlanketType as EventStore>::Error>>
Source§async fn head(
&self,
) -> Result<Option<SequencePosition>, <TraitVariantBlanketType as EventStore>::Error>
async fn head( &self, ) -> Result<Option<SequencePosition>, <TraitVariantBlanketType as EventStore>::Error>
None when it
holds nothing. Read moreSource§async fn contains_event_id(
&self,
id: EventId,
) -> Result<bool, <TraitVariantBlanketType as EventStore>::Error>
async fn contains_event_id( &self, id: EventId, ) -> Result<bool, <TraitVariantBlanketType as EventStore>::Error>
id. Read more