src/DurableBatchPolicy.bend

mylsm-lsm-store@0.5.0.0 · 23 lines · 0 definitions

1import Base
2
3# Returns the count-limit decision for a mutation batch.
4type Validation is Data:
5  ValidBatch{}
6  EmptyBatch{}
7  BatchCountExceeded{}
8
9# Returns the maximum number of mutations in a batch.
10def max_batch_count() -> Nat:
11  256n
12
13# Checks whether a batch count is within the allowed range.
14def within_batch_count(count: Nat) -> Bool:
15  Nat.is_le(count, max_batch_count())
16
17# Rejects empty and oversized batches before writing.
18def validate_count(count: Nat) -> Validation:
19  match count:
20    case 0n:
21      EmptyBatch{}
22    case count:
23      Bool.pick(Validation, within_batch_count(count), ValidBatch{}, BatchCountExceeded{})