mirror of https://github.com/voidlizard/hbs2
wip, ncq2 new writer
This commit is contained in:
parent
91a0af9ee3
commit
a1e6ff50f9
|
@ -234,17 +234,25 @@ data RunSt =
|
||||||
RunNew
|
RunNew
|
||||||
| RunWrite (FileKey, Fd, Int, Int)
|
| RunWrite (FileKey, Fd, Int, Int)
|
||||||
| RunSync (FileKey, Fd, Int, Int, Bool)
|
| RunSync (FileKey, Fd, Int, Int, Bool)
|
||||||
|
| RunFin
|
||||||
|
|
||||||
ncqStorageRun2 :: forall m . MonadUnliftIO m
|
ncqStorageRun2 :: forall m . MonadUnliftIO m
|
||||||
=> NCQStorage2
|
=> NCQStorage2
|
||||||
-> m ()
|
-> m ()
|
||||||
ncqStorageRun2 ncq@NCQStorage2{..} = flip runContT pure $ callCC \exit -> do
|
ncqStorageRun2 ncq@NCQStorage2{..} = flip runContT pure do
|
||||||
|
|
||||||
jobQ <- newTQueueIO
|
jobQ <- newTQueueIO
|
||||||
closeQ <- newTQueueIO
|
closeQ <- newTQueueIO
|
||||||
|
|
||||||
closer <- ContT $ withAsync $ liftIO $ forever do
|
closer <- ContT $ withAsync $ liftIO $ fix \loop -> do
|
||||||
atomically (readTQueue closeQ) >>= \(fk, fh) -> do
|
what <- atomically do
|
||||||
|
stop <- readTVar ncqStorageStopReq
|
||||||
|
tryReadTQueue closeQ >>= \case
|
||||||
|
Just e -> pure $ Just e
|
||||||
|
Nothing | not stop -> STM.retry
|
||||||
|
| otherwise -> pure Nothing
|
||||||
|
|
||||||
|
maybe1 what none $ \(fk, fh) -> do
|
||||||
closeFd fh
|
closeFd fh
|
||||||
let fname = BS8.unpack (coerce fk)
|
let fname = BS8.unpack (coerce fk)
|
||||||
-- notice $ yellow "indexing" <+> pretty fname
|
-- notice $ yellow "indexing" <+> pretty fname
|
||||||
|
@ -253,10 +261,9 @@ ncqStorageRun2 ncq@NCQStorage2{..} = flip runContT pure $ callCC \exit -> do
|
||||||
Nothing -> err $ "can't open index" <+> pretty idx
|
Nothing -> err $ "can't open index" <+> pretty idx
|
||||||
Just (bs,nway) -> do
|
Just (bs,nway) -> do
|
||||||
nwayHashScanAll nway bs $ \_ k _ -> do
|
nwayHashScanAll nway bs $ \_ k _ -> do
|
||||||
unless (k == emptyKey) do
|
unless (k == emptyKey) $ atomically do
|
||||||
none
|
|
||||||
atomically do
|
|
||||||
ncqAlterEntrySTM ncq (coerce k) (const Nothing)
|
ncqAlterEntrySTM ncq (coerce k) (const Nothing)
|
||||||
|
loop
|
||||||
|
|
||||||
link closer
|
link closer
|
||||||
|
|
||||||
|
@ -269,20 +276,26 @@ ncqStorageRun2 ncq@NCQStorage2{..} = flip runContT pure $ callCC \exit -> do
|
||||||
|
|
||||||
flip fix RunNew $ \loop -> \case
|
flip fix RunNew $ \loop -> \case
|
||||||
|
|
||||||
|
RunFin -> do
|
||||||
|
debug "wait finalizing"
|
||||||
|
atomically $ pollSTM closer >>= maybe STM.retry (const none)
|
||||||
|
debug "exit storage"
|
||||||
|
|
||||||
RunNew -> do
|
RunNew -> do
|
||||||
stop <- readTVarIO ncqStorageStopReq
|
stop <- readTVarIO ncqStorageStopReq
|
||||||
mt <- readTVarIO ncqWriteQ <&> Seq.null
|
mt <- readTVarIO ncqWriteQ <&> Seq.null
|
||||||
|
|
||||||
when (stop && mt) do
|
if stop && mt then do
|
||||||
exit ()
|
loop RunFin
|
||||||
|
else do
|
||||||
(fk,fhx) <- openNewDataFile
|
(fk,fhx) <- openNewDataFile
|
||||||
loop $ RunWrite (fk,fhx,0,0)
|
loop $ RunWrite (fk,fhx,0,0)
|
||||||
|
|
||||||
RunSync (fk, fh, w, total, continue) -> do
|
RunSync (fk, fh, w, total, continue) -> do
|
||||||
|
|
||||||
|
stop <- readTVarIO ncqStorageStopReq
|
||||||
sync <- readTVarIO ncqStorageSyncReq
|
sync <- readTVarIO ncqStorageSyncReq
|
||||||
let needClose = total >= ncqMinLog
|
let needClose = total >= ncqMinLog || stop
|
||||||
|
|
||||||
rest <- if not (sync || needClose || w > ncqFsync) then
|
rest <- if not (sync || needClose || w > ncqFsync) then
|
||||||
pure w
|
pure w
|
||||||
|
@ -299,7 +312,7 @@ ncqStorageRun2 ncq@NCQStorage2{..} = flip runContT pure $ callCC \exit -> do
|
||||||
atomically $ writeTQueue closeQ (fk, fh)
|
atomically $ writeTQueue closeQ (fk, fh)
|
||||||
loop RunNew
|
loop RunNew
|
||||||
|
|
||||||
| not continue -> exit ()
|
| not continue -> loop RunFin
|
||||||
|
|
||||||
| otherwise -> loop $ RunWrite (fk, fh, rest, total)
|
| otherwise -> loop $ RunWrite (fk, fh, rest, total)
|
||||||
|
|
||||||
|
|
|
@ -130,9 +130,11 @@ runTest action = do
|
||||||
flip runContT pure do
|
flip runContT pure do
|
||||||
ContT $ bracket none $ const do
|
ContT $ bracket none $ const do
|
||||||
unless keep (rm tmp)
|
unless keep (rm tmp)
|
||||||
|
flushLoggers
|
||||||
|
|
||||||
lift $ lift $ action (TestEnv tmp)
|
lift $ lift $ action (TestEnv tmp)
|
||||||
|
|
||||||
|
|
||||||
testNCQFuckupRecovery1 :: MonadUnliftIO m
|
testNCQFuckupRecovery1 :: MonadUnliftIO m
|
||||||
=> TestEnv
|
=> TestEnv
|
||||||
-> m ()
|
-> m ()
|
||||||
|
@ -680,6 +682,7 @@ testNCQ2ConcurrentWriteSimple1 tn n TestEnv{..} = flip runContT pure do
|
||||||
ncqPutBS ncq1 (Just B) Nothing co
|
ncqPutBS ncq1 (Just B) Nothing co
|
||||||
|
|
||||||
liftIO $ ncqStorageStop2 ncq1
|
liftIO $ ncqStorageStop2 ncq1
|
||||||
|
wait w
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
|
|
Loading…
Reference in New Issue