This commit is contained in:
voidlizard 2025-06-23 08:01:11 +03:00
parent c5d578e2df
commit 240ae9179d
2 changed files with 21 additions and 15 deletions

View File

@ -159,9 +159,15 @@ ncqLookupEntrySTM ncq h = do
v <- readTVar tv v <- readTVar tv
pure $ Just (v, tv) pure $ Just (v, tv)
ncqPutBS :: MonadUnliftIO m => NCQStorage2 -> ByteString -> m HashRef ncqPutBS :: MonadUnliftIO m
ncqPutBS ncq@NCQStorage2{..} bs = do => NCQStorage2
let h = HashRef (hashObject @HbSync bs) -> Maybe NCQSectionType
-> Maybe HashRef
-> ByteString
-> m HashRef
ncqPutBS ncq@NCQStorage2{..} mtp mhref bs' = do
let h = fromMaybe (HashRef (hashObject @HbSync bs')) mhref
let bs = ncqMakeSectionBS mtp h bs'
atomically do atomically do
waitTSem ncqWriteSem waitTSem ncqWriteSem
stop <- readTVar ncqStorageStopReq stop <- readTVar ncqStorageStopReq
@ -220,7 +226,7 @@ ncqStorageRun2 ncq@NCQStorage2{..} = flip runContT pure $ callCC \exit -> do
sync <- readTVarIO ncqStorageSyncReq sync <- readTVarIO ncqStorageSyncReq
when (w > ncqFsync || sync) do when (w > ncqFsync || sync) do
liftIO (appendEntry fh undefined (NCQEntryNew 0 "")) -- liftIO (appendEntry fh undefined (NCQEntryNew 0 ""))
liftIO (fileSynchronise fh) liftIO (fileSynchronise fh)
atomically do atomically do
writeTVar ncqStorageSyncReq False writeTVar ncqStorageSyncReq False
@ -241,26 +247,26 @@ ncqStorageRun2 ncq@NCQStorage2{..} = flip runContT pure $ callCC \exit -> do
Right chu -> do Right chu -> do
ws <- for chu $ \h -> do ws <- for chu $ \h -> do
atomically (ncqLookupEntrySTM ncq h) >>= \case atomically (ncqLookupEntrySTM ncq h) >>= \case
Nothing -> pure 0 Just (r@(NCQEntryNew n bs),t) -> do
Just (r,t) -> lift (appendEntry fh h r) n <- lift (appendSection fh h bs)
atomically (writeTVar t (NCQEntryJustWritten n fh bs))
pure n
_ -> pure 0
loop (fh, w + sum ws) loop (fh, w + sum ws)
where where
appendEntry :: forall m . MonadUnliftIO m appendSection :: forall m . MonadUnliftIO m
=> Fd => Fd
-> HashRef -> HashRef
-> NCQEntry -> ByteString
-> m Int -> m Int
appendEntry fh h (NCQEntryNew _ bs) = do appendSection fh h section = do
let section = ncqMakeSectionBS Nothing h bs
liftIO (Posix.fdWrite fh section) <&> fromIntegral liftIO (Posix.fdWrite fh section) <&> fromIntegral
appendEntry fh h _ = do {-# INLINE appendSection #-}
pure 0
{-# INLINE appendEntry #-}

View File

@ -626,7 +626,7 @@ testNCQ2Concurrent1 noRead tn n TestEnv{..} = flip runContT pure do
pooledForConcurrentlyN_ tnn fnv $ \(n,ha,_) -> do pooledForConcurrentlyN_ tnn fnv $ \(n,ha,_) -> do
co <- BS.readFile n co <- BS.readFile n
ncqPutBS ncq1 co ncqPutBS ncq1 (Just B) Nothing co
ncqStorageStop2 ncq1 ncqStorageStop2 ncq1
performMajorGC performMajorGC