| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
Database.LSMTree.Internal.Snapshot
Synopsis
- newtype SnapshotLabel = SnapshotLabel Text
- data SnapshotMetaData = SnapshotMetaData {}
- newtype SnapLevels r = SnapLevels {
- getSnapLevels :: Vector (SnapLevel r)
- data SnapLevel r = SnapLevel {
- snapIncoming :: !(SnapIncomingRun r)
- snapResidentRuns :: !(Vector r)
- data SnapIncomingRun r
- data SnapMergingRun t r
- = SnapCompletedMerge !MergeDebt !r
- | SnapOngoingMerge !RunParams !MergeCredits !(Vector r) !t
- newtype SnapMergingTree r = SnapMergingTree (SnapMergingTreeState r)
- data SnapMergingTreeState r
- data SnapPendingMerge r
- = SnapPendingLevelMerge ![SnapPreExistingRun r] !(Maybe (SnapMergingTree r))
- | SnapPendingUnionMerge ![SnapMergingTree r]
- data SnapPreExistingRun r
- toSnapLevels :: (PrimMonad m, MonadMVar m) => Levels m h -> m (SnapLevels (Ref (Run m h)))
- toSnapMergingTree :: (PrimMonad m, MonadMVar m) => Ref (MergingTree m h) -> m (SnapMergingTree (Ref (Run m h)))
- snapshotWriteBuffer :: (MonadMVar m, MonadSTM m, MonadST m, MonadMask m) => HasFS m h -> HasBlockIO m h -> UniqCounter m -> UniqCounter m -> ActionRegistry m -> ActiveDir -> NamedSnapshotDir -> WriteBuffer -> Ref (WriteBufferBlobs m h) -> m WriteBufferFsPaths
- openWriteBuffer :: (MonadMVar m, MonadMask m, MonadSTM m, MonadST m) => ActionRegistry m -> ResolveSerialisedValue -> HasFS m h -> HasBlockIO m h -> RefCtx -> UniqCounter m -> ActiveDir -> WriteBufferFsPaths -> m (WriteBuffer, Ref (WriteBufferBlobs m h))
- data SnapshotRun = SnapshotRun {}
- snapshotRun :: (MonadMask m, PrimMonad m) => HasFS m h -> HasBlockIO m h -> UniqCounter m -> ActionRegistry m -> NamedSnapshotDir -> Ref (Run m h) -> m SnapshotRun
- openRun :: (MonadMask m, MonadSTM m, MonadST m) => HasFS m h -> HasBlockIO m h -> RefCtx -> UniqCounter m -> ActionRegistry m -> NamedSnapshotDir -> ActiveDir -> Salt -> SnapshotRun -> m (Ref (Run m h))
- fromSnapLevels :: forall m h. (MonadMask m, MonadMVar m, MonadSTM m, MonadST m) => HasFS m h -> HasBlockIO m h -> RefCtx -> Salt -> UniqCounter m -> TableConfig -> ResolveSerialisedValue -> ActionRegistry m -> ActiveDir -> SnapLevels (Ref (Run m h)) -> m (Levels m h)
- fromSnapMergingTree :: forall m h. (MonadMask m, MonadMVar m, MonadSTM m, MonadST m) => HasFS m h -> HasBlockIO m h -> RefCtx -> Salt -> UniqCounter m -> ResolveSerialisedValue -> ActiveDir -> ActionRegistry m -> SnapMergingTree (Ref (Run m h)) -> m (Ref (MergingTree m h))
- hardLinkRunFiles :: (MonadMask m, PrimMonad m) => HasFS m h -> HasBlockIO m h -> ActionRegistry m -> RunFsPaths -> RunFsPaths -> m ()
Snapshot metadata
newtype SnapshotLabel Source #
Custom, user-supplied text that is included in the metadata.
The main use case for a SnapshotLabel is for the user to supply textual
information about the key/value/blob type for the table that corresponds to
the snapshot. This information is used to dynamically check that a snapshot
is opened at the correct key/value/blob type.
Constructors
| SnapshotLabel Text |
Instances
| IsString SnapshotLabel Source # | |
Defined in Database.LSMTree.Internal.Snapshot Methods fromString :: String -> SnapshotLabel # | |
| Show SnapshotLabel Source # | |
Defined in Database.LSMTree.Internal.Snapshot Methods showsPrec :: Int -> SnapshotLabel -> ShowS # show :: SnapshotLabel -> String # showList :: [SnapshotLabel] -> ShowS # | |
| NFData SnapshotLabel Source # | |
Defined in Database.LSMTree.Internal.Snapshot Methods rnf :: SnapshotLabel -> () # | |
| Eq SnapshotLabel Source # | |
Defined in Database.LSMTree.Internal.Snapshot Methods (==) :: SnapshotLabel -> SnapshotLabel -> Bool # (/=) :: SnapshotLabel -> SnapshotLabel -> Bool # | |
| DecodeVersioned SnapshotLabel Source # | |
Defined in Database.LSMTree.Internal.Snapshot.Codec Methods decodeVersioned :: SnapshotVersion -> Decoder s SnapshotLabel Source # | |
| Encode SnapshotLabel Source # | |
Defined in Database.LSMTree.Internal.Snapshot.Codec Methods encode :: SnapshotLabel -> Encoding Source # | |
data SnapshotMetaData Source #
Constructors
| SnapshotMetaData | |
Fields
| |
Instances
| NFData SnapshotMetaData Source # | |
Defined in Database.LSMTree.Internal.Snapshot Methods rnf :: SnapshotMetaData -> () # | |
| Eq SnapshotMetaData Source # | |
Defined in Database.LSMTree.Internal.Snapshot Methods (==) :: SnapshotMetaData -> SnapshotMetaData -> Bool # (/=) :: SnapshotMetaData -> SnapshotMetaData -> Bool # | |
| DecodeVersioned SnapshotMetaData Source # | |
Defined in Database.LSMTree.Internal.Snapshot.Codec Methods decodeVersioned :: SnapshotVersion -> Decoder s SnapshotMetaData Source # | |
| Encode SnapshotMetaData Source # | |
Defined in Database.LSMTree.Internal.Snapshot.Codec Methods encode :: SnapshotMetaData -> Encoding Source # | |
Levels snapshot format
newtype SnapLevels r Source #
Constructors
| SnapLevels | |
Fields
| |
Instances
Constructors
| SnapLevel | |
Fields
| |
Instances
data SnapIncomingRun r Source #
Note that for snapshots of incoming runs, we store only the merge debt and nominal credits, not the nominal debt or the merge credits. The rationale is a bit subtle.
The nominal debt does not need to be stored because it can be derived based on the table's write buffer capacity (which is stored in the snapshot's TableConfig), and on the level number that the merge is at (which also known from the snapshot structure).
The merge credits can be recalculated from the combination of the nominal debt, nominal credits and merge debt.
The merge debt is always the sum of the size of the input runs, so at first glance this seems redundant. However for completed merges we no longer have the input runs, so we must store the merge debt if we are to perfectly round trip the snapshot. This is a nice simple property to have though it is probably not 100% essential. We could weaken the round trip property to allow forgetting the merge debt and credit of completed merges (and set them both to zero).
Constructors
| SnapIncomingMergingRun | |
Fields
| |
| SnapIncomingSingleRun !r | |
Instances
data SnapMergingRun t r Source #
Constructors
| SnapCompletedMerge !MergeDebt !r | |
| SnapOngoingMerge !RunParams !MergeCredits !(Vector r) !t |
Instances
MergeTree snapshot format
newtype SnapMergingTree r Source #
Constructors
| SnapMergingTree (SnapMergingTreeState r) |
Instances
data SnapMergingTreeState r Source #
Constructors
| SnapCompletedTreeMerge !r | |
| SnapPendingTreeMerge !(SnapPendingMerge r) | |
| SnapOngoingTreeMerge !(SnapMergingRun TreeMergeType r) |
Instances
data SnapPendingMerge r Source #
Constructors
| SnapPendingLevelMerge ![SnapPreExistingRun r] !(Maybe (SnapMergingTree r)) | |
| SnapPendingUnionMerge ![SnapMergingTree r] |
Instances
data SnapPreExistingRun r Source #
Constructors
| SnapPreExistingRun !r | |
| SnapPreExistingMergingRun !(SnapMergingRun LevelMergeType r) |
Instances
Conversion to levels snapshot format
toSnapLevels :: (PrimMonad m, MonadMVar m) => Levels m h -> m (SnapLevels (Ref (Run m h))) Source #
Conversion to merging tree snapshot format
toSnapMergingTree :: (PrimMonad m, MonadMVar m) => Ref (MergingTree m h) -> m (SnapMergingTree (Ref (Run m h))) Source #
Write buffer
snapshotWriteBuffer :: (MonadMVar m, MonadSTM m, MonadST m, MonadMask m) => HasFS m h -> HasBlockIO m h -> UniqCounter m -> UniqCounter m -> ActionRegistry m -> ActiveDir -> NamedSnapshotDir -> WriteBuffer -> Ref (WriteBufferBlobs m h) -> m WriteBufferFsPaths Source #
openWriteBuffer :: (MonadMVar m, MonadMask m, MonadSTM m, MonadST m) => ActionRegistry m -> ResolveSerialisedValue -> HasFS m h -> HasBlockIO m h -> RefCtx -> UniqCounter m -> ActiveDir -> WriteBufferFsPaths -> m (WriteBuffer, Ref (WriteBufferBlobs m h)) Source #
Run
data SnapshotRun Source #
Information needed to open a Run from disk using snapshotRun and
openRun.
TODO: one could imagine needing only the RunNumber to identify the files
on disk, and the other parameters being stored with the run itself, rather
than needing to be supplied.
Constructors
| SnapshotRun | |
Fields | |
Instances
| NFData SnapshotRun Source # | |
Defined in Database.LSMTree.Internal.Snapshot Methods rnf :: SnapshotRun -> () # | |
| Eq SnapshotRun Source # | |
Defined in Database.LSMTree.Internal.Snapshot | |
| DecodeVersioned SnapshotRun Source # | |
Defined in Database.LSMTree.Internal.Snapshot.Codec Methods decodeVersioned :: SnapshotVersion -> Decoder s SnapshotRun Source # | |
| Encode SnapshotRun Source # | |
Defined in Database.LSMTree.Internal.Snapshot.Codec Methods encode :: SnapshotRun -> Encoding Source # | |
snapshotRun :: (MonadMask m, PrimMonad m) => HasFS m h -> HasBlockIO m h -> UniqCounter m -> ActionRegistry m -> NamedSnapshotDir -> Ref (Run m h) -> m SnapshotRun Source #
creates hard links for all files
associated with the snapshotRun _ _ snapUc _ targetDir runrun, and puts the new directory entries in the
targetDir directory. The entries are renamed using snapUc.
openRun :: (MonadMask m, MonadSTM m, MonadST m) => HasFS m h -> HasBlockIO m h -> RefCtx -> UniqCounter m -> ActionRegistry m -> NamedSnapshotDir -> ActiveDir -> Salt -> SnapshotRun -> m (Ref (Run m h)) Source #
takes all run
files that are referenced by openRun _ _ uniqCounter _ sourceDir targetDir _ snaprunsnaprun, and hard links them from sourceDir
into targetDir with new, unique names (using uniqCounter). Each set of
(hard linked) files that represents a run is opened and verified, returning
Run as a result.
The result must ultimately be released using releaseRef.
Opening snapshot formats
Levels format
fromSnapLevels :: forall m h. (MonadMask m, MonadMVar m, MonadSTM m, MonadST m) => HasFS m h -> HasBlockIO m h -> RefCtx -> Salt -> UniqCounter m -> TableConfig -> ResolveSerialisedValue -> ActionRegistry m -> ActiveDir -> SnapLevels (Ref (Run m h)) -> m (Levels m h) Source #
Duplicates runs and re-creates merging runs.
Merging Tree format
fromSnapMergingTree :: forall m h. (MonadMask m, MonadMVar m, MonadSTM m, MonadST m) => HasFS m h -> HasBlockIO m h -> RefCtx -> Salt -> UniqCounter m -> ResolveSerialisedValue -> ActiveDir -> ActionRegistry m -> SnapMergingTree (Ref (Run m h)) -> m (Ref (MergingTree m h)) Source #
Converts a snapshot of a merging tree of runs to a real merging tree.
Returns a new reference. Input runs remain owned by the caller.
Hard links
hardLinkRunFiles :: (MonadMask m, PrimMonad m) => HasFS m h -> HasBlockIO m h -> ActionRegistry m -> RunFsPaths -> RunFsPaths -> m () Source #
creates a hard link for
each hardLinkRunFiles _ _ _ sourcePaths targetPathssourcePaths path using the corresponding targetPaths path as the
name for the new directory entry.