Skip to content

Commit d4959e7

Browse files
amesgenjasagredo
authored andcommitted
Reimplement #1265 using modifyMVar
1 parent f4d877b commit d4959e7

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Patch
2+
3+
- Replace `bracketOnError` with `modifyMVar` in the Cached Index implementation.

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/ImmutableDB/Impl/Index/Cache.hs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -574,26 +574,23 @@ getChunkInfo ::
574574
getChunkInfo cacheEnv chunk = do
575575
lastUsed <- LastUsed <$> getMonotonicTime
576576
-- Make sure we don't leave an empty MVar in case of an exception.
577-
mbCacheHit <- bracketOnError (takeMVar cacheVar) (tryPutMVar cacheVar) $
577+
mbCacheHit <- modifyMVar cacheVar $
578578
\cached@Cached { currentChunk, currentChunkInfo, nbPastChunks } -> if
579579
| chunk == currentChunk -> do
580580
-- Cache hit for the current chunk
581-
putMVar cacheVar cached
582581
traceWith tracer $ TraceCurrentChunkHit chunk nbPastChunks
583-
return $ Just $ Left currentChunkInfo
582+
return (cached, Just $ Left currentChunkInfo)
584583
| Just (pastChunkInfo, cached') <- lookupPastChunkInfo chunk lastUsed cached -> do
585584
-- Cache hit for an chunk in the past
586-
putMVar cacheVar cached'
587585
traceWith tracer $ TracePastChunkHit chunk nbPastChunks
588-
return $ Just $ Right pastChunkInfo
586+
return (cached', Just $ Right pastChunkInfo)
589587
| otherwise -> do
590588
-- Cache miss for an chunk in the past. We don't want to hold on to
591589
-- the 'cacheVar' MVar, blocking all other access to the cace, while
592590
-- we're reading things from disk, so put it back now and update the
593591
-- cache afterwards.
594-
putMVar cacheVar cached
595592
traceWith tracer $ TracePastChunkMiss chunk nbPastChunks
596-
return Nothing
593+
return (cached, Nothing)
597594
case mbCacheHit of
598595
Just hit -> return hit
599596
Nothing -> do

0 commit comments

Comments
 (0)