1+ {-# LANGUAGE CPP #-}
2+
13{- HLINT ignore "Avoid restricted alias" -}
24
35{-|
@@ -32,6 +34,10 @@ import Database.LSMTree.Internal.Vector (byteVectorFromPrim)
3234import Database.LSMTree.Internal.Vector.Growing (GrowingVector )
3335import qualified Database.LSMTree.Internal.Vector.Growing as Growing (append ,
3436 freeze , new )
37+ #ifdef NO_IGNORE_ASSERTS
38+ import qualified Database.LSMTree.Internal.Vector.Growing as Growing
39+ (readMaybeLast )
40+ #endif
3541
3642{-|
3743 A general-purpose fence pointer index under incremental construction.
@@ -80,10 +86,15 @@ keyListElem (SerialisedKey' keyBytes) = [keySizeBytes, keyBytes] where
8086appendSingle :: (SerialisedKey , SerialisedKey )
8187 -> IndexOrdinaryAcc s
8288 -> ST s (Maybe Chunk )
83- appendSingle (_, key) (IndexOrdinaryAcc lastKeys baler)
84- = do
85- Growing. append lastKeys 1 key
86- feedBaler (keyListElem key) baler
89+ appendSingle (firstKey, lastKey) (IndexOrdinaryAcc lastKeys baler)
90+ = assert (firstKey <= lastKey) $
91+ do
92+ #ifdef NO_IGNORE_ASSERTS
93+ maybeLastLastKey <- Growing. readMaybeLast lastKeys
94+ assert (all (< firstKey) maybeLastLastKey) $ return ()
95+ #endif
96+ Growing. append lastKeys 1 lastKey
97+ feedBaler (keyListElem lastKey) baler
8798
8899{-|
89100 For a specification of this operation, see the documentation of [its
@@ -94,6 +105,10 @@ appendMulti :: (SerialisedKey, Word32)
94105 -> ST s [Chunk ]
95106appendMulti (key, overflowPageCount) (IndexOrdinaryAcc lastKeys baler)
96107 = do
108+ #ifdef NO_IGNORE_ASSERTS
109+ maybeLastLastKey <- Growing. readMaybeLast lastKeys
110+ assert (all (< key) maybeLastLastKey) $ return ()
111+ #endif
97112 Growing. append lastKeys pageCount key
98113 maybeToList <$> feedBaler keyListElems baler
99114 where
0 commit comments