Skip to content

Commit

Permalink
fix calculation of merge debt
Browse files Browse the repository at this point in the history
The adjustment of the calculation is necessary to avoid assertion
failures for the new assertion.
  • Loading branch information
mheinzel committed Jul 29, 2024
1 parent b524ebf commit 260c4d5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions prototypes/ScheduledMerges.hs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ newMerge tr level mergepolicy mergelast rs = do
mergeRunsSize = map Map.size rs
}
assert (length rs `elem` [4, 5]) $
MergingRun mergepolicy mergelast <$> newSTRef (OngoingMerge debt rs r)
assert (mergeDebtLeft debt >= cost) $
MergingRun mergepolicy mergelast <$> newSTRef (OngoingMerge debt rs r)
where
cost = sum (map Map.size rs)
-- How much we need to discharge before the merge can be guaranteed
Expand All @@ -299,7 +300,7 @@ newMerge tr level mergepolicy mergelast rs = do
debt = newMergeDebt $ case mergepolicy of
MergePolicyLevelling -> 4 * tieringRunSize (level-1)
+ levellingRunSize level
MergePolicyTiering -> 4 * tieringRunSize (level-1)
MergePolicyTiering -> length rs * tieringRunSize (level-1)
-- deliberately lazy:
r = case mergelast of
MergeMidLevel -> (mergek rs)
Expand Down Expand Up @@ -364,6 +365,10 @@ data MergeDebt =
newMergeDebt :: Debt -> MergeDebt
newMergeDebt d = MergeDebt 0 d

mergeDebtLeft :: MergeDebt -> Int
mergeDebtLeft (MergeDebt c d) =
assert (c < d) $ d - c

-- | As credits are paid, debt is reduced in batches when sufficient credits have accumulated.
data MergeDebtPaydown =
-- | This remaining merge debt is fully paid off with credits.
Expand Down

0 comments on commit 260c4d5

Please sign in to comment.