cache sweeping

This commit is contained in:
Dmitry Zuikov 2023-02-28 05:54:53 +03:00
parent 264282e6b1
commit 917f25ded3
2 changed files with 10 additions and 9 deletions

View File

@ -586,12 +586,17 @@ postponedLoop env0 = do
void $ liftIO $ async $ withPeerM e $ withDownload env0 do
po <- asks (view peerPostponed)
ban <- asks (view blockBanned)
stored <- asks (view blockStored)
forever do
-- FIXME: del-posponed-time-hardcode
pause @'Seconds 60
debug "postponedLoop"
liftIO $ Cache.purgeExpired ban
liftIO $ Cache.purgeExpired stored
back <- liftIO $ atomically $ stateTVar po $ \hm ->
let els = HashMap.toList hm in
-- FIXME: back-from-postponed-size-var
@ -671,12 +676,16 @@ peerDownloadLoop peer = do
forever do
liftIO do
Cache.purgeExpired sizeCache
Cache.purgeExpired noBlock
auth' <- lift $ find (KnownPeerKey peer) id
pinfo' <- lift $ find (PeerInfoKey peer) id -- (view peerDownloadFail)
let mbauth = (,) <$> auth' <*> pinfo'
let noAuth = warn ( "lost peer auth" <+> pretty peer) >> pause @'Seconds 5
let noAuth = warn ( "lost peer auth" <+> pretty peer) >> pause @'Seconds 1
maybe1 mbauth noAuth $ \(_,pinfo) -> do

View File

@ -235,14 +235,6 @@ incBlockSizeReqCount h = do
writeTVar (view bsLastSeen blk) now
modifyTVar (view bsReqSizeTimes blk) succ
-- FIXME: что-то более обоснованно
calcWaitTime :: MonadIO m => BlockDownloadM e m Double
calcWaitTime = do
wip <- asks (view blockWip) >>= liftIO . Cache.size
let wipn = realToFrac wip * 3
let waiting = 5 + ( (realToFrac (toNanoSeconds defBlockWaitMax) * wipn) / 1e9 )
pure waiting
isBlockHereCached :: forall e m . ( MyPeer e
, MonadIO m
, HasStorage m