def get.sst.loop
mylsm-lsm-store@0.6.0.1 · src/ByteDurableDb.bend:1124
import mylsm-lsm-store@0.6.0.1/src/ByteDurableDb.bend as ByteDurableDb
import Base
import mylsm-lsm-store@0.6.0.1/src/ByteMemTable.bend as ByteMemTable
import mylsm-lsm-store@0.6.0.1/src/DbLock.bend as DbLock
import mylsm-lsm-store@0.6.0.1/src/scan/SstCursor.bend as SstCursor
import mylsm-lsm-store@0.6.0.1/src/scan/VisibleStats.bend as VisibleStats
import bend-kit-bytes@0.3.2.0/bytes.bend as Bytes
1124def get.sst.loop(
1125 fuel: Nat,
1126 +path: String,
1127 lock: DbLock.Lock,
1128 table: ByteMemTable.Table,
1129 state: PointRead
1130) -> IO(Handle & Result<&1, &1, Error, Maybe<&1, Bytes.Bytes>>):
1131 match fuel:
1132 case 0n:
1133 get.sst.exhausted(path, lock, table, state)
1134 case 1n+rest:
1135 match state:
1136 case Need{cursor, query}:
1137 do IO<Handle & Result<&1, &1, Error, Maybe<&1, Bytes.Bytes>>>:
1138 step : SstCursor.Step <- SstCursor.next(cursor)
1139 get.sst.loop(rest, path, lock, table, Read{step, query})
1140 case Read{step, query}:
1141 match step:
1142 case SstCursor.Item{entry, cursor}:
1143 match entry:
1144 case ByteMemTable.Entry{key, val}:
1145 match val:
1146 case None{}:
1147 get.sst.loop(rest, path, lock, table, Need{cursor, query})
1148 case Some{value}:
1149 get.sst.loop(rest, path, lock, table,
1150 get.sst.compare.order(value, cursor, key,
1151 ByteMemTable.bytes.clone(query)))
1152 case SstCursor.Skip{cursor}:
1153 get.sst.loop(rest, path, lock, table, Need{cursor, query})
1154 case SstCursor.End{}:
1155 IO.pure(Handle & Result<&1, &1, Error, Maybe<&1, Bytes.Bytes>>,
1156 (Handle{path, lock, table, Open{}, VisibleStats.Stats{0n, 0n}}, Done{None{}}))
1157 case SstCursor.Error{(code, message)}:
1158 IO.pure(Handle & Result<&1, &1, Error, Maybe<&1, Bytes.Bytes>>,
1159 (Handle{path, lock, table, Open{}, VisibleStats.Stats{0n, 0n}}, Fail{recovery.error(code, message)}))
1160 case Compare{value, cursor, query, order}:
1161 match order:
1162 case EQ{}:
1163 get.sst.closed(path, lock, table, Some{value}, cursor)
1164 case GT{}:
1165 get.sst.closed(path, lock, table, None{}, cursor)
1166 case LT{}:
1167 get.sst.loop(rest, path, lock, table, Need{cursor, query})