lsm-tree-0.1.0.0: Log-structured merge-trees
Safe HaskellSafe-Inferred
LanguageGHC2021

Database.LSMTree.Internal.RunBuilder

Description

A mutable run (RunBuilder) that is under construction.

Synopsis

Documentation

data RunBuilder m h Source #

The in-memory representation of an LSM run that is under construction. (The "M" stands for mutable.) This is the output sink for two key algorithms: 1. writing out the write buffer, and 2. incrementally merging two or more runs.

It contains open file handles for all four files used in the disk representation of a run. Each file handle is opened write-only and should be written to using normal buffered I/O.

Not suitable for concurrent construction from multiple threads!

Constructors

RunBuilder 

Fields

data IndexType Source #

The type of supported index types.

Constructors

Compact 
Ordinary 

new Source #

Arguments

:: (MonadST m, MonadSTM m) 
=> HasFS m h 
-> HasBlockIO m h 
-> RunParams 
-> RunFsPaths 
-> NumEntries

an upper bound of the number of entries to be added

-> m (RunBuilder m h) 

Create an RunBuilder to start building a run.

NOTE: new assumes that runDir that the run is created in exists.

addKeyOp :: (MonadST m, MonadSTM m, MonadThrow m) => RunBuilder m h -> SerialisedKey -> Entry SerialisedValue (RawBlobRef m h) -> m () Source #

Add a key/op pair.

In the InsertWithBlob case, the RawBlobRef identifies where the blob can be found (which is either from a write buffer or another run). The blobs will be copied from their existing blob file into the new run's blob file.

Use only for entries that are fully in-memory (other than any blob). To handle larger-than-page values in a chunked style during run merging, use addLargeSerialisedKeyOp.

The k/ops and the primary array of the index get written incrementally, everything else only at the end when unsafeFinalise is called.

unsafeFinalise :: (MonadST m, MonadSTM m, MonadThrow m) => RunBuilder m h -> m (HasFS m h, HasBlockIO m h, RunFsPaths, Bloom SerialisedKey, Index, RunParams, NumEntries) Source #

Finish construction of the run. Writes the filter and index to file and leaves all written files on disk.

Do not use the RunBuilder after calling this function!

TODO: Ensure proper cleanup even in presence of exceptions.

close :: MonadSTM m => RunBuilder m h -> m () Source #

Close a run that is being constructed (has not been finalised yet), removing all files associated with it from disk. After calling this operation, the run must not be used anymore.

TODO: Ensure proper cleanup even in presence of exceptions.