Skip to content

Commit cd9145e

Browse files
authored
Merge pull request #501 from IntersectMBO/jdral/remove-levels-invariant
Remove commented out `levelsInvariant` code
2 parents f52293b + 9a0c567 commit cd9145e

File tree

1 file changed

+1
-87
lines changed

1 file changed

+1
-87
lines changed

src/Database/LSMTree/Internal/MergeSchedule.hs

Lines changed: 1 addition & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -524,86 +524,6 @@ flushWriteBuffer tr conf@TableConfig{confDiskCachePolicy}
524524
, tableCache = tableCache'
525525
}
526526

527-
{- TODO: re-enable
528-
-- | Note that the invariants rely on the fact that levelling is only used on
529-
-- the last level.
530-
--
531-
-- NOTE: @_levelsInvariant@ is based on the @ScheduledMerges.invariant@
532-
-- prototype. See @ScheduledMerges.invariant@ for documentation about the merge
533-
-- algorithm.
534-
_levelsInvariant :: forall m h. TableConfig -> Levels m h -> ST (PrimState m) Bool
535-
_levelsInvariant conf levels =
536-
go (LevelNo 1) levels >>= \ !_ -> pure True
537-
where
538-
sr = confSizeRatio conf
539-
wba = confWriteBufferAlloc conf
540-
541-
go :: LevelNo -> Levels m h -> ST (PrimState m) ()
542-
go !_ (V.uncons -> Nothing) = pure ()
543-
544-
go !ln (V.uncons -> Just (Level mr rs, ls)) = do
545-
mrs <- case mr of
546-
SingleRun r -> pure $ CompletedMerge r
547-
MergingRun var -> readMutVar var
548-
assert (length rs < sizeRatioInt sr) $ pure ()
549-
assert (expectedRunLengths ln rs ls) $ pure ()
550-
assert (expectedMergingRunLengths ln mr mrs ls) $ pure ()
551-
go (succ ln) ls
552-
553-
-- All runs within a level "proper" (as opposed to the incoming runs
554-
-- being merged) should be of the correct size for the level.
555-
expectedRunLengths ln rs ls = do
556-
case mergePolicyForLevel (confMergePolicy conf) ln ls of
557-
-- Levels using levelling have only one run, and that single run is
558-
-- (almost) always involved in an ongoing merge. Thus there are no
559-
-- other "normal" runs. The exception is when a levelling run becomes
560-
-- too large and is promoted, in that case initially there's no merge,
561-
-- but it is still represented as a 'MergingRun', using 'SingleRun'.
562-
LevelLevelling -> assert (V.null rs) True
563-
LevelTiering -> V.all (\r -> assert (fits LevelTiering r ln) True) rs
564-
565-
-- Incoming runs being merged also need to be of the right size, but the
566-
-- conditions are more complicated.
567-
expectedMergingRunLengths ln mr mrs ls =
568-
case mergePolicyForLevel (confMergePolicy conf) ln ls of
569-
LevelLevelling ->
570-
case (mr, mrs) of
571-
-- A single incoming run (which thus didn't need merging) must be
572-
-- of the expected size range already
573-
(SingleRun r, CompletedMerge{}) -> assert (fits LevelLevelling r ln) True
574-
-- A completed merge for levelling can be of almost any size at all!
575-
-- It can be smaller, due to deletions in the last level. But it
576-
-- can't be bigger than would fit into the next level.
577-
(_, CompletedMerge r) -> assert (fitsUB LevelLevelling r (succ ln)) True
578-
LevelTiering ->
579-
case (mr, mrs, mergeLastForLevel ls) of
580-
-- A single incoming run (which thus didn't need merging) must be
581-
-- of the expected size already
582-
(SingleRun r, CompletedMerge{}, _) -> assert (fits LevelTiering r ln) True
583-
584-
-- A completed last level run can be of almost any smaller size due
585-
-- to deletions, but it can't be bigger than the next level down.
586-
-- Note that tiering on the last level only occurs when there is
587-
-- a single level only.
588-
(_, CompletedMerge r, Merge.LastLevel) ->
589-
assert (ln == LevelNo 1) $
590-
assert (fitsUB LevelTiering r (succ ln)) $
591-
True
592-
593-
-- A completed mid level run is usually of the size for the
594-
-- level it is entering, but can also be one smaller (in which case
595-
-- it'll be held back and merged again).
596-
(_, CompletedMerge r, Merge.MidLevel) ->
597-
assert (fitsUB LevelTiering r ln || fitsUB LevelTiering r (succ ln)) True
598-
599-
-- Check that a run fits in the current level
600-
fits policy r ln = fitsLB policy r ln && fitsUB policy r ln
601-
-- Check that a run is too large for previous levels
602-
fitsLB policy r ln = maxRunSize sr wba policy (pred ln) < Run.size r
603-
-- Check that a run is too small for next levels
604-
fitsUB policy r ln = Run.size r <= maxRunSize sr wba policy ln
605-
-}
606-
607527
{-# SPECIALISE addRunToLevels ::
608528
Tracer IO (AtLevel MergeTrace)
609529
-> TableConfig
@@ -635,13 +555,7 @@ addRunToLevels ::
635555
-> Levels m h
636556
-> m (Levels m h)
637557
addRunToLevels tr conf@TableConfig{..} resolve hfs hbio root uc r0 reg levels = do
638-
ls' <- go (LevelNo 1) (V.singleton r0) levels
639-
{- TODO: re-enable
640-
#ifdef NO_IGNORE_ASSERTS
641-
void $ stToIO $ _levelsInvariant conf ls'
642-
#endif
643-
-}
644-
return ls'
558+
go (LevelNo 1) (V.singleton r0) levels
645559
where
646560
-- NOTE: @go@ is based on the @increment@ function from the
647561
-- @ScheduledMerges@ prototype.

0 commit comments

Comments
 (0)