This commit is contained in:
Dmitry Zuikov 2024-05-31 13:48:08 +03:00
parent 6de1949e56
commit 75e5a1f976
1 changed files with 6 additions and 8 deletions

View File

@ -1,4 +1,5 @@
{-# Language PatternSynonyms #-} {-# Language PatternSynonyms #-}
{-# Language RecordWildCards #-}
module HBS2.Storage.Compact where module HBS2.Storage.Compact where
@ -57,11 +58,11 @@ newtype EntryNum = EntryNum Word32
data IndexEntry = data IndexEntry =
IndexEntry IndexEntry
{ idxEntryOffset :: EntryOffset { idxEntryOffset :: !EntryOffset
, idxEntrySize :: EntrySize , idxEntrySize :: !EntrySize
, idxEntrySeq :: Word64 , idxEntrySeq :: !Word64
, idxEntryTomb :: Bool , idxEntryTomb :: !Bool
, idxEntryKey :: ByteString , idxEntryKey :: !ByteString
} }
deriving stock (Show,Generic) deriving stock (Show,Generic)
@ -86,7 +87,6 @@ data CompactStorage =
CompactStorage CompactStorage
{ csHandle :: MVar Handle { csHandle :: MVar Handle
, csHeaderOff :: IORef EntryOffset , csHeaderOff :: IORef EntryOffset
-- , csSeq :: IORef Integer
, csSeq :: TVar Integer , csSeq :: TVar Integer
, csKeys :: Vector (TVar (HashMap ByteString (Either (IndexEntry,Integer) (ByteString,Integer)))) , csKeys :: Vector (TVar (HashMap ByteString (Either (IndexEntry,Integer) (ByteString,Integer))))
} }
@ -134,7 +134,6 @@ compactStorageOpen _ fp = do
pure $ CompactStorage mha hoff0 ss keys0 pure $ CompactStorage mha hoff0 ss keys0
else do else do
(p,header) <- readHeader mha Nothing >>= maybe (throwIO InvalidHeader) pure (p,header) <- readHeader mha Nothing >>= maybe (throwIO InvalidHeader) pure
traceM (show ("HEADER",header))
hoff <- newIORef p hoff <- newIORef p
let sto = CompactStorage mha hoff ss keys0 let sto = CompactStorage mha hoff ss keys0
readIndex sto (hdrIndexOffset header) (hdrIndexEntries header) readIndex sto (hdrIndexOffset header) (hdrIndexEntries header)
@ -143,7 +142,6 @@ compactStorageOpen _ fp = do
0 -> pure () 0 -> pure ()
off -> do off -> do
(_,pHeader) <- readHeader mha (Just off) >>= maybe (throwIO InvalidHeader) pure (_,pHeader) <- readHeader mha (Just off) >>= maybe (throwIO InvalidHeader) pure
traceM (show ("PHEADER",pHeader))
readIndex sto (hdrIndexOffset pHeader) (hdrIndexEntries pHeader) readIndex sto (hdrIndexOffset pHeader) (hdrIndexEntries pHeader)
next (hdrPrev pHeader) next (hdrPrev pHeader)