From 4ced2446df05ce5bd87e6a23f26559d667f29fb0 Mon Sep 17 00:00:00 2001 From: Stevan Andjelkovic Date: Wed, 30 Mar 2022 14:50:03 +0200 Subject: [PATCH] refactor(journal): use init term id, buffer length and pos bits to shift from journal type --- src/journal/src/Journal/Internal.hs | 8 ++++---- src/journal/src/Journal/MP.hs | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/journal/src/Journal/Internal.hs b/src/journal/src/Journal/Internal.hs index bdf4f2d7..6108f74e 100644 --- a/src/journal/src/Journal/Internal.hs +++ b/src/journal/src/Journal/Internal.hs @@ -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)) diff --git a/src/journal/src/Journal/MP.hs b/src/journal/src/Journal/MP.hs index e029a4a1..cfd76d59 100644 --- a/src/journal/src/Journal/MP.hs +++ b/src/journal/src/Journal/MP.hs @@ -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?