src/DurableDb.bend relies on unsafe/foreign
raw source on the hub · import mylsm-lsm-store@0.5.0.0/src/DurableDb.bend as DurableDb
16 imports
import Base import ./Db.bend as Db import ./DbLock.bend as DbLock import ./DbIo.bend as DbIo import ./DurableCommit.bend as Commit import ./DurableError.bend as DurableError import ./DurableDbPolicy.bend as Policy import ./Fs.bend as Fs import ./Recover.bend as Recover import ./Flush.bend as Flush import ./Manifest.bend as Manifest import ./CompactIo.bend as Compact import ./Wal.bend as Wal import ./DurableBatchPolicy.bend as BatchPolicy import ./MemTable.bend as MemTable import bend-kit-bytes@0.3.2.0/bytes.bend as Bytes
Types
type Handle source · line 19 · raw
Type
Owns the database, lock, and lifecycle state.
Handle@path:String -> @lock:0x4fcd94fa965aa1443134557fd075a483/src/DbLock.Lock -> @db:0x4fcd94fa965aa1443134557fd075a483/src/Db.Db -> @state:0x4fcd94fa965aa1443134557fd075a483/src/DurableDbPolicy.HandleState -> @operation_errors:Nat -> Handle
type Stats source · line 23 · raw
Data
Collects bounded database, cache, and error counters.
Stats@active_bytes:Nat -> @wal_bytes:Nat -> @memtable_entries:Nat -> @memtable_payload_bytes:Nat -> @cache_entries:Nat -> @operation_errors:Nat -> @state:0x4fcd94fa965aa1443134557fd075a483/src/DurableDbPolicy.HandleState -> Stats
type Maintenance source · line 27 · raw
Data
Tracks whether post-commit maintenance is safe to continue.
MaintainedMaintenance
Pending@error:0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error -> Maintenance
type WriteOutcome source · line 32 · raw
Data
Separates commit confirmation from maintenance status.
WriteOutcome@maintenance:Maintenance -> WriteOutcome
type StatsNamesState source · line 387 · raw
Type
Tracks directory entries while collecting active-file sizes.
StatsNames@names:List<&2, String> -> @dir:String -> @total:Nat -> StatsNamesState
StatsNamesSized@result:Result<&1, &1, Pair(U32, String), Nat> -> @names:List<&2, String> -> @dir:String -> @total:Nat -> StatsNamesState
type StatsLevelsState source · line 414 · raw
Type
Tracks Manifest levels while collecting active-file sizes.
StatsLevels@levels:List<&2, List<&2, String>> -> @index:Nat -> @dir:String -> @total:Nat -> StatsLevelsState
StatsLevelsSized@result:Result<&1, &1, Pair(U32, String), Nat> -> @levels:List<&2, List<&2, String>> -> @index:Nat -> @dir:String -> @total:Nat -> StatsLevelsState
Definitions
def create_error.kind source · line 35 · raw
@exists:Bool -> @+code:U32 -> @message:String -> @+path:String -> 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error
def create_error.code source · line 42 · raw
@+code:U32 -> @message:String -> @+path:String -> 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error
def open_error.kind source · line 45 · raw
@missing:Bool -> @code:U32 -> @message:String -> @operation:String -> @path:String -> 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error
def open_error source · line 53 · raw
@+code:U32 -> @message:String -> @operation:String -> @path:String -> 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error
Performs the open error operation and returns its result.
def open_result source · line 57 · raw
@result:Result<&1, &1, Pair(U32, String), 0x4fcd94fa965aa1443134557fd075a483/src/Db.Db> -> @lock:0x4fcd94fa965aa1443134557fd075a483/src/DbLock.Lock -> @operation:String -> @+path:String -> IO(Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Handle>)
Performs the open result operation and returns its result.
def locked_result source · line 73 · raw
@result:Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, 0x4fcd94fa965aa1443134557fd075a483/src/DbLock.Lock> -> @operation:String -> @+path:String -> IO(Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Handle>)
Continues existing-open recovery after acquiring the database lock.
def preflight_manifest source · line 87 · raw
@manifest:Result<&1, &1, Pair(U32, String), 0x4fcd94fa965aa1443134557fd075a483/src/Manifest.Manifest> -> @+path:String -> IO(Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Handle>)
Acquires ownership only after validating the existing Manifest.
def preflight_result source · line 101 · raw
@result:Result<&1, &1, Pair(U32, String), Bool> -> @+path:String -> IO(Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Handle>)
Rejects a missing Manifest or begins validating the existing one.
def open_existing source · line 118 · raw
@+path:String -> IO(Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Handle>)
Opens and recovers an existing database under its lock.
def create_locked source · line 124 · raw
@result:Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, 0x4fcd94fa965aa1443134557fd075a483/src/DbLock.Lock> -> @+path:String -> IO(Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Handle>)
Performs the create locked operation and returns its result.
def created_dir source · line 137 · raw
@result:Result<&1, &1, Pair(U32, String), Unit> -> @+path:String -> IO(Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Handle>)
Acquires ownership after reserving the new database directory.
def create source · line 151 · raw
@+path:String -> IO(Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Handle>)
Creates a database and returns its owned durable handle.
def close source · line 157 · raw
@handle:Handle -> IO(Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Unit>)
Closes the durable handle and releases its database lock.
def get_result source · line 163 · raw
@state:0x4fcd94fa965aa1443134557fd075a483/src/DurableDbPolicy.HandleState -> @pair:Pair(0x4fcd94fa965aa1443134557fd075a483/src/Db.Db, Maybe<&2, String>) -> @lock:0x4fcd94fa965aa1443134557fd075a483/src/DbLock.Lock -> @+operation_errors:Nat -> @+path:String -> Pair(Handle, Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Maybe<&2, String>>)
Returns a value for readable handles and rejects reads after uncertain commit.
def get source · line 188 · raw
@handle:Handle -> @+key:String -> IO(Pair(Handle, Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Maybe<&2, String>>))
Reads a key from the owned durable database handle.
def maintenance_after_commit source · line 195 · raw
@result:Result<&1, &1, Pair(U32, String), 0x4fcd94fa965aa1443134557fd075a483/src/Db.Db> -> @+committed:0x4fcd94fa965aa1443134557fd075a483/src/Db.Db -> @lock:0x4fcd94fa965aa1443134557fd075a483/src/DbLock.Lock -> @operation_errors:Nat -> @+path:String -> IO(Pair(Handle, Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, WriteOutcome>))
Preserves the confirmed commit when post-commit maintenance fails.
def encoding_rejected_cause source · line 212 · raw
@error:0x4fcd94fa965aa1443134557fd075a483/src/Wal.Error -> 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.WriteCause
Maps WAL encoding limits to public write-validation causes.
def committed_result source · line 220 · raw
@committed:Pair(0x4fcd94fa965aa1443134557fd075a483/src/Db.Db, 0x4fcd94fa965aa1443134557fd075a483/src/DurableCommit.Stage) -> @lock:0x4fcd94fa965aa1443134557fd075a483/src/DbLock.Lock -> @operation_errors:Nat -> @+path:String -> IO(Pair(Handle, Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, WriteOutcome>))
Updates handle state from the WAL commit stage and maintains durable commits.
def batch_result source · line 246 · raw
@+db:0x4fcd94fa965aa1443134557fd075a483/src/Db.Db -> @batch:0x4fcd94fa965aa1443134557fd075a483/src/Wal.Batch -> @lock:0x4fcd94fa965aa1443134557fd075a483/src/DbLock.Lock -> @operation_errors:Nat -> @+path:String -> IO(Pair(Handle, Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, WriteOutcome>))
Commits a validated mutation batch and returns the updated owned handle.
def batch_count_result source · line 259 · raw
@+db:0x4fcd94fa965aa1443134557fd075a483/src/Db.Db -> @muts:List<&2, 0x4fcd94fa965aa1443134557fd075a483/src/Wal.Mut> -> @lock:0x4fcd94fa965aa1443134557fd075a483/src/DbLock.Lock -> @operation_errors:Nat -> @+path:String -> @validation:0x4fcd94fa965aa1443134557fd075a483/src/DurableBatchPolicy.Validation -> IO(Pair(Handle, Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, WriteOutcome>))
Rejects empty and oversized batches before WAL access.
def batch_count source · line 283 · raw
@+db:0x4fcd94fa965aa1443134557fd075a483/src/Db.Db -> @+muts:List<&2, 0x4fcd94fa965aa1443134557fd075a483/src/Wal.Mut> -> @lock:0x4fcd94fa965aa1443134557fd075a483/src/DbLock.Lock -> @operation_errors:Nat -> @+path:String -> IO(Pair(Handle, Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, WriteOutcome>))
Validates the mutation count before attempting a commit.
def write_batch source · line 293 · raw
@handle:Handle -> @muts:List<&2, 0x4fcd94fa965aa1443134557fd075a483/src/Wal.Mut> -> IO(Pair(Handle, Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, WriteOutcome>))
Validates and commits a public mutation batch atomically.
def put source · line 313 · raw
@handle:Handle -> @+key:String -> @+value:String -> IO(Pair(Handle, Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, WriteOutcome>))
Writes one key and value through the durable handle.
def delete source · line 317 · raw
@handle:Handle -> @+key:String -> IO(Pair(Handle, Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, WriteOutcome>))
Deletes one key through the durable handle.
def maintenance_result source · line 321 · raw
@result:Result<&1, &1, Pair(U32, String), 0x4fcd94fa965aa1443134557fd075a483/src/Db.Db> -> @+original:0x4fcd94fa965aa1443134557fd075a483/src/Db.Db -> @operation:String -> @lock:0x4fcd94fa965aa1443134557fd075a483/src/DbLock.Lock -> @operation_errors:Nat -> @+path:String -> Pair(Handle, Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Unit>)
Preserves the original database when maintenance fails.
def flush_result source · line 337 · raw
@+db:0x4fcd94fa965aa1443134557fd075a483/src/Db.Db -> @lock:0x4fcd94fa965aa1443134557fd075a483/src/DbLock.Lock -> @operation_errors:Nat -> @+path:String -> IO(Pair(Handle, Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Unit>))
Flushes the database and updates handle state from the result.
def compact_result source · line 348 · raw
@+db:0x4fcd94fa965aa1443134557fd075a483/src/Db.Db -> @lock:0x4fcd94fa965aa1443134557fd075a483/src/DbLock.Lock -> @operation_errors:Nat -> @+path:String -> IO(Pair(Handle, Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Unit>))
Compacts the database and updates handle state from the result.
def flush source · line 359 · raw
@handle:Handle -> IO(Pair(Handle, Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Unit>))
Flushes the durable handle and returns maintenance status.
def compact source · line 373 · raw
@handle:Handle -> IO(Pair(Handle, Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Unit>))
Compacts the durable handle and returns maintenance status.
def stats_names source · line 392 · raw
@fuel:Nat -> @state:StatsNamesState -> IO(Result<&1, &1, Pair(U32, String), Nat>)
Sums file sizes for the supplied directory entries within a fixed budget.
def stats_levels source · line 419 · raw
@fuel:Nat -> @state:StatsLevelsState -> IO(Result<&1, &1, Pair(U32, String), Nat>)
Sums published SSTable sizes across Manifest levels within a fixed budget.
def stats_active_manifest_size source · line 444 · raw
@result:Result<&1, &1, Pair(U32, String), Nat> -> @+levels:List<&2, List<&2, String>> -> @+path:String -> IO(Result<&1, &1, Pair(U32, String), Nat>)
Adds the sizes of all published SSTables to the Manifest size.
def stats_active_manifest source · line 457 · raw
@result:Result<&1, &1, Pair(U32, String), 0x4fcd94fa965aa1443134557fd075a483/src/Manifest.Manifest> -> @+path:String -> IO(Result<&1, &1, Pair(U32, String), Nat>)
Reads the Manifest and sums only the files it references.
def stats_result source · line 470 · raw
@results:Pair(Result<&1, &1, Pair(U32, String), Nat>, Result<&1, &1, Pair(U32, String), Nat>) -> @+db:0x4fcd94fa965aa1443134557fd075a483/src/Db.Db -> @+state:0x4fcd94fa965aa1443134557fd075a483/src/DurableDbPolicy.HandleState -> @lock:0x4fcd94fa965aa1443134557fd075a483/src/DbLock.Lock -> @+operation_errors:Nat -> @+path:String -> Pair(Handle, Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Stats>)
Builds counters from file sizes and the in-memory database state.
def stats_io source · line 493 · raw
@db:0x4fcd94fa965aa1443134557fd075a483/src/Db.Db -> @state:0x4fcd94fa965aa1443134557fd075a483/src/DurableDbPolicy.HandleState -> @lock:0x4fcd94fa965aa1443134557fd075a483/src/DbLock.Lock -> @operation_errors:Nat -> @+path:String -> IO(Pair(Handle, Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Stats>))
Reads Manifest and WAL sizes before building the stats record.
def stats source · line 508 · raw
@handle:Handle -> IO(Pair(Handle, Result<&1, &1, 0x4fcd94fa965aa1443134557fd075a483/src/DurableError.Error, Stats>))
Reads bounded operational stats from the durable handle.