This commit is contained in:
voidlizard 2025-07-21 12:45:46 +03:00
parent e08f68fbaf
commit 77ee8410cc
2 changed files with 25 additions and 37 deletions

View File

@ -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

View File

@ -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