Skip to content

Commit

Permalink
feat(journal): try to make clean up thread-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-stevan-andjelkovic committed Mar 1, 2022
1 parent 59e143d commit dcc4140
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/journal/src/Journal/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ calculatePositionLimit jour = do
maxSubscriberPos <- readCounter (jBytesConsumed jour)
termWindowLen <- termWindowLength (jMetadata jour)
let _consumerPos = maxSubscriberPos
proposedLimit = minSubscriberPos + fromIntegral termWindowLen
proposedLimit = minSubscriberPos + int322Int termWindowLen

cleanBufferTo jour minSubscriberPos
return (int2Int64 proposedLimit)
where
Expand All @@ -110,7 +111,9 @@ cleanBufferTo jour position = do
len = min bytesForCleaning (bufferCapacity - termOffset)
cleanAt dirtyTerm (termOffset + sizeOf (8 :: Int64)) (len - sizeOf (8 :: Int64))
writeInt64OffAddr dirtyTerm termOffset 0
incrCounter_ len (jCleanPosition jour)
-- incrCounter_ len (jCleanPosition jour)
_success <- casCounter (jCleanPosition jour) cleanPosition (cleanPosition + len)
return ()

backPressureStatus :: Int64 -> Int -> Logger -> IO (Either AppendError (Int64, BufferClaim))
backPressureStatus position len logger = do
Expand Down Expand Up @@ -283,11 +286,12 @@ dumpTermBuffer i (bb, termOffset) = do
| offset > termOffset = __IMPOSSIBLE__
| offset < termOffset = do
h <- readHeader offset
dumpHeader h
dumpBody offset (bodyLength h)
dumpEntries (offset +
TermOffset (int2Int32 (align (hEADER_LENGTH + bodyLength h)
fRAME_ALIGNMENT)))
when (bodyLength h /= 0) $ do
dumpHeader h
dumpBody offset (bodyLength h)
dumpEntries (offset +
TermOffset (int2Int32 (align (hEADER_LENGTH + bodyLength h)
fRAME_ALIGNMENT)))

readHeader :: TermOffset -> IO (HeaderTag, HeaderLength)
readHeader offset = (,) <$> readFrameType bb offset <*> readFrameLength bb offset
Expand Down

0 comments on commit dcc4140

Please sign in to comment.