src/Db.bend fails
raw source on the hub · import mylsm-lsm-store@0.3.2.0/src/Db.bend as Db
9 imports
import Base import ./Keys.bend as Keys import ./MemTable.bend as MemTable import ./Sstable.bend as Sstable import ./Wal.bend as Wal import ./Fs.bend as Fs import ./Manifest.bend as Manifest import ./Decimal.bend as Decimal import ./CrashPoint.bend as CrashPoint
Types
type BEntry source · line 29 · raw
Data
BEntry@tab:String -> @key:String -> @val:Maybe<&2, String> -> BEntry
type Db source · line 40 · raw
Data
manifest_token is the exact serialized Manifest observed by this handle. Flush and compaction compare it before publication to reject stale-handle drift.
Db@dir:String -> @mem:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @frozen:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @batch_cap:Nat -> @bcache:List<&2, BEntry> -> @levels:List<&2, List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Sstable.Table>> -> @flushed:Nat -> @manifest_token:String -> @mem_count:Nat -> @frozen_count:Nat -> Db
type RotRes source · line 46 · raw
Data
Rotation result: both tables plus their exact counts, so no pass ever walks a memtable to learn its size. Counts stay exact by construction (open_db starts 0/0; every transition does arithmetic, never List.length).
Rot@mem:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @frozen:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @mem_count:Nat -> @frozen_count:Nat -> RotRes
type ReChunk source · line 346 · raw
Data
ReChunk@bytes:Nat -> @text:String -> ReChunk
Definitions
def default_batch_cap source · line 32 · raw
Nat
def bcache_bound source · line 35 · raw
Nat
def wal_path source · line 49 · raw
@+dir:String -> String
def open_db source · line 52 · raw
@+dir:String -> Db
def apply_mut source · line 57 · raw
@+mem:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @+mut:0x9b667819f2297aa52572c1e6523fa301/src/Wal.Mut -> 0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable
def apply_batch source · line 64 · raw
@+muts:List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Wal.Mut> -> @+mem:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> 0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable
def table_entries source · line 73 · raw
@+tab:0x9b667819f2297aa52572c1e6523fa301/src/Sstable.Table -> List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/MemTable.Entry>
def level_entries source · line 78 · raw
@+tabs:List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Sstable.Table> -> List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/MemTable.Entry>
def all_level_entries source · line 85 · raw
@+lvls:List<&2, List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Sstable.Table>> -> List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/MemTable.Entry>
def all_entries source · line 92 · raw
@+db:Db -> List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/MemTable.Entry>
def table_hit_if source · line 99 · raw
@present:Bool -> @tab:0x9b667819f2297aa52572c1e6523fa301/src/Sstable.Table -> @+key:String -> Maybe<&2, Maybe<&2, String>>
def table_hit source · line 106 · raw
@+tab:0x9b667819f2297aa52572c1e6523fa301/src/Sstable.Table -> @+key:String -> Maybe<&2, Maybe<&2, String>>
def tables_hits source · line 109 · raw
@+tabs:List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Sstable.Table> -> @+key:String -> List<&2, Maybe<&2, Maybe<&2, String>>>
def levels_hits source · line 116 · raw
@+lvls:List<&2, List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Sstable.Table>> -> @+key:String -> List<&2, Maybe<&2, Maybe<&2, String>>>
def hits_first source · line 123 · raw
@+hits:List<&2, Maybe<&2, Maybe<&2, String>>> -> Maybe<&2, Maybe<&2, String>>
def flatten_opt source · line 132 · raw
@+opt:Maybe<&2, Maybe<&2, String>> -> Maybe<&2, String>
def db_get source · line 139 · raw
@+db:Db -> @+key:String -> Maybe<&2, String>
def pick_hit source · line 150 · raw
@hit:Bool -> @ans:Maybe<&2, String> -> @best:Maybe<&2, Maybe<&2, String>> -> Maybe<&2, Maybe<&2, String>>
def bcache_go source · line 157 · raw
@+cache:List<&2, BEntry> -> @+tab:String -> @+key:String -> @+best:Maybe<&2, Maybe<&2, String>> -> Maybe<&2, Maybe<&2, String>>
def bcache_lookup source · line 164 · raw
@+cache:List<&2, BEntry> -> @+tab:String -> @+key:String -> Maybe<&2, Maybe<&2, String>>
def bcache_push_all source · line 167 · raw
@+fresh:List<&2, BEntry> -> @+old:List<&2, BEntry> -> List<&2, BEntry>
def probe_fill source · line 170 · raw
@hit:Maybe<&2, Maybe<&2, String>> -> @+tab:String -> @+key:String -> Pair(Maybe<&2, Maybe<&2, String>>, List<&2, BEntry>)
def probe_cached source · line 177 · raw
@cached:Maybe<&2, Maybe<&2, String>> -> @+tab:0x9b667819f2297aa52572c1e6523fa301/src/Sstable.Table -> @+key:String -> Pair(Maybe<&2, Maybe<&2, String>>, List<&2, BEntry>)
def table_probe source · line 184 · raw
@+tab:0x9b667819f2297aa52572c1e6523fa301/src/Sstable.Table -> @+key:String -> @+cache:List<&2, BEntry> -> Pair(Maybe<&2, Maybe<&2, String>>, List<&2, BEntry>)
def tables_cons source · line 187 · raw
@cur:Pair(Maybe<&2, Maybe<&2, String>>, List<&2, BEntry>) -> @rest:Pair(List<&2, Maybe<&2, Maybe<&2, String>>>, List<&2, BEntry>) -> Pair(List<&2, Maybe<&2, Maybe<&2, String>>>, List<&2, BEntry>)
def tables_walk source · line 194 · raw
@+tabs:List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Sstable.Table> -> @+key:String -> @+cache:List<&2, BEntry> -> Pair(List<&2, Maybe<&2, Maybe<&2, String>>>, List<&2, BEntry>)
def levels_cons source · line 201 · raw
@cur:Pair(List<&2, Maybe<&2, Maybe<&2, String>>>, List<&2, BEntry>) -> @rest:Pair(List<&2, Maybe<&2, Maybe<&2, String>>>, List<&2, BEntry>) -> Pair(List<&2, Maybe<&2, Maybe<&2, String>>>, List<&2, BEntry>)
def levels_cached source · line 208 · raw
@+lvls:List<&2, List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Sstable.Table>> -> @+key:String -> @+cache:List<&2, BEntry> -> Pair(List<&2, Maybe<&2, Maybe<&2, String>>>, List<&2, BEntry>)
def cached_levels source · line 215 · raw
@lr:Pair(List<&2, Maybe<&2, Maybe<&2, String>>>, List<&2, BEntry>) -> @+dir:String -> @+mem:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @+frozen:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @+batch_cap:Nat -> @+bcache:List<&2, BEntry> -> @+levels:List<&2, List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Sstable.Table>> -> @+flushed:Nat -> @+manifest_token:String -> @+mem_count:Nat -> @+frozen_count:Nat -> Pair(Db, Maybe<&2, String>)
def cached_frozen source · line 220 · raw
@fhit:Maybe<&2, Maybe<&2, String>> -> @+dir:String -> @+mem:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @+frozen:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @+batch_cap:Nat -> @+bcache:List<&2, BEntry> -> @+levels:List<&2, List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Sstable.Table>> -> @+flushed:Nat -> @+manifest_token:String -> @+key:String -> @+mem_count:Nat -> @+frozen_count:Nat -> Pair(Db, Maybe<&2, String>)
def cached_mem source · line 227 · raw
@mhit:Maybe<&2, Maybe<&2, String>> -> @+dir:String -> @+mem:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @+frozen:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @+batch_cap:Nat -> @+bcache:List<&2, BEntry> -> @+levels:List<&2, List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Sstable.Table>> -> @+flushed:Nat -> @+manifest_token:String -> @+key:String -> @+mem_count:Nat -> @+frozen_count:Nat -> Pair(Db, Maybe<&2, String>)
def db_get_cached source · line 234 · raw
@+db:Db -> @+key:String -> Pair(Db, Maybe<&2, String>)
def wal_frame source · line 242 · raw
@+data:String -> String
WAL framing v1 is applied here (see Recover): each batch is stored as dashes(len) ++ ";" ++ encode(batch) so replay can stream frames and truncate a torn tail. Files are permissioned 0600 at creation.
def wal_tail source · line 247 · raw
@fr:Pair(File, Result<&1, &1, Pair(U32, String), Unit>) -> @+dir:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)
Tail of the append: match heads the def body (params always destructurable), so the write's pair splits with single uses.
def wal_append source · line 259 · raw
@+dir:String -> @+data:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)
def batch_len source · line 265 · raw
@+muts:List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Wal.Mut> -> Nat
def rotate_cnt source · line 268 · raw
@full:Bool -> @+grown:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @+frozen:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @+count:Nat -> @+fcount:Nat -> RotRes
def frozen_empty source · line 275 · raw
@+frozen:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> Bool
def rotate_after source · line 284 · raw
@+grown:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @+frozen:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @+count:Nat -> @+fcount:Nat -> RotRes
def apply_and_rotate source · line 287 · raw
@+muts:List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Wal.Mut> -> @+mem:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @+frozen:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @+mem_count:Nat -> @+frozen_count:Nat -> RotRes
def apply_done source · line 290 · raw
@res:RotRes -> @+dir:String -> @+batch_cap:Nat -> @+bcache:List<&2, BEntry> -> @+levels:List<&2, List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Sstable.Table>> -> @+flushed:Nat -> @+manifest_token:String -> Db
def rot_done source · line 295 · raw
@res:RotRes -> @+dir:String -> @+batch_cap:Nat -> @+bcache:List<&2, BEntry> -> @+levels:List<&2, List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Sstable.Table>> -> @+flushed:Nat -> @+manifest_token:String -> Result<&1, &1, Pair(U32, String), Db>
def db_write source · line 298 · raw
@+db:Db -> @+batch:0x9b667819f2297aa52572c1e6523fa301/src/Wal.Batch -> IO(Result<&1, &1, Pair(U32, String), Db>)
def db_put source · line 307 · raw
@+db:Db -> @+key:String -> @+val:String -> IO(Result<&1, &1, Pair(U32, String), Db>)
def batch_cap_of source · line 310 · raw
@+db:Db -> Nat
def with_batch_cap source · line 315 · raw
@+db:Db -> @+cap:Nat -> Db
def staged_muts source · line 320 · raw
@+staged:List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Wal.Batch> -> List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Wal.Mut>
def db_write_staged source · line 327 · raw
@+db:Db -> @+staged:List<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Wal.Batch> -> IO(Result<&1, &1, Pair(U32, String), Db>)
def db_del source · line 332 · raw
@+db:Db -> @+key:String -> IO(Result<&1, &1, Pair(U32, String), Db>)
def reopen_chunk_chars source · line 343 · raw
Nat
def reopen_chunk_parse source · line 349 · raw
@pair:0x9b667819f2297aa52572c1e6523fa301/src/Decimal.Parse -> Result<&1, &1, Pair(U32, String), ReChunk>
def reopen_dash_step source · line 356 · raw
@+done:Bool -> @isdash:Bool -> @+acc:Nat -> Pair(Bool, Nat)
def reopen_dash_snd source · line 367 · raw
@st:Pair(Bool, Nat) -> Nat
def reopen_dash_fst source · line 372 · raw
@st:Pair(Bool, Nat) -> @+ch:Char -> Pair(Bool, Nat)
def reopen_dash_go source · line 377 · raw
@fuel:Nat -> @st:Pair(Bool, Nat) -> @str:String -> Nat
def reopen_dashes_len source · line 388 · raw
@+str:String -> Nat
def reopen_semi_is source · line 391 · raw
@eq:Bool -> @+num:Nat -> Maybe<&2, Nat>
def reopen_semi source · line 398 · raw
@+ch:Char -> @+num:Nat -> Maybe<&2, Nat>
def reopen_semi_go source · line 401 · raw
@dropped:String -> @+num:Nat -> Maybe<&2, Nat>
def reopen_frame_len source · line 408 · raw
@+str:String -> Maybe<&2, Nat>
def reopen_consumed source · line 412 · raw
@+num:Nat -> Nat
def reopen_clip source · line 415 · raw
@+mlen:Maybe<&2, Nat> -> @+str:String -> String
def reopen_drop source · line 422 · raw
@+mlen:Maybe<&2, Nat> -> @+str:String -> String
def reopen_dec_apply source · line 429 · raw
@+m2:Maybe<&2, 0x9b667819f2297aa52572c1e6523fa301/src/Wal.Batch> -> @+res:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> 0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable
def reopen_replay_go source · line 436 · raw
@fuel:Nat -> @+mem:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @+str:String -> 0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable
def reopen_replay source · line 444 · raw
@+str:String -> 0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable
def reopen_assemble source · line 447 · raw
@+mem:0x9b667819f2297aa52572c1e6523fa301/src/MemTable.MemTable -> @+dir:String -> Db
def reopen_read_loop source · line 453 · raw
@chunks_left:Nat -> @+path:String -> @+offset:Nat -> @+acc:String -> @pending:Maybe<&2, ReChunk> -> IO(Result<&1, &1, Pair(U32, String), String>)
Chunked WAL reader (SstStream.stream_loop shape): the freshly read chunk
re-enters as the pending parameter, so every match scrutinee is a
parameter or field and the loop is a single self-recursive def.
def reopen_read source · line 469 · raw
@+dir:String -> IO(Result<&1, &1, Pair(U32, String), Db>)
def reopen_exists source · line 474 · raw
@ok:Result<&1, &1, Pair(U32, String), Bool> -> @+dir:String -> IO(Result<&1, &1, Pair(U32, String), Db>)
def reopen source · line 485 · raw
@+dir:String -> IO(Result<&1, &1, Pair(U32, String), Db>)