Skip to content

Commit

Permalink
refactor(journal): use init term id, buffer length and pos bits to sh…
Browse files Browse the repository at this point in the history
…ift from journal type
  • Loading branch information
symbiont-stevan-andjelkovic committed Mar 30, 2022
1 parent 08bb1eb commit 4ced244
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/journal/src/Journal/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ tryClaim jour len = do
let index = indexByTermCount termCount
activePartitionIndex = index
rt <- readRawTail (jMetadata jour) index
initTermId <- readInitialTermId (jMetadata jour)
termLen <- readTermLength (jMetadata jour)
let initTermId = jInitialTermId jour
termLen = jTermLength jour
posBitsToShift = jPositionBitsToShift jour

-- XXX: cache and read these from there?
let termId = rawTailTermId rt
termOffset = rawTailTermOffset rt termLen
termBeginPosition =
computeTermBeginPosition termId (positionBitsToShift termLen) initTermId
termBeginPosition = computeTermBeginPosition termId posBitsToShift initTermId
jLog = logg (jLogger jour)

jLog ("tryClaim, termCount: " ++ show (unTermCount termCount))
Expand Down
14 changes: 7 additions & 7 deletions src/journal/src/Journal/MP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,13 @@ tryClaim jour len = do
let activePartitionIndex = indexByTermCount termCount
termBuffer = jTermBuffers jour Vector.! unPartitionIndex activePartitionIndex
rawTail <- readRawTail (jMetadata jour) activePartitionIndex
initTermId <- readInitialTermId (jMetadata jour)
let termLen = unCapacity (getCapacity termBuffer)
termId = rawTailTermId rawTail
termOffset = rawTailTermOffset rawTail (int2Int32 termLen)
position =
computeTermBeginPosition termId (positionBitsToShift (int2Int32 termLen)) initTermId
+ int322Int64 (unTermOffset termOffset)
let initTermId = jInitialTermId jour
termLen = jTermLength jour
termId = rawTailTermId rawTail
termOffset = rawTailTermOffset rawTail termLen
posBitsToShift = jPositionBitsToShift jour
position = computeTermBeginPosition termId posBitsToShift initTermId
+ int322Int64 (unTermOffset termOffset)

if unTermCount termCount /= unTermId (termId - initTermId)
then return (Left AdminAction) -- XXX: what does this mean to end up here?
Expand Down

0 comments on commit 4ced244

Please sign in to comment.