From bdf0395b1e44460bcab30d7db666e047a2db33f5 Mon Sep 17 00:00:00 2001 From: voidlizard Date: Thu, 31 Jul 2025 15:22:36 +0300 Subject: [PATCH] wip --- .../lib/HBS2/Storage/NCQ3/Internal/Fossil.hs | 11 +++++----- hbs2-tests/test/NCQ3.hs | 21 ++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/hbs2-storage-ncq/lib/HBS2/Storage/NCQ3/Internal/Fossil.hs b/hbs2-storage-ncq/lib/HBS2/Storage/NCQ3/Internal/Fossil.hs index bb91f397..52f64a31 100644 --- a/hbs2-storage-ncq/lib/HBS2/Storage/NCQ3/Internal/Fossil.hs +++ b/hbs2-storage-ncq/lib/HBS2/Storage/NCQ3/Internal/Fossil.hs @@ -71,12 +71,13 @@ ncqFossilMergeStep me@NCQStorage3{..} = withSem ncqServiceSem $ flip runContT p for_ [f1, f2] $ \fi -> do let fik = coerce fi - writeFiltered me (ncqGetFileName me fi) fd $ \_ _ k _ -> do + writeFiltered me (ncqGetFileName me fi) fd $ \o _ k _ -> do ncqLocate_ False me k >>= \case Nothing -> pure False Just (InMemory{}) -> pure False - Just (InFossil fk _ _) -> do - let beWritten = fik >= fk + Just (InFossil fk o1 _) -> do + let skip = fk > fik || (fk == fik && o1 < fromIntegral o) + let beWritten = not skip atomically do here <- readTVar already <&> HS.member k let proceed = not here && beWritten @@ -118,8 +119,8 @@ writeFiltered ncq fn out filt = do ncqStorageScanDataFile ncq fn $ \o s k v -> do skip <- filt o s k v <&> not - when skip do - debug $ pretty k <+> pretty "skipped" + -- when skip do + -- debug $ pretty k <+> pretty "skipped" unless skip $ liftIO do void $ appendSection out (LBS.toStrict (makeEntryLBS k v)) diff --git a/hbs2-tests/test/NCQ3.hs b/hbs2-tests/test/NCQ3.hs index 2e632eca..d36429b6 100644 --- a/hbs2-tests/test/NCQ3.hs +++ b/hbs2-tests/test/NCQ3.hs @@ -364,7 +364,7 @@ ncq3Tests = do let (_, argz) = splitOpts [] syn let n = headDef 50000 [ fromIntegral x | LitIntVal x <- argz ] - let p0 = headDef 0.25 [ realToFrac x | LitScientificVal x <- drop 1 argz ] + let p0 = headDef 0.55 [ realToFrac x | LitScientificVal x <- drop 1 argz ] thashes <- newTVarIO mempty @@ -391,19 +391,20 @@ ncq3Tests = do notice $ "should be deleted" <+> pretty (HS.size deleted) <+> "/" <+> pretty tnum - t0 <- getTimeCoarse + ncqWithStorage3 dir $ \sto@NCQStorage3{..} -> do - ncqIndexCompactFull sto - -- ncqCompactStep sto + notice "wait for compaction" - t1 <- getTimeCoarse + flip runContT pure do - let dt = timeSpecDeltaSeconds @(Fixed E6) t0 t1 - - notice $ "ncqCompactStep time" <+> pretty dt - - none + void $ ContT $ withAsync $ forever do + fs <- dirFiles (ncqGetWorkDir sto) + let n = List.length fs + ss <- sum <$> mapM getFileSize fs + notice $ "dir size" <+> pretty n <+> pretty (ss `div` megabytes) + pause @'Seconds 20 + pause @'Seconds 600 testNCQ3Concurrent1 :: MonadUnliftIO m => Bool