diff --git a/hbs2-storage-ncq/lib/HBS2/Storage/NCQ2.hs b/hbs2-storage-ncq/lib/HBS2/Storage/NCQ2.hs index c6387745..157d4718 100644 --- a/hbs2-storage-ncq/lib/HBS2/Storage/NCQ2.hs +++ b/hbs2-storage-ncq/lib/HBS2/Storage/NCQ2.hs @@ -316,11 +316,14 @@ ncqLocate2 ncq@NCQStorage2{..} href = flip runContT pure $ callCC \exit -> do pure mzero where - lookupEntry (hx :: HashRef) (mmaped, nway) = runMaybeT do - entryBs <- liftIO (nwayHashLookup nway mmaped (coerce hx)) >>= toMPlus - pure - ( fromIntegral $ N.word64 (BS.take 8 entryBs) - , fromIntegral $ N.word32 (BS.take 4 (BS.drop 8 entryBs)) ) + lookupEntry (hx :: HashRef) (mmaped, nway) = + liftIO (nwayHashLookup nway mmaped (coerce hx)) >>= \case + Nothing -> pure Nothing + Just entryBs -> do + pure $ Just + ( fromIntegral $ N.word64 (BS.take 8 entryBs) + , fromIntegral $ N.word32 (BS.take 4 (BS.drop 8 entryBs)) ) + {-# INLINE lookupEntry #-} ncqAlterEntrySTM :: NCQStorage2 -> HashRef -> (Maybe NCQEntry -> Maybe NCQEntry) -> STM () @@ -595,7 +598,7 @@ evictIfNeededSTM :: NCQStorage2 -> Maybe Int -> STM () evictIfNeededSTM NCQStorage2{..} howMany = do cur <- readTVar ncqCachedEntries - let need = fromMaybe (cur `div` 2) howMany + let need = fromMaybe cur howMany excess = max 0 (cur + need - ncqMaxCached) when (excess > 0) do diff --git a/hbs2-tests/test/TestNCQ.hs b/hbs2-tests/test/TestNCQ.hs index 9d8183ac..eb2b4196 100644 --- a/hbs2-tests/test/TestNCQ.hs +++ b/hbs2-tests/test/TestNCQ.hs @@ -756,7 +756,7 @@ testFilterEmulate1 n TestEnv{..} = do ncqWithStorage ncqDir $ \sto -> liftIO do - for_ [1..4] $ \i -> do + for_ [1..5] $ \i -> do notice $ "-- pass" <+> pretty i <+> "--"