Deterministic transactional write-ahead log framing and crash recovery for MoonBit.
moon add Sxy11112/moonjournalkitlet records = [
@journal.JournalRecord::new(Begin, 1U, 7U),
@journal.JournalRecord::new(
Put,
2U,
7U,
payload=@journal.encode_put_payload(b"user/7", b"active"),
),
@journal.JournalRecord::new(Commit, 3U, 7U),
]
let bytes = @journal.encode_records(records)
let scan = @journal.scan_journal(bytes)
let plan = @journal.build_recovery_plan(scan.records)
assert_eq(plan.actions.length(), 1)moon check --target all
moon test --target wasm
moon test --target wasm-gc
moon run cmd/main
moon run bench/mainpub(all) struct DecodeResult {
status : DecodeStatus
record : JournalRecord?
next_offset : Int
message : String
} derive(Eq, Debug)pub(all) struct JournalRecord {
kind : RecordKind
sequence : UInt
transaction : UInt
payload : Bytes
} derive(Eq, Debug)fn JournalRecord::new(kind : RecordKind, sequence : UInt, transaction : UInt, payload? : Bytes) -> JournalRecordpub(all) struct Mutation {
transaction : UInt
sequence : UInt
kind : MutationKind
key : Bytes
value : Bytes
} derive(Eq, Debug)pub(all) struct ScanResult {
records : Array[JournalRecord]
valid_bytes : Int
total_bytes : Int
stop : ScanStop
fault_offset : Int
message : String
} derive(Eq, Debug)pub(all) struct SegmentPlan {
segments : Array[SegmentMeta]
total_records : Int
total_bytes : Int
valid : Bool
message : String
} derive(Eq, Debug)pub(all) struct StreamFeedResult {
records : Array[JournalRecord]
buffered_bytes : Int
stop : ScanStop?
message : String
} derive(Eq, Debug)fn StreamJournalDecoder::new(strict_sequence? : Bool, max_payload? : Int, max_buffered? : Int) -> StreamJournalDecoderfn crc32c(data : BytesView) -> UIntfn crc32c_extend(state : UInt, data : BytesView) -> UIntfn encode_checkpoint_payload(sequence : UInt) -> Bytesfn encode_delete_payload(key : BytesView) -> Bytesfn encode_put_payload(key : BytesView, value : BytesView) -> Bytesfn plan_segments(records : Array[JournalRecord], max_bytes : Int, max_records : Int, first_id? : UInt) -> SegmentPlanfn scan_journal(data : BytesView, strict_sequence? : Bool, max_payload? : Int, max_records? : Int) -> ScanResultDeterministic transactional write-ahead log framing and crash recovery for MoonBit.