Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Database.LSMTree.Internal.Index
Description
Provides support for working with fence pointer indexes of different types and their accumulators.
Keys used with an index are subject to the key size constraints of the concrete type of the index. These constraints are stated in the descriptions of the modules Database.LSMTree.Internal.Index.Compact and Database.LSMTree.Internal.Index.Ordinary, respectively.
Part of the functionality that this module provides is the construction of
serialised indexes in a mostly incremental fashion. The incremental part of
serialisation is provided through index accumulators, while the
non-incremental bits are provided through the index operations headerLBS
and finalLBS
. To completely serialise an index interleaved with its
construction, proceed as follows:
Synopsis
- data IndexType
- indexToIndexType :: Index -> IndexType
- data Index
- search :: SerialisedKey -> Index -> PageSpan
- sizeInPages :: Index -> NumPages
- headerLBS :: IndexType -> LazyByteString
- finalLBS :: NumEntries -> Index -> LazyByteString
- fromSBS :: IndexType -> ShortByteString -> Either String (NumEntries, Index)
- data IndexAcc s
- = CompactIndexAcc !(IndexCompactAcc s)
- | OrdinaryIndexAcc !(IndexOrdinaryAcc s)
- newWithDefaults :: IndexType -> ST s (IndexAcc s)
- appendSingle :: (SerialisedKey, SerialisedKey) -> IndexAcc s -> ST s (Maybe Chunk)
- appendMulti :: (SerialisedKey, Word32) -> IndexAcc s -> ST s [Chunk]
- unsafeEnd :: IndexAcc s -> ST s (Maybe Chunk, Index)
Index types
The type of supported index types.
Instances
Show IndexType Source # | |
NFData IndexType Source # | |
Defined in Database.LSMTree.Internal.Index | |
Eq IndexType Source # | |
DecodeVersioned IndexType Source # | |
Defined in Database.LSMTree.Internal.Snapshot.Codec Methods decodeVersioned :: SnapshotVersion -> Decoder s IndexType Source # | |
Encode IndexType Source # | |
indexToIndexType :: Index -> IndexType Source #
Indexes
The type of supported indexes.
Constructors
CompactIndex !IndexCompact | |
OrdinaryIndex !IndexOrdinary |
search :: SerialisedKey -> Index -> PageSpan Source #
Searches for a page span that contains a key–value pair with the given key. If there is indeed such a pair, the result is the corresponding page span; if there is no such pair, the result is an arbitrary but valid page span.
sizeInPages :: Index -> NumPages Source #
Yields the number of pages covered by an index.
headerLBS :: IndexType -> LazyByteString Source #
Yields the header of the serialised form of an index.
See the module documentation for how to generate a complete serialised index.
finalLBS :: NumEntries -> Index -> LazyByteString Source #
Yields the footer of the serialised form of an index.
See the module documentation for how to generate a complete serialised index.
fromSBS :: IndexType -> ShortByteString -> Either String (NumEntries, Index) Source #
Reads an index along with the number of entries of the respective run from a byte string.
The byte string must contain the serialised index exactly, with no leading or trailing space. Furthermore, its contents must be stored 64-bit-aligned.
The contents of the byte string may be directly used as the backing memory for the constructed index. Currently, this is done for compact indexes.
For deserialising numbers, the endianness of the host system is used. If serialisation has been done with a different endianness, this mismatch is detected by looking at the type–version indicator.
Index accumulators
The type of supported index accumulators, where an index accumulator denotes an index under incremental construction.
Incremental index construction is only guaranteed to work correctly when the supplied key ranges do not overlap and are given in ascending order.
Constructors
CompactIndexAcc !(IndexCompactAcc s) | |
OrdinaryIndexAcc !(IndexOrdinaryAcc s) |
newWithDefaults :: IndexType -> ST s (IndexAcc s) Source #
Create a new index accumulator, using a default configuration.
appendSingle :: (SerialisedKey, SerialisedKey) -> IndexAcc s -> ST s (Maybe Chunk) Source #
Adds information about a single page that fully comprises one or more key–value pairs to an index and outputs newly available chunks.
See the documentation of the IndexAcc
type for constraints to adhere to.
appendMulti :: (SerialisedKey, Word32) -> IndexAcc s -> ST s [Chunk] Source #
Adds information about multiple pages that together comprise a single key–value pair to an index and outputs newly available chunks.
The provided Word32
value denotes the number of overflow pages, so that
the number of pages that comprise the key–value pair is the successor of
that number.
See the documentation of the IndexAcc
type for constraints to adhere to.
unsafeEnd :: IndexAcc s -> ST s (Maybe Chunk, Index) Source #
Returns the constructed index, along with a final chunk in case the
serialised key list has not been fully output yet, thereby invalidating the
index under construction. Executing unsafeEnd index
is only safe when
index
is not used afterwards.