src/DbLock.bend relies on unsafe/foreign
raw source on the hub · import mylsm-lsm-store@0.6.0.2/src/DbLock.bend as DbLock
4 imports
import Base import ./DurableError.bend as DurableError import ./DbLockPolicy.bend as Policy import ./Fs.bend as Fs
Types
type Lock source · line 7 · raw
Type
Owns the open LOCK file until release.
Lock@file:File -> Lock
type WaitPurpose source · line 11 · raw
Data
Determines whether a clock sample selects backoff or deadline validation.
ChooseDelayWaitPurpose
CheckDeadlineWaitPurpose
type AttemptDecision source · line 16 · raw
Type
Carries the raw result of one nonblocking lock attempt.
ContendedAttemptDecision
Failed@error:Pair(U32, String) -> AttemptDecision
type WaitState source · line 21 · raw
Type
Carries file ownership through the single recursive wait state machine.
TryLock@file:File -> @started_us:Nat -> @timeout_ms:Nat -> @backoff_ms:U32 -> @operation:String -> @path:String -> WaitState
LockAttempt@pair:Pair(File, Result<&1, &1, Pair(U32, String), Unit>) -> @started_us:Nat -> @timeout_ms:Nat -> @backoff_ms:U32 -> @operation:String -> @path:String -> WaitState
ReadClock@file:File -> @started_us:Nat -> @timeout_ms:Nat -> @backoff_ms:U32 -> @operation:String -> @path:String -> @purpose:WaitPurpose -> WaitState
ClockSample@file:File -> @started_us:Nat -> @timeout_ms:Nat -> @backoff_ms:U32 -> @operation:String -> @path:String -> @purpose:WaitPurpose -> @result:Result<&1, &1, Pair(U32, String), Nat> -> WaitState
Pause@file:File -> @started_us:Nat -> @timeout_ms:Nat -> @backoff_ms:U32 -> @operation:String -> @path:String -> @duration_ms:U32 -> WaitState
PauseResult@file:File -> @started_us:Nat -> @timeout_ms:Nat -> @backoff_ms:U32 -> @operation:String -> @path:String -> @result:Result<&1, &1, Pair(U32, String), Unit> -> WaitState
WaitFatal@file:File -> @error:Pair(U32, String) -> @operation:String -> @path:String -> WaitState
WaitExpired@file:File -> @operation:String -> @path:String -> WaitState
Definitions
def lock_path source · line 41 · raw
@path:String -> String
Builds the stable LOCK path for a database directory.
def open_failed source · line 53 · raw
@error:Pair(U32, String) -> @operation:String -> @path:String -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Lock>)
Classifies a failure to open the LOCK file.
def lock_failed source · line 60 · raw
@file:File -> @error:Pair(U32, String) -> @operation:String -> @path:String -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Lock>)
Closes the file and classifies a failed lock attempt.
def lock_result source · line 73 · raw
@pair:Pair(File, Result<&1, &1, Pair(U32, String), Unit>) -> @operation:String -> @path:String -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Lock>)
Returns an owned lock on success or closes the failed handle.
def lock_file source · line 85 · raw
@file:File -> @operation:String -> @path:String -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Lock>)
Attempts the nonblocking OS lock on the open file.
def opened source · line 91 · raw
@result:Result<&1, &1, Pair(U32, String), File> -> @operation:String -> @path:String -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Lock>)
Locks the opened file or classifies its open error.
def acquire source · line 103 · raw
@+path:String -> @operation:String -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Lock>)
Opens the stable LOCK file and acquires its OS lock.
def release_failed source · line 109 · raw
@file:File -> @error:Pair(U32, String) -> @operation:String -> @path:String -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Unit>)
Closes the file and preserves the unlock error.
def release_succeeded source · line 122 · raw
@file:File -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Unit>)
Closes the file after a successful unlock.
def released source · line 128 · raw
@pair:Pair(File, Result<&1, &1, Pair(U32, String), Unit>) -> @operation:String -> @path:String -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Unit>)
Closes the file after either unlock result.
def unlock_file source · line 140 · raw
@file:File -> @operation:String -> @path:String -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Unit>)
Unlocks the file and closes it after the result.
def release source · line 146 · raw
@lock:Lock -> @operation:String -> @path:String -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Unit>)
Consumes the lock and releases its file handle.
def wait.timeout source · line 152 · raw
@file:File -> @operation:String -> @path:String -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Lock>)
Closes the lock file and returns a distinct timeout error.
def wait.host_error source · line 159 · raw
@file:File -> @error:Pair(U32, String) -> @operation:String -> @path:String -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Lock>)
Closes the lock file and classifies a clock or sleep host failure.
def wait.attempt.decision source · line 173 · raw
@error:Pair(U32, String) -> AttemptDecision
Separates contention from fatal lock errors while preserving host details.
def wait.attempt.state source · line 180 · raw
@decision:AttemptDecision -> @file:File -> @started_us:Nat -> @timeout_ms:Nat -> @backoff_ms:U32 -> @operation:String -> @path:String -> WaitState
Converts a raw lock failure into the next owned state.
def wait.delay.state source · line 197 · raw
@decision:0x7586b743ff7fd05e412d5115859629b6/src/DbLockPolicy.WaitDecision -> @file:File -> @started_us:Nat -> @timeout_ms:Nat -> @backoff_ms:U32 -> @operation:String -> @path:String -> WaitState
Converts backoff policy into either one sleep or a terminal state.
def wait.deadline.state source · line 214 · raw
@remaining_ms:Nat -> @file:File -> @started_us:Nat -> @timeout_ms:Nat -> @backoff_ms:U32 -> @operation:String -> @path:String -> WaitState
Converts a post-sleep deadline sample into a retry or timeout state.
def wait.clock.decision source · line 230 · raw
@purpose:WaitPurpose -> @file:File -> @started_us:Nat -> @+timeout_ms:Nat -> @+backoff_ms:U32 -> @operation:String -> @path:String -> @elapsed_ms:Nat -> WaitState
Selects backoff or deadline logic from a monotonic elapsed-time sample.
def wait.exhausted source · line 250 · raw
@state:WaitState -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Lock>)
Closes a handle if the finite retry budget is unexpectedly exhausted.
def wait.loop source · line 272 · raw
@fuel:Nat -> @state:WaitState -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Lock>)
Runs lock, clock, and sleep transitions with one decreasing structural fuel.
def acquire_wait.started source · line 323 · raw
@file:File -> @operation:String -> @path:String -> @timeout_ms:U32 -> @backoff_ms:U32 -> @result:Result<&1, &1, Pair(U32, String), Nat> -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Lock>)
Begins retries after validating the monotonic clock source.
def acquire_wait.opened source · line 341 · raw
@result:Result<&1, &1, Pair(U32, String), File> -> @operation:String -> @path:String -> @timeout_ms:U32 -> @backoff_ms:U32 -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Lock>)
Opens the stable lock file and samples the monotonic start time.
def acquire_wait.valid source · line 357 · raw
@valid:Bool -> @+path:String -> @operation:String -> @+timeout_ms:U32 -> @+backoff_ms:U32 -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Lock>)
Opens and waits only after the pure option validation succeeds.
def acquire_wait source · line 374 · raw
@+path:String -> @operation:String -> @+timeout_ms:U32 -> @+backoff_ms:U32 -> IO(Result<&1, &1, 0x7586b743ff7fd05e412d5115859629b6/src/DurableError.Error, Lock>)
Acquires the lock immediately or waits with a finite monotonic timeout.
Effects (foreign code)
effect DbLock.try_lock source · line 44 · raw
@file:File -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Unit>))
foreign: src/effs/db_lock.c, src/effs/db_lock.js
effect DbLock.try_unlock source · line 48 · raw
@file:File -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Unit>))
foreign: src/effs/db_unlock.c, src/effs/db_unlock.js