wip, log merging, debug-10

This commit is contained in:
Dmitry Zuikov 2023-07-19 12:31:00 +03:00
parent 85987c4902
commit 43139c44ea
1 changed files with 14 additions and 6 deletions

View File

@ -184,9 +184,15 @@ refChanWorker env brains = do
merge <- async (logMergeProcess env mergeQ)
sto <- getStorage
subscribe @e RefChanRequestEventKey $ \(RefChanRequestEvent chan val) -> do
debug $ "RefChanRequestEvent" <+> pretty (AsBase58 chan) <+> pretty val
h <- liftIO $ getRef sto (RefChanLogKey @s chan)
unless ((HashRef <$> h) == Just val) do
refChanAddDownload env chan val $ \href -> do
debug $ "BLOCK DOWNLOADED" <+> pretty href
atomically $ writeTQueue mergeQ (chan, href)
@ -400,7 +406,10 @@ logMergeProcess _ q = do
pause @'Seconds 1
_ <- atomically $ peekTQueue q
logs <- liftIO $ atomically $ flushTQueue q
let byChan = HashMap.fromListWith (<>) [ (x,[y]) | (x,y) <- logs ] & HashMap.toList
let byChan = HashMap.fromListWith (<>) [ (x,[y]) | (x,y) <- logs ]
& HashMap.toList
& fmap (over _2 List.nub)
-- FIXME: in-parallel
mapM_ (logMergeChan menv sto) byChan
@ -424,7 +433,6 @@ logMergeProcess _ q = do
atomically $ modifyTVar (mergeHeads e) (HashMap.insert h headblk)
pure headblk
logMergeChan menv sto (chan, logs) = void $ runMaybeT do
let chanKey = RefChanLogKey @s chan