mirror of https://github.com/voidlizard/hbs2
file corruption during concurrent writes
This commit is contained in:
parent
6133c1cb2f
commit
5197c2fa2b
|
@ -301,7 +301,7 @@ runPeerM s bus p f = do
|
||||||
<*> liftIO (newTVarIO mempty)
|
<*> liftIO (newTVarIO mempty)
|
||||||
|
|
||||||
let de = view envDeferred env
|
let de = view envDeferred env
|
||||||
as <- liftIO $ replicateM 8 $ async $ runPipeline de
|
as <- liftIO $ replicateM 4 $ async $ runPipeline de
|
||||||
|
|
||||||
sw <- liftIO $ async $ forever $ withPeerM env $ do
|
sw <- liftIO $ async $ forever $ withPeerM env $ do
|
||||||
pause defSweepTimeout
|
pause defSweepTimeout
|
||||||
|
|
|
@ -8,16 +8,16 @@ defChunkSize :: Integral a => a
|
||||||
defChunkSize = 500
|
defChunkSize = 500
|
||||||
|
|
||||||
defBlockSize :: Integer
|
defBlockSize :: Integer
|
||||||
defBlockSize = 1024 * 1024
|
defBlockSize = 256 * 1024
|
||||||
|
|
||||||
defStorePath :: IsString a => a
|
defStorePath :: IsString a => a
|
||||||
defStorePath = "hbs2"
|
defStorePath = "hbs2"
|
||||||
|
|
||||||
defPipelineSize :: Int
|
defPipelineSize :: Int
|
||||||
defPipelineSize = 2000
|
defPipelineSize = 16000*4
|
||||||
|
|
||||||
defChunkWriterQ :: Integral a => a
|
defChunkWriterQ :: Integral a => a
|
||||||
defChunkWriterQ = 2000
|
defChunkWriterQ = 32000
|
||||||
|
|
||||||
defBlockDownloadQ :: Integral a => a
|
defBlockDownloadQ :: Integral a => a
|
||||||
defBlockDownloadQ = 65536*128
|
defBlockDownloadQ = 65536*128
|
||||||
|
|
|
@ -159,7 +159,7 @@ runTestPeer p zu = do
|
||||||
cww <- newChunkWriterIO stor (Just chDir)
|
cww <- newChunkWriterIO stor (Just chDir)
|
||||||
|
|
||||||
sw <- liftIO $ replicateM 4 $ async $ simpleStorageWorker stor
|
sw <- liftIO $ replicateM 4 $ async $ simpleStorageWorker stor
|
||||||
cw <- liftIO $ replicateM 8 $ async $ runChunkWriter cww
|
cw <- liftIO $ replicateM 4 $ async $ runChunkWriter cww
|
||||||
|
|
||||||
zu stor cww
|
zu stor cww
|
||||||
|
|
||||||
|
@ -295,6 +295,7 @@ blockDownloadLoop cw = do
|
||||||
let blks = [ "GTtQp6QjK7G9Sh5Aq4koGSpMX398WRWn3DV28NUAYARg"
|
let blks = [ "GTtQp6QjK7G9Sh5Aq4koGSpMX398WRWn3DV28NUAYARg"
|
||||||
, "5LoU2EVq7JSpiT9FmLEakVHxpsE989XnX6jE4gaUcLFA"
|
, "5LoU2EVq7JSpiT9FmLEakVHxpsE989XnX6jE4gaUcLFA"
|
||||||
, "CotHSTLrg8T5NrYxyhG1AeJrdz1s4A5PdtA95Fh96JX8"
|
, "CotHSTLrg8T5NrYxyhG1AeJrdz1s4A5PdtA95Fh96JX8"
|
||||||
|
, "ANHxB2dUcSFDB7W7JuuqkSjAUXWyekVKdQLqNBhFKGgj"
|
||||||
]
|
]
|
||||||
|
|
||||||
blq <- liftIO $ Q.newTBQueueIO defBlockDownloadQ
|
blq <- liftIO $ Q.newTBQueueIO defBlockDownloadQ
|
||||||
|
@ -382,24 +383,28 @@ blockDownloadLoop cw = do
|
||||||
subscribe @e (BlockChunksEventKey h) $ \(BlockReady _) -> do
|
subscribe @e (BlockChunksEventKey h) $ \(BlockReady _) -> do
|
||||||
processBlock q h
|
processBlock q h
|
||||||
|
|
||||||
-- liftIO $ async $ do
|
let blockWtf = do
|
||||||
-- void $ race (pause defBlockWaitMax) $ withPeerM env $ fix \next -> do
|
debug $ "WTF!" <+> pretty (p,coo) <+> pretty h
|
||||||
-- pause defBlockWaitSleep
|
|
||||||
-- wl <- find key (view sBlockWrittenL)
|
|
||||||
|
|
||||||
-- let w = sum (fromMaybe [] wl)
|
|
||||||
|
|
||||||
-- debug $ "WTF?" <+> pretty (w, thisBkSize)
|
|
||||||
|
|
||||||
-- -- maybe1 w (pure ()) $ \z -> do
|
|
||||||
-- if fromIntegral w >= thisBkSize then do
|
|
||||||
-- debug "THE BLOCK IS ABOUT TO BE READY"
|
|
||||||
-- -- write to disk and so on
|
|
||||||
-- else do
|
|
||||||
-- pause defBlockWaitSleep
|
|
||||||
-- next
|
|
||||||
|
|
||||||
|
liftIO $ async $ do
|
||||||
-- FIXME: block is not downloaded, return it to the Q
|
-- FIXME: block is not downloaded, return it to the Q
|
||||||
|
void $ race (pause defBlockWaitMax >> blockWtf)
|
||||||
|
$ withPeerM env $ fix \next -> do
|
||||||
|
w <- find @e key (view sBlockWrittenT)
|
||||||
|
|
||||||
|
maybe1 w (pure ()) $ \z -> do
|
||||||
|
wrt <- liftIO $ readTVarIO z
|
||||||
|
|
||||||
|
if fromIntegral wrt >= thisBkSize then do
|
||||||
|
debug $ "THE BLOCK IS ABOUT TO BE READY" <+> pretty h
|
||||||
|
h1 <- liftIO $ getHash cw key h
|
||||||
|
if h1 == h then do
|
||||||
|
liftIO $ commitBlock cw key h
|
||||||
|
expire @e key
|
||||||
|
else pause defBlockWaitSleep >> next
|
||||||
|
else do
|
||||||
|
pause defBlockWaitSleep
|
||||||
|
next
|
||||||
|
|
||||||
request @e p (BlockChunks @e coo (BlockGetAllChunks @e h chusz)) -- FIXME: nicer construction
|
request @e p (BlockChunks @e coo (BlockGetAllChunks @e h chusz)) -- FIXME: nicer construction
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue