Skip to content

Commit

Permalink
Extend the FormatPage reference impl with disk page sizes
Browse files Browse the repository at this point in the history
So now instead of the model implementation producing arbitrary sized
pages, they're now padded to the underlying disk page size. The
prototype is aware of multiple disk page sizes, but we only use 4k to
compare against the real implementation.

This also now means that (in the model) encoding a page can fail,
because it can exceed the disk page size.

Several functions now have an extra DiskPageSize arg, and have Maybe
results. Update the other tests to match this API change.

We don't yet change any of the generators, or tests (other than for the
API changes).
  • Loading branch information
dcoutts committed Apr 29, 2024
1 parent f6a0359 commit 9da20c9
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 134 deletions.
6 changes: 4 additions & 2 deletions bench/micro/Bench/Database/LSMTree/Internal/RawPage.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE TypeApplications #-}

{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}

module Bench.Database.LSMTree.Internal.RawPage (
benchmarks
Expand Down Expand Up @@ -28,7 +29,8 @@ benchmarks = rawpage `deepseq` bgroup "Bench.Database.LSMTree.Internal.RawPage"
]
where
page :: PageLogical
page = unGen (genFullPageLogical genSmallKey genSmallValue) (mkQCGen 42) 200
page = unGen (genFullPageLogical DiskPage4k genSmallKey genSmallValue)
(mkQCGen 42) 200

rawpage :: RawPage
rawpage = fst $ toRawPage $ page
Expand All @@ -54,6 +56,6 @@ benchmarks = rawpage `deepseq` bgroup "Bench.Database.LSMTree.Internal.RawPage"
toRawPage :: PageLogical -> (RawPage, BS.ByteString)
toRawPage p = (page, sfx)
where
bs = serialisePage $ encodePage p
Just bs = serialisePage <$> encodePage DiskPage4k p
(pfx, sfx) = BS.splitAt 4096 bs -- hardcoded page size.
page = case SBS.toShort pfx of SBS.SBS ba -> makeRawPage (ByteArray ba) 0

0 comments on commit 9da20c9

Please sign in to comment.