1+ {-# LANGUAGE CPP #-}
2+
13{- HLINT ignore "Avoid restricted alias" -}
24
35{-|
@@ -31,7 +33,7 @@ import Database.LSMTree.Internal.Serialise
3133import Database.LSMTree.Internal.Vector (byteVectorFromPrim )
3234import Database.LSMTree.Internal.Vector.Growing (GrowingVector )
3335import qualified Database.LSMTree.Internal.Vector.Growing as Growing (append ,
34- freeze , new )
36+ freeze , new , readMaybeLast )
3537
3638{-|
3739 A general-purpose fence pointer index under incremental construction.
@@ -80,10 +82,15 @@ keyListElem (SerialisedKey' keyBytes) = [keySizeBytes, keyBytes] where
8082appendSingle :: (SerialisedKey , SerialisedKey )
8183 -> IndexOrdinaryAcc s
8284 -> ST s (Maybe Chunk )
83- appendSingle (_, key) (IndexOrdinaryAcc lastKeys baler)
84- = do
85- Growing. append lastKeys 1 key
86- feedBaler (keyListElem key) baler
85+ appendSingle (firstKey, lastKey) (IndexOrdinaryAcc lastKeys baler)
86+ = assert (firstKey <= lastKey) $
87+ do
88+ #ifdef NO_IGNORE_ASSERTS
89+ maybeLastLastKey <- Growing. readMaybeLast lastKeys
90+ assert (all (< firstKey) maybeLastLastKey) $ return ()
91+ #endif
92+ Growing. append lastKeys 1 lastKey
93+ feedBaler (keyListElem lastKey) baler
8794
8895{-|
8996 For a specification of this operation, see the documentation of [its
@@ -94,6 +101,10 @@ appendMulti :: (SerialisedKey, Word32)
94101 -> ST s [Chunk ]
95102appendMulti (key, overflowPageCount) (IndexOrdinaryAcc lastKeys baler)
96103 = do
104+ #ifdef NO_IGNORE_ASSERTS
105+ maybeLastLastKey <- Growing. readMaybeLast lastKeys
106+ assert (all (< key) maybeLastLastKey) $ return ()
107+ #endif
97108 Growing. append lastKeys pageCount key
98109 maybeToList <$> feedBaler keyListElems baler
99110 where
0 commit comments