ByteWalIo.recover.result: def of mylsm-lsm-store@0.6.0.1 Import: import mylsm-lsm-store@0.6.0.1/src/ByteWalIo.bend as ByteWalIo Lines 265-345 of mylsm-lsm-store@0.6.0.1/src/ByteWalIo.bend: https://jend.leeeet.dev/read.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteWalIo.bend&start_line=265&end_line=345 import Base import mylsm-lsm-store@0.6.0.1/src/ByteMemTable.bend as ByteMemTable import mylsm-lsm-store@0.6.0.1/src/ByteWal.bend as ByteWal import mylsm-lsm-store@0.6.0.1/src/SstStreamIo.bend as SstStreamIo import bend-kit-bytes@0.3.2.0/bytes.bend as Bytes def recover.result( +path: String, fuel: Nat, state: RecoveryState ) -> IO(Result<&1, &1, U32 & String, ByteMemTable.Table>): match fuel: case 0n: recover.exhausted(state) case 1n+rest: match state: case Tail{file, path, +offset, table}: do IO>: _closed : Unit <- File.close(file) tail.closed(path, offset, table) case At{file, +size, +offset, table, at_end, can_read_length}: match at_end: case True{}: close.done(file, table) case False{}: match can_read_length: case False{}: recover.result(path, rest, Tail{file, path, offset, table}) case True{}: do IO>: pair : File & Result<&1, &1, U32 & String, SstStreamIo.ExactResult> <- SstStreamIo.exact.start(file, 4n) recover.result(path, rest, Length{pair, size, offset, table}) case Length{pair, +size, +offset, table}: match pair: case (file, Fail{failure}): close.failed(file, failure) case (file, Done{SstStreamIo.ExactResult{bytes, complete}}): recover.result(path, rest, recover.length.completed(path, file, size, offset, table, bytes, complete)) case Prefix{file, +size, +offset, table, prefix, +frame_length, within_file}: match within_file: case False{}: recover.result(path, rest, Tail{file, path, offset, table}) case True{}: do IO>: pair : File & Result<&1, &1, U32 & String, SstStreamIo.ExactResult> <- SstStreamIo.exact.start(file, 4n) recover.result(path, rest, Count{pair, size, offset, table, prefix, frame_length}) case Count{pair, +size, +offset, table, prefix, +frame_length}: match pair: case (file, Fail{failure}): close.failed(file, failure) case (file, Done{SstStreamIo.ExactResult{bytes, complete}}): recover.result(path, rest, recover.count.completed(path, file, size, offset, table, prefix, bytes, complete, frame_length)) case Counted{file, +size, +offset, table, prefix, count_bytes, +frame_length, within_limit}: match within_limit: case False{}: close.failed(file, error("byte WAL frame exceeds configured limit")) case True{}: do IO>: pair : File & Result<&1, &1, U32 & String, SstStreamIo.ExactResult> <- SstStreamIo.exact.start(file, U32.to_nat((frame_length - 4 : U32))) recover.result(path, rest, Body{pair, size, offset, table, prefix, count_bytes, frame_length}) case Body{pair, +size, +offset, table, prefix, count_bytes, +frame_length}: match pair: case (file, Fail{failure}): close.failed(file, failure) case (file, Done{SstStreamIo.ExactResult{bytes, complete}}): match complete: case False{}: recover.result(path, rest, Tail{file, path, offset, table}) case True{}: recover.result(path, rest, Decoded{file, size, Nat.add(offset, Nat.add(4n, U32.to_nat(frame_length))), table, ByteWal.decode(Bytes.concat([prefix, count_bytes, bytes]))}) case Decoded{file, +size, +next_offset, table, result}: match result: case Fail{_}: close.failed(file, error("corrupt byte WAL frame")) case Done{batch}: recover.result(path, rest, recover.at(file, size, next_offset, apply.batch(table, batch))) case Failed{file, failure}: close.failed(file, failure) Uses (31): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=File https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=File.close https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=IO https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=IO.bind https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.add https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Pair https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Result https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Sigma https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.sub https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.to_nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Unit https://jend.leeeet.dev/definition.txt?path=bend-kit-bytes@0.3.3.0/bytes.bend&name=concat https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteMemTable.bend&name=Table https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteWal.bend&name=decode https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteWalIo.bend&name=RecoveryState https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteWalIo.bend&name=apply.batch https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteWalIo.bend&name=close.done https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteWalIo.bend&name=close.failed https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteWalIo.bend&name=error https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteWalIo.bend&name=recover.at https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteWalIo.bend&name=recover.count.completed https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteWalIo.bend&name=recover.exhausted https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteWalIo.bend&name=recover.length.completed https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteWalIo.bend&name=tail.closed https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/SstStreamIo.bend&name=ExactResult https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/SstStreamIo.bend&name=exact.start