| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Ouroboros.Consensus.Storage.LeiosDB.Impl.SQLite.Queries
Description
The SQL text of every statement the SQLite-backed LeiosDB runs. The schema they run against is in Ouroboros.Consensus.Storage.LeiosDB.Impl.SQLite.Schema.
Synopsis
- sql_scan_ebs ∷ String
- sql_scan_complete_ebs_since ∷ String
- sql_insert_eb ∷ String
- sql_lookup_ebBodies ∷ String
- sql_insert_ebBody ∷ String
- sql_insert_tx ∷ String
- sql_filter_missing_txs_json ∷ String
- sql_find_complete_ebs ∷ String
- sql_mark_notified_ebs ∷ String
- sql_decrement_missing_tx_count ∷ String
- sql_delete_missing_txs ∷ String
- sql_insert_missing_txs ∷ String
- sql_init_missing_tx_count ∷ String
- sql_mark_point_notified ∷ String
- sql_retrieve_from_ebTxs_json ∷ String
- sql_lookup_eb_closure ∷ String
- sql_scan_recent_ebs ∷ String
- sql_pin_eb ∷ String
- sql_mark_as_copied ∷ String
- sql_copy_completeness ∷ String
- sql_copy_insert_eb ∷ String
- sql_copy_insert_ebTxs ∷ String
- sql_copy_insert_txs ∷ String
- sql_imm_filter_present ∷ String
- sql_next_pinned_eb ∷ String
- sql_gc_has_work ∷ String
- sql_gc_markable ∷ String
- sql_gc_stage_marked ∷ String
- sql_gc_mark ∷ String
- sql_sweep_pick_marked ∷ String
- sql_gc_ebTxs ∷ String
- sql_gc_missing_txs ∷ String
- sql_gc_ebs_by_hash ∷ String
- sql_sweep_any_marked ∷ String
- sql_sweep_pick_orphans ∷ String
- sql_sweep_orphan_txs ∷ String
- sql_sweep_pop_orphans ∷ String
- sql_has_unstaged_gc_candidates ∷ String
- sql_unstaged_gc_candidates_page ∷ String
- sql_insert_gc_candidates ∷ String
Documentation
sql_scan_complete_ebs_since ∷ String Source #
For sqlScanCompleteEbPointsSince
The two conditions are decoupled across rows: the same EB hash can have
several (ebSlot, ebHashBytes) rows (one per announcer slot), and
missingTxCount is maintained per row on body insert but per hash on tx
arrival, so the complete row and the recent row can differ. Requiring
both on a single row would wrongly drop a complete EB re-announced recently
(its recent row never got a body insert, so its missingTxCount is still
NULL), leaving its cert-RB parked forever. Hence: keep a hash that has
any complete row and any row at ebSlot >= ?.
sql_filter_missing_txs_json ∷ String Source #
Batch-filter txHashes via JSON1. Parameter is a JSON array of hex
strings; 'unhex(je.value)' decodes back into a BLOB comparable against
the indexed txs.txHashBytes column.
sql_find_complete_ebs ∷ String Source #
Find EBs that are now complete (missingTxCount reached 0). Volatile rows only: completion is decided within the one coherent volatile set.
sql_mark_notified_ebs ∷ String Source #
Mark complete EBs as notified so they are not found again by
sql_find_complete_ebs. Uses -1 as a sentinel for "already notified".
sql_decrement_missing_tx_count ∷ String Source #
Decrement missingTxCount for every EB still waiting on the given txHash.
Uses ebsMissingTxs rather than ebTxs, which makes this more efficient
than a full scan of ebTxs in the average case.
Must be paired with sql_delete_missing_txs in the same transaction.
Parameter 1: txHashBytes
sql_delete_missing_txs ∷ String Source #
Retire the waiting rows for a tx that has just landed. Parameter 1: txHashBytes
sql_insert_missing_txs ∷ String Source #
Record which of a freshly-inserted body's txs we do not yet hold.
One anti-join over the EB's own ebTxs range -- the same work
sql_init_missing_tx_count used to do to produce a count, now materialised so
that the arrival side reads the rows instead of recomputing them. Paying it
here rather than on every tx arrival is what earns the index removal: this
runs once per body, against ~4.7 times per tx for the old reverse lookup.
Parameter 1: ebHashBytes
sql_init_missing_tx_count ∷ String Source #
Initialize missingTxCount after EB body is inserted, returning the
resulting count. Counts ebTxs entries that don't yet have a corresponding
tx in the txs table. The RETURNING clause lets the caller detect the
special case missingTxCount = 0 (all referenced txs already present) with
a PK lookup on the row that was just touched, instead of a full-table
scan via sql_find_complete_ebs.
Parameters: 1 = ebHashBytes, 2 = ebHashBytes, 3 = ebSlot
sql_mark_point_notified ∷ String Source #
Mark a specific EB as notified (missingTxCount = -1). PK-scoped
variant of sql_mark_notified_ebs; used by sqlInsertEbBody when the
body's arrival is what completed the closure.
Parameters: 1 = ebSlot, 2 = ebHashBytes
sql_retrieve_from_ebTxs_json ∷ String Source #
Batch retrieve of tx bytes for a batch of (ebHash, offset) points.
?1 is the ebHash blob (all offsets belong to the same EB); ?2 is a
JSON int array of offsets. The join uses ebTxs' PK
(ebHashBytes, txOffset), so index lookups still fire.
sql_scan_recent_ebs ∷ String Source #
Every recent announcement, with or without completeness evidence.
Companion of sql_scan_complete_ebs_since: the difference of the two sets
is probed against the immutable partition (see
sqlScanCompleteEbPointsSince).
Pin every announcement row of the EB: certified, awaiting copy, never
evicted. The durable record that survives a crash before the copy lands.
Also rescues GC-marked rows (status = 3): a promotion arriving between
mark and sweep unmarks the hash, and the sweeper's all-marked pick
then skips it.
sql_mark_as_copied ∷ String Source #
Mark a pinned EB as copied (evictable). A volatile write, so it goes
through the writer as MarkCopied -- only ever strictly after the
immutable partition committed the EB's closure.
sql_copy_completeness ∷ String Source #
Body row count and closure row count of the EB in the volatile partition, in one probe: the LEFT JOIN's second count skips missing txs, so the EB's closure is complete iff both counts are equal (and non-zero).
sql_copy_insert_eb ∷ String Source #
Copy the EB's newest announcement row. Only the columns the immutable
partition has (sql_schema_imm): completeness and GC status are
volatile-only.
OR IGNORE: the mark that retires the pin is a separate volatile write, so
a crash in between leaves the EB copied and still pinned, and the copier
repeats the copy on the next start.
sql_copy_insert_ebTxs ∷ String Source #
Copy the EB's body rows. OR IGNORE for the same reason as
sql_copy_insert_eb.
sql_copy_insert_txs ∷ String Source #
Copy the EB's txs. OR IGNORE: a tx shared with an earlier-copied EB is
already present.
sql_imm_filter_present ∷ String Source #
Which of the given hashes (JSON hex array) the immutable partition holds. Presence is proof of a complete closure: copies land atomically and only complete EBs are copied.
sql_next_pinned_eb ∷ String Source #
Pinned EBs the copier has not marked as copied yet, for self-heal
re-enqueueing.
| The next EB waiting to be copied into the immutable partition: pinned
(sql_pin_eb) but not yet marked copied (sql_mark_as_copied). Oldest
first, and covered by idx_ebs_pinned.
The pin is the copy work list. It is in the database rather than in memory, so a copy interrupted by a crash is simply still pending on the next start.
sql_gc_has_work ∷ String Source #
Whether a GC at slot ?1 could has any work, i.e.
if there are any old volatile EBs, already copied EBs or leftover EBs
from an interrupted GC pass.
sql_gc_markable ∷ String Source #
The markability predicate, shared by sql_gc_mark and
sql_gc_stage_marked so the marked set and the staged set can never
diverge. c is the row under test; it is markable if it is
- old enough (its slot is before the GC frontier ?1) and
- either volatile (status 0) or already copied (status 2) and
- not vetoed by a live row of the same hash (pinned, or announced at or
after the frontier).
sql_gc_stage_marked ∷ String Source #
Add the txs of every EB sql_gc_mark is about to hit as GC candidates.
Must run strictly BEFORE sql_gc_mark in the same transaction:
the UPDATE changes the status of EBs and orphans the transactions.
Mark for GC (status = 3) every row satisfying sql_gc_markable.
sql_sweep_pick_marked ∷ String Source #
Up to ?1 GC-marked EBs ready to sweep.
Intuition: give me up to N hash values that are currently in status 3 and have never been assigned any status other than 3.
Note: 'FROM ebs cand' and 'FROM ebs live' allows referring to the rows
of the ebs table using the alias cand and live.
TODO(geo2a): think how to simplify this query.
sql_gc_ebTxs ∷ String Source #
Evict the ebTxs rows with the specified ebHashBytes (a JSON array of byte strings).
sql_gc_missing_txs ∷ String Source #
Evict the ebsMissingTxs rows with the specified ebHashBytes (a JSON array of byte strings).
sql_gc_ebs_by_hash ∷ String Source #
Evict the ebs rows with the specified ebHashBytes (a JSON array of byte strings).
sql_sweep_any_marked ∷ String Source #
Whether any GC-marked EBs remain.
sql_sweep_pick_orphans ∷ String Source #
Get up to ?1 transactions to be evicted.
sql_sweep_orphan_txs ∷ String Source #
Evict transactions with the specified hashes (a JSON array of byte strings), making sure that they are not referenced by any EBs.
sql_sweep_pop_orphans ∷ String Source #
Delete GC transaction candidates with the specified hashes (a JSON array of byte strings).
sql_has_unstaged_gc_candidates ∷ String Source #
Whether the volatile partition holds any unstaged GC candidates (txs no EB references).
sql_unstaged_gc_candidates_page ∷ String Source #
One keyset page of unstaged GC candidates (txs no EB references), for
gcReinit: ?1 = cursor (exclusive), ?2 = page size.
sql_insert_gc_candidates ∷ String Source #
Stage one page of GC candidates (JSON hex array ?1).