Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Database.LSMTree.Extras.ReferenceImpl
Synopsis
- newtype Key = Key {
- unKey :: ByteString
- newtype Value = Value {}
- data Operation
- data BlobRef = BlobRef Word64 Word32
- type PageSerialised = ByteString
- data PageIntermediate
- data PageSize = PageSize {
- pageSizeElems :: !Int
- pageSizeBlobs :: !Int
- pageSizeBytes :: !Int
- pageSizeDisk :: !DiskPageSize
- pageSizeEmpty :: DiskPageSize -> PageSize
- pageSizeAddElem :: (Key, Operation) -> PageSize -> Maybe PageSize
- data DiskPageSize
- encodePage :: DiskPageSize -> [(Key, Operation)] -> Maybe PageIntermediate
- decodePage :: PageIntermediate -> [(Key, Operation)]
- serialisePage :: PageIntermediate -> PageSerialised
- deserialisePage :: DiskPageSize -> PageSerialised -> PageIntermediate
- pageOverflowPrefixSuffixLen :: PageIntermediate -> Maybe (Int, Int)
- pageDiskPages :: PageIntermediate -> Int
- pageSerialisedChunks :: DiskPageSize -> PageSerialised -> [ByteString]
- toRawPage :: PageContentFits -> (RawPage, [RawOverflowPage])
- toRawPageMaybeOverfull :: PageContentMaybeOverfull -> Maybe (RawPage, [RawOverflowPage])
- toEntry :: Operation -> Entry SerialisedValue BlobSpan
- toEntryPrefix :: Operation -> Int -> Entry SerialisedValue BlobSpan
- toSerialisedKey :: Key -> SerialisedKey
- toSerialisedValue :: Value -> SerialisedValue
- toBlobSpan :: BlobRef -> BlobSpan
- fromRawPage :: (RawPage, [RawOverflowPage]) -> PageContentFits
- fromEntry :: Entry SerialisedValue BlobSpan -> Operation
- fromEntryPrefix :: Entry SerialisedValue BlobSpan -> Int -> [RawOverflowPage] -> Operation
- fromSerialisedKey :: SerialisedKey -> Key
- fromSerialisedValue :: SerialisedValue -> Value
- fromSerialisedValuePrefix :: SerialisedValue -> Int -> [RawOverflowPage] -> Value
- fromRawOverflowPages :: [RawOverflowPage] -> ByteString
- fromBlobSpan :: BlobSpan -> BlobRef
- newtype PageContentFits = PageContentFits [(Key, Operation)]
- pageContentFitsInvariant :: PageContentFits -> Bool
- newtype PageContentOrdered = PageContentOrdered [(Key, Operation)]
- pageContentOrderedInvariant :: PageContentOrdered -> Bool
- newtype PageContentMaybeOverfull = PageContentMaybeOverfull [(Key, Operation)]
- data PageContentSingle = PageContentSingle Key Operation
- genPageContentFits :: DiskPageSize -> MinKeySize -> Gen [(Key, Operation)]
- genPageContentMaybeOverfull :: DiskPageSize -> MinKeySize -> Gen [(Key, Operation)]
- genPageContentSingle :: DiskPageSize -> MinKeySize -> Gen (Key, Operation)
- genPageContentNearFull :: DiskPageSize -> Gen Key -> Gen Value -> Gen [(Key, Operation)]
- genPageContentMedium :: DiskPageSize -> Gen Key -> Gen Value -> Gen [(Key, Operation)]
- newtype MinKeySize = MinKeySize Int
- noMinKeySize :: MinKeySize
- orderdKeyOps :: [(Key, Operation)] -> [(Key, Operation)]
- shrinkKeyOps :: [(Key, Operation)] -> [[(Key, Operation)]]
- shrinkOrderedKeyOps :: [(Key, Operation)] -> [[(Key, Operation)]]
Page types
type PageSerialised = ByteString Source #
A serialised page consists of either a single disk page or several
disk pages. The latter is a primary page followed by one or more overflow
pages. Each disk page (single or multi) uses the same DiskPageSize
, which
should be known from context (e.g. configuration).
data PageIntermediate Source #
Instances
Show PageIntermediate | |
Defined in FormatPage Methods showsPrec :: Int -> PageIntermediate -> ShowS # show :: PageIntermediate -> String # showList :: [PageIntermediate] -> ShowS # | |
Eq PageIntermediate | |
Defined in FormatPage Methods (==) :: PageIntermediate -> PageIntermediate -> Bool # (/=) :: PageIntermediate -> PageIntermediate -> Bool # |
Page size
Constructors
PageSize | |
Fields
|
pageSizeEmpty :: DiskPageSize -> PageSize Source #
Encoding and decoding
data DiskPageSize Source #
A serialised page fits within chunks of memory of 4k, 8k, 16k, 32k or 64k.
Constructors
DiskPage4k | |
DiskPage8k | |
DiskPage16k | |
DiskPage32k | |
DiskPage64k |
Instances
Arbitrary DiskPageSize | |
Defined in FormatPage | |
Bounded DiskPageSize | |
Defined in FormatPage | |
Enum DiskPageSize | |
Defined in FormatPage Methods succ :: DiskPageSize -> DiskPageSize # pred :: DiskPageSize -> DiskPageSize # toEnum :: Int -> DiskPageSize # fromEnum :: DiskPageSize -> Int # enumFrom :: DiskPageSize -> [DiskPageSize] # enumFromThen :: DiskPageSize -> DiskPageSize -> [DiskPageSize] # enumFromTo :: DiskPageSize -> DiskPageSize -> [DiskPageSize] # enumFromThenTo :: DiskPageSize -> DiskPageSize -> DiskPageSize -> [DiskPageSize] # | |
Show DiskPageSize | |
Defined in FormatPage Methods showsPrec :: Int -> DiskPageSize -> ShowS # show :: DiskPageSize -> String # showList :: [DiskPageSize] -> ShowS # | |
Eq DiskPageSize | |
Defined in FormatPage |
encodePage :: DiskPageSize -> [(Key, Operation)] -> Maybe PageIntermediate Source #
decodePage :: PageIntermediate -> [(Key, Operation)] Source #
Overflow pages
pageOverflowPrefixSuffixLen :: PageIntermediate -> Maybe (Int, Int) Source #
If a page uses overflow pages, return the:
- value prefix length (within the first page)
- value suffix length (within the overflow pages)
pageDiskPages :: PageIntermediate -> Int Source #
The total number of disk pages, including any overflow pages.
pageSerialisedChunks :: DiskPageSize -> PageSerialised -> [ByteString] Source #
Conversions to real implementation types
toRawPage :: PageContentFits -> (RawPage, [RawOverflowPage]) Source #
Convert from PageContentFits
(from the reference implementation)
to RawPage
(from the real implementation).
toEntryPrefix :: Operation -> Int -> Entry SerialisedValue BlobSpan Source #
toSerialisedKey :: Key -> SerialisedKey Source #
toBlobSpan :: BlobRef -> BlobSpan Source #
Conversions from real implementation types
fromRawPage :: (RawPage, [RawOverflowPage]) -> PageContentFits Source #
fromEntryPrefix :: Entry SerialisedValue BlobSpan -> Int -> [RawOverflowPage] -> Operation Source #
fromSerialisedKey :: SerialisedKey -> Key Source #
fromSerialisedValuePrefix :: SerialisedValue -> Int -> [RawOverflowPage] -> Value Source #
fromBlobSpan :: BlobSpan -> BlobRef Source #
Test case types and generators
newtype PageContentFits Source #
A test case consisting of a key/operation sequence that is guaranteed to either fit into a single 4k disk page, or be a single entry that spans a one primary 4k disk page and zero or more overflow disk pages.
The keys are not ordered.
Constructors
PageContentFits [(Key, Operation)] |
Instances
Arbitrary PageContentFits Source # | |
Defined in Database.LSMTree.Extras.ReferenceImpl Methods arbitrary :: Gen PageContentFits Source # shrink :: PageContentFits -> [PageContentFits] Source # | |
Show PageContentFits Source # | |
Defined in Database.LSMTree.Extras.ReferenceImpl Methods showsPrec :: Int -> PageContentFits -> ShowS # show :: PageContentFits -> String # showList :: [PageContentFits] -> ShowS # | |
Eq PageContentFits Source # | |
Defined in Database.LSMTree.Extras.ReferenceImpl Methods (==) :: PageContentFits -> PageContentFits -> Bool # (/=) :: PageContentFits -> PageContentFits -> Bool # |
newtype PageContentOrdered Source #
A test case consisting of a key/operation sequence that is guaranteed to either fit into a single 4k disk page, or be a single entry that spans a one primary 4k disk page and zero or more overflow disk pages.
The keys are in strictly ascending order.
Constructors
PageContentOrdered [(Key, Operation)] |
Instances
Arbitrary PageContentOrdered Source # | |
Defined in Database.LSMTree.Extras.ReferenceImpl Methods arbitrary :: Gen PageContentOrdered Source # shrink :: PageContentOrdered -> [PageContentOrdered] Source # | |
Show PageContentOrdered Source # | |
Defined in Database.LSMTree.Extras.ReferenceImpl Methods showsPrec :: Int -> PageContentOrdered -> ShowS # show :: PageContentOrdered -> String # showList :: [PageContentOrdered] -> ShowS # | |
Eq PageContentOrdered Source # | |
Defined in Database.LSMTree.Extras.ReferenceImpl Methods (==) :: PageContentOrdered -> PageContentOrdered -> Bool # (/=) :: PageContentOrdered -> PageContentOrdered -> Bool # |
pageContentOrderedInvariant :: PageContentOrdered -> Bool Source #
Stricly increasing, so no duplicates.
newtype PageContentMaybeOverfull Source #
A test case consisting of a key/operation sequence that is not guaranteed to fit into a a 4k disk page.
These test cases are useful for checking the boundary conditions for what can fit into a disk page.
The keys are not ordered.
Constructors
PageContentMaybeOverfull [(Key, Operation)] |
Instances
Arbitrary PageContentMaybeOverfull Source # | |
Defined in Database.LSMTree.Extras.ReferenceImpl Methods arbitrary :: Gen PageContentMaybeOverfull Source # shrink :: PageContentMaybeOverfull -> [PageContentMaybeOverfull] Source # | |
Show PageContentMaybeOverfull Source # | |
Defined in Database.LSMTree.Extras.ReferenceImpl Methods showsPrec :: Int -> PageContentMaybeOverfull -> ShowS # show :: PageContentMaybeOverfull -> String # showList :: [PageContentMaybeOverfull] -> ShowS # | |
Eq PageContentMaybeOverfull Source # | |
Defined in Database.LSMTree.Extras.ReferenceImpl Methods (==) :: PageContentMaybeOverfull -> PageContentMaybeOverfull -> Bool # (/=) :: PageContentMaybeOverfull -> PageContentMaybeOverfull -> Bool # |
data PageContentSingle Source #
A tests case consisting of a single key/operation pair.
Constructors
PageContentSingle Key Operation |
Instances
Arbitrary PageContentSingle Source # | |
Defined in Database.LSMTree.Extras.ReferenceImpl Methods arbitrary :: Gen PageContentSingle Source # shrink :: PageContentSingle -> [PageContentSingle] Source # | |
Show PageContentSingle Source # | |
Defined in Database.LSMTree.Extras.ReferenceImpl Methods showsPrec :: Int -> PageContentSingle -> ShowS # show :: PageContentSingle -> String # showList :: [PageContentSingle] -> ShowS # | |
Eq PageContentSingle Source # | |
Defined in Database.LSMTree.Extras.ReferenceImpl Methods (==) :: PageContentSingle -> PageContentSingle -> Bool # (/=) :: PageContentSingle -> PageContentSingle -> Bool # |
Generators and shrinkers
genPageContentFits :: DiskPageSize -> MinKeySize -> Gen [(Key, Operation)] Source #
Generate a test case consisting of a key/operation sequence that is guaranteed to fit into a given disk page size.
The distribution is designed to cover:
- small pages
- medium sized pages
- nearly full pages
- plus single key pages (possibly using one or more overflow pages)
- a corner case of a single large key/operation pair followed by some small key op pairs.
The keys are not ordered: use orderdKeyOps
to sort and de-duplicate them
if that is needed (but note this will change the order of key sizes).
genPageContentMaybeOverfull :: DiskPageSize -> MinKeySize -> Gen [(Key, Operation)] Source #
Generate a test case consisting of a key/operation sequence that is not guaranteed to fit into a given disk page size.
These test cases are useful for checking the boundary conditions for what
can fit into a disk page. This covers a similar distribution to
genPageContentFits
but also includes about 20% of pages that are over full,
including the corner case of a large key ops pair followed by smaller key op
pairs (again possibly over full).
The keys are not ordered: use orderdKeyOps
to sort and de-duplicate them
if that is needed.
genPageContentSingle :: DiskPageSize -> MinKeySize -> Gen (Key, Operation) Source #
Generate a test case consisting of a single key/operation pair.
genPageContentNearFull :: DiskPageSize -> Gen Key -> Gen Value -> Gen [(Key, Operation)] Source #
Generate only pages that are nearly full. This isn't the maximum possible size, but where adding one more randomly-chosen key/op pair would not fit (but perhaps a smaller pair would still fit).
Consider if you really need this: the genPageContentMedium
also includes
these cases naturally as part of its distribution. On the other hand, this
can be good for generating benchmark data.
genPageContentMedium :: DiskPageSize -> Gen Key -> Gen Value -> Gen [(Key, Operation)] Source #
This generates a reasonable "middle" distribution of page sizes (relative to the given disk page size). In particular it covers:
- small pages (~45% for 4k pages, ~15% for 64k pages)
- near-maximum pages (~20% for 4k pages, ~20% for 64k pages)
- some in between (~35% for 4k pages, ~60% for 64k pages)
The numbers above are when used with the normal arbitrary
Key
and
Value
generators. And with these generators, it tends to use lots of
small-to-medium size keys and values, rather than a few huge ones.
newtype MinKeySize Source #
In some use cases it is necessary to generate Keys
that are at least of
some minimum length. Use noMinKeySize
if no such constraint is need.
Constructors
MinKeySize Int |
Instances
Show MinKeySize | |
Defined in FormatPage Methods showsPrec :: Int -> MinKeySize -> ShowS # show :: MinKeySize -> String # showList :: [MinKeySize] -> ShowS # |
noMinKeySize :: MinKeySize Source #
No minimum key size: MinKeySize 0
.
orderdKeyOps :: [(Key, Operation)] -> [(Key, Operation)] Source #
Sort and de-duplicate a key/operation sequence to ensure the sequence is strictly ascending by key.
If you need this in a QC generator, you will need shrinkOrderedKeyOps
in
the corresponding shrinker.