diff --git a/hbs2-storage-ncq/lib/HBS2/Storage/NCQ2.hs b/hbs2-storage-ncq/lib/HBS2/Storage/NCQ2.hs index 19f37592..71c45265 100644 --- a/hbs2-storage-ncq/lib/HBS2/Storage/NCQ2.hs +++ b/hbs2-storage-ncq/lib/HBS2/Storage/NCQ2.hs @@ -598,16 +598,16 @@ ncqStorageRun2 ncq@NCQStorage2{..} = flip runContT pure do Nothing -> none Just e -> answer (Just (InMemory (ncqEntryData e))) >> next - useVersion ncq $ const do + -- useVersion ncq $ const do - tracked <- readTVarIO ncqTrackedFiles + tracked <- readTVarIO ncqTrackedFiles - for_ tracked $ \(TrackedFile{..}) -> do - readTVarIO tfCached >>= \case + for_ tracked $ \(TrackedFile{..}) -> do + readTVarIO tfCached >>= \case + Just ce -> lookupCached tfKey ce + Nothing -> ncqLoadTrackedFile ncq TrackedFile{..} >>= \case + Nothing -> err $ "unable to load index" <+> pretty tfKey Just ce -> lookupCached tfKey ce - Nothing -> ncqLoadTrackedFile ncq TrackedFile{..} >>= \case - Nothing -> err $ "unable to load index" <+> pretty tfKey - Just ce -> lookupCached tfKey ce next diff --git a/hbs2-tests/test/TestNCQ.hs b/hbs2-tests/test/TestNCQ.hs index d372af7c..692defdb 100644 --- a/hbs2-tests/test/TestNCQ.hs +++ b/hbs2-tests/test/TestNCQ.hs @@ -954,52 +954,40 @@ testNCQ2Lookup1 syn TestEnv{..} = do (h, answ) <- atomically $ readTQueue readQ - f1 <- ncqLookupEntry sto h <&> isJust + ncqLookupEntry sto h >>= \case + Nothing -> none + Just e -> atomically (putTMVar answ (Just (InMemory (ncqEntryData e)))) >> next - when f1 do - atomically (putTMVar answ True) >> next + ffs <- readTVarIO $ (N2.ncqTrackedFiles sto) - ffs <- liftIO $ N2.ncqListTrackedFiles sto + for_ ffs $ \TrackedFile{..} -> do + readTVarIO tfCached >>= \case - for_ ffs $ \(f, ce, te) -> do - - -- when (isNotPending ce) do - case ce of Just (PendingEntry{}) -> none Just (CachedEntry{..}) -> do - found <- ncqLookupIndex h (cachedMmapedIdx, cachedNway) <&> isJust - - when found do - atomically (putTMVar answ True) >> next + ncqLookupIndex h (cachedMmapedIdx, cachedNway) >>= \case + Nothing -> none + Just (o,s) -> atomically (putTMVar answ (Just (N2.InFossil tfKey cachedMmapedData o s))) >> next Nothing -> do - tnow <- getTimeCoarse >>= newTVarIO + ncqLoadTrackedFile sto TrackedFile{..} >>= \case + Nothing -> err "FUCK" >> next + Just PendingEntry -> next + Just CachedEntry{..} -> do + ncqLookupIndex h (cachedMmapedIdx, cachedNway) >>= \case + Nothing -> none + Just (o,s) -> atomically (putTMVar answ (Just (N2.InFossil tfKey cachedMmapedData o s))) >> next - let indexFile = N2.ncqGetFileName sto (toFileName (IndexFile f)) - let dataFile = N2.ncqGetFileName sto (toFileName (DataFile f)) - - what@(idxBs, idxNway) <- nwayHashMMapReadOnly indexFile `orDie` "mmap fucked" - datBs <- mmapFileByteString dataFile Nothing - - let ce = CachedEntry idxBs datBs idxNway tnow - - atomically $ writeTVar te (Just ce) - - found <- ncqLookupIndex h what <&> isJust - - when found do - atomically (putTMVar answ True) >> next - - atomically (putTMVar answ False) >> next + atomically (putTMVar answ Nothing) >> next liftIO $ pooledForConcurrentlyN_ nt hs $ \h -> do answ <- newEmptyTMVarIO atomically $ writeTQueue readQ (h, answ) found <- atomically $ takeTMVar answ - when found do + when (isJust found) do atomically $ modifyTVar' tfound succ t1 <- getTimeCoarse