Skip to content

Commit 45ca97f

Browse files
committed
Temporarily allow searching empty ordinary indexes
1 parent df265f1 commit 45ca97f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Database/LSMTree/Internal/Index/Ordinary.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,17 @@ toLastKeys (IndexOrdinary lastKeys) = lastKeys
8080
type-agnostic version]('Database.LSMTree.Internal.Index.search').
8181
-}
8282
search :: SerialisedKey -> IndexOrdinary -> PageSpan
83-
search key (IndexOrdinary lastKeys) = assert (pageCount > 0) result where
83+
search key (IndexOrdinary lastKeys)
84+
-- TODO: ideally, we could assert that an index is never empty, but
85+
-- unfortunately we can not currently do this. Runs (and thefeore indexes)
86+
-- /can/ be empty if they were created by a last-level merge where all input
87+
-- entries were deletes. Other parts of the @lsm-tree@ code won't fail as long
88+
-- as we return @PageSpan 0 0@ when we search an empty ordinary index. The
89+
-- ideal fix would be to remove empty runs from the levels entirely, but this
90+
-- requires more involved changes to the merge schedule and until then we'll
91+
-- just hack the @pageCount <= 0@ case in.
92+
| pageCount <= 0 = PageSpan (PageNo 0) (PageNo 0)
93+
| otherwise = assert (pageCount > 0) result where
8494

8595
protoStart :: Int
8696
!protoStart = binarySearchL lastKeys key

0 commit comments

Comments
 (0)