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

Database.LSMTree.Internal.Merge

Description

The Merge type and its functions are not intended for concurrent use. Concurrent access should therefore be sequentialised using a suitable concurrency primitive, such as an MVar.

Synopsis

Documentation

data Merge t m h Source #

An in-progress incremental k-way merge of Runs.

Since we always resolve all entries of the same key in one go, there is no need to store incompletely-resolved entries.

Constructors

Merge 

Fields

data MergeType Source #

Fully general merge type, mainly useful for testing.

Instances

Instances details
Show MergeType Source # 
Instance details

Defined in Database.LSMTree.Internal.Merge

NFData MergeType Source # 
Instance details

Defined in Database.LSMTree.Internal.Merge

Methods

rnf :: MergeType -> () #

Eq MergeType Source # 
Instance details

Defined in Database.LSMTree.Internal.Merge

IsMergeType MergeType Source # 
Instance details

Defined in Database.LSMTree.Internal.Merge

class IsMergeType t where Source #

Merges can either exist on a level of the LSM, or be a union merge of two tables.

Methods

isLastLevel :: t -> Bool Source #

A last level merge behaves differently from a mid-level merge: last level merges can actually remove delete operations, whereas mid-level merges must preserve them.

isUnion :: t -> Bool Source #

Union merges follow the semantics of Data.Map.unionWith (<>). Since the input runs are semantically treated like Data.Maps, deletes are ignored and inserts act like mupserts, so they need to be merged monoidally using resolveValue.

data LevelMergeType Source #

Different types of merges created as part of a regular (non-union) level.

A last level merge behaves differently from a mid-level merge: last level merges can actually remove delete operations, whereas mid-level merges must preserve them. This is orthogonal to the MergePolicy.

data TreeMergeType Source #

Different types of merges created as part of the merging tree.

Constructors

MergeLevel 
MergeUnion 

Instances

Instances details
Show TreeMergeType Source # 
Instance details

Defined in Database.LSMTree.Internal.Merge

NFData TreeMergeType Source # 
Instance details

Defined in Database.LSMTree.Internal.Merge

Methods

rnf :: TreeMergeType -> () #

Eq TreeMergeType Source # 
Instance details

Defined in Database.LSMTree.Internal.Merge

IsMergeType TreeMergeType Source # 
Instance details

Defined in Database.LSMTree.Internal.Merge

DecodeVersioned TreeMergeType Source # 
Instance details

Defined in Database.LSMTree.Internal.Snapshot.Codec

Encode TreeMergeType Source #

We start the tags for these merge types at an offset. This way, if we serialise MR.MergeMidLevel :: MR.LevelMergeType as 0 and then accidentally try deserialising it as a MR.TreeMergeType, that will fail.

However, LevelMergeType and TreeMergeType are only different (overlapping) subsets of MergeType. In particular, MergeLastLevel and MergeLevel are semantically the same. Encoding them as the same number leaves the door open to relaxing the restrictions on which merge types can occur where, e.g. decoding them as a general MergeType, without having to change the file format.

Instance details

Defined in Database.LSMTree.Internal.Snapshot.Codec

data MergeState Source #

The current state of the merge.

Constructors

Merging

There is still merging work to be done

MergingDone

There is no more merging work to be done, but the merge still has to be completed to yield a new run.

Completed

A run was yielded as the result of a merge. The merge is implicitly closed.

Closed

The merge was closed before it was completed.

new :: (IsMergeType t, MonadMask m, MonadSTM m, MonadST m) => HasFS m h -> HasBlockIO m h -> RunParams -> t -> Mappend -> RunFsPaths -> Vector (Ref (Run m h)) -> m (Maybe (Merge t m h)) Source #

Returns Nothing if no input Run contains any entries. The list of runs should be sorted from new to old.

abort :: (MonadMask m, MonadSTM m, MonadST m) => Merge t m h -> m () Source #

This function should be called when discarding a Merge before it was done (i.e. returned MergeComplete). This removes the incomplete files created for the new run so far and avoids leaking file handles.

Once it has been called, do not use the Merge any more!

complete :: (MonadSTM m, MonadST m, MonadMask m) => Merge t m h -> m (Ref (Run m h)) Source #

Complete a Merge, returning a new Run as the result of merging the input runs.

All resources held by the merge are released, so do not use the it any more!

This function will not do any merging work if there is any remaining. That is, if not enough steps were performed to exhaust the input Readers, this function will throw an error.

Returns an error if the merge was not yet done, if it was already completed before, or if it was already closed.

Note: this function creates new Run resources, so it is recommended to run this function with async exceptions masked. Otherwise, these resources can leak. And it must eventually be released with releaseRef.

stepsToCompletion :: (MonadMask m, MonadSTM m, MonadST m) => Merge t m h -> Int -> m (Ref (Run m h)) Source #

Like steps, but calling complete once the merge is finished.

Note: run with async exceptions masked. See complete.

stepsToCompletionCounted :: (MonadMask m, MonadSTM m, MonadST m) => Merge t m h -> Int -> m (Int, Ref (Run m h)) Source #

Like steps, but calling complete once the merge is finished.

Note: run with async exceptions masked. See complete.

data StepResult Source #

Constructors

MergeInProgress 
MergeDone 

Instances

Instances details
Eq StepResult Source # 
Instance details

Defined in Database.LSMTree.Internal.Merge

steps Source #

Arguments

:: (MonadMask m, MonadSTM m, MonadST m) 
=> Merge t m h 
-> Int

How many input entries to consume (at least)

-> m (Int, StepResult) 

Do at least a given number of steps of merging. Each step reads a single entry, then either resolves the previous entry with the new one or writes it out to the run being created. Since we always finish resolving a key we started, we might do slightly more work than requested.

Returns the number of input entries read, which is guaranteed to be at least as many as requested (unless the merge is complete).

Returns an error if the merge was already completed or closed.