src/DbLockPolicy.bend
mylsm-lsm-store@0.5.0.0 · 36 lines · 0 definitions
1import Base
2import mylsm-lsm-store@0.5.0.0/src/DurableError.bend as DurableError
3
4# Recognizes the host errno values for lock contention.
5def busy_code(+code: U32) -> Bool:
6 U32.is_eq(code, 11) || U32.is_eq(code, 35)
7
8# Recognizes the host errno for a missing path.
9def missing_code(+code: U32) -> Bool:
10 U32.is_eq(code, 2)
11
12# Maps non-contention lock errors to NotFound or Io.
13def classify_nonbusy_lock_error(
14 missing: Bool,
15 code: U32,
16 message: String,
17 operation: String,
18 path: String,
19) -> DurableError.Error:
20 match missing:
21 case True{}:
22 DurableError.Error{DurableError.NotFound{}, operation, path, code, message}
23 case False{}:
24 DurableError.Error{DurableError.Io{}, operation, path, code, message}
25
26# Maps contention to Busy and retains host details.
27def classify_lock_busy(busy: Bool, +code: U32, message: String, operation: String, path: String) -> DurableError.Error:
28 match busy:
29 case True{}:
30 DurableError.Error{DurableError.Busy{}, operation, path, code, message}
31 case False{}:
32 classify_nonbusy_lock_error(missing_code(code), code, message, operation, path)
33
34# Maps lock errors using the pure platform policy.
35def classify_lock_error(+code: U32, message: String, operation: String, path: String) -> DurableError.Error:
36 classify_lock_busy(busy_code(code), code, message, operation, path)