@@ -87,7 +87,6 @@ import Data.Kind
8787import Data.Map.Strict (Map )
8888import qualified Data.Map.Strict as Map
8989import Data.Maybe (catMaybes )
90- import qualified Data.Primitive.ByteArray as P
9190import qualified Data.Set as Set
9291import Data.Typeable
9392import qualified Data.Vector as V
@@ -104,7 +103,6 @@ import Database.LSMTree.Internal.Paths (SessionRoot (..),
104103 SnapshotName )
105104import qualified Database.LSMTree.Internal.Paths as Paths
106105import Database.LSMTree.Internal.Range (Range (.. ))
107- import qualified Database.LSMTree.Internal.RawBytes as RB
108106import Database.LSMTree.Internal.Run (Run )
109107import qualified Database.LSMTree.Internal.Run as Run
110108import Database.LSMTree.Internal.RunReaders (OffsetKey (.. ))
@@ -116,8 +114,7 @@ import Database.LSMTree.Internal.UniqCounter
116114import qualified Database.LSMTree.Internal.WriteBuffer as WB
117115import qualified Database.LSMTree.Internal.WriteBufferBlobs as WBB
118116import qualified System.FS.API as FS
119- import System.FS.API (FsError , FsErrorPath (.. ), FsPath , Handle ,
120- HasFS )
117+ import System.FS.API (FsError , FsErrorPath (.. ), FsPath , HasFS )
121118import qualified System.FS.API.Lazy as FS
122119import qualified System.FS.BlockIO.API as FS
123120import System.FS.BlockIO.API (HasBlockIO )
@@ -724,14 +721,14 @@ close t = do
724721 ResolveSerialisedValue
725722 -> V.Vector SerialisedKey
726723 -> Table IO h
727- -> IO (V.Vector (Maybe (Entry SerialisedValue (WeakBlobRef IO (Handle h) )))) #-}
724+ -> IO (V.Vector (Maybe (Entry SerialisedValue (WeakBlobRef IO h )))) #-}
728725-- | See 'Database.LSMTree.Normal.lookups'.
729726lookups ::
730727 (MonadST m , MonadSTM m , MonadThrow m )
731728 => ResolveSerialisedValue
732729 -> V. Vector SerialisedKey
733730 -> Table m h
734- -> m (V. Vector (Maybe (Entry SerialisedValue (WeakBlobRef m ( Handle h ) ))))
731+ -> m (V. Vector (Maybe (Entry SerialisedValue (WeakBlobRef m h ))))
735732lookups resolve ks t = do
736733 traceWith (tableTracer t) $ TraceLookups (V. length ks)
737734 withOpenTable t $ \ thEnv ->
@@ -753,15 +750,15 @@ lookups resolve ks t = do
753750 ResolveSerialisedValue
754751 -> Range SerialisedKey
755752 -> Table IO h
756- -> (SerialisedKey -> SerialisedValue -> Maybe (WeakBlobRef IO (Handle h) ) -> res)
753+ -> (SerialisedKey -> SerialisedValue -> Maybe (WeakBlobRef IO h ) -> res)
757754 -> IO (V.Vector res) #-}
758755-- | See 'Database.LSMTree.Normal.rangeLookup'.
759756rangeLookup ::
760757 (MonadFix m , MonadMask m , MonadMVar m , MonadST m , MonadSTM m )
761758 => ResolveSerialisedValue
762759 -> Range SerialisedKey
763760 -> Table m h
764- -> (SerialisedKey -> SerialisedValue -> Maybe (WeakBlobRef m ( Handle h ) ) -> res )
761+ -> (SerialisedKey -> SerialisedValue -> Maybe (WeakBlobRef m h ) -> res )
765762 -- ^ How to map to a query result, different for normal/monoidal
766763 -> m (V. Vector res )
767764rangeLookup resolve range t fromEntry = do
@@ -828,44 +825,19 @@ updates resolve es t = do
828825
829826{-# SPECIALISE retrieveBlobs ::
830827 Session IO h
831- -> V.Vector (WeakBlobRef IO (FS.Handle h) )
828+ -> V.Vector (WeakBlobRef IO h )
832829 -> IO (V.Vector SerialisedBlob) #-}
833830retrieveBlobs ::
834- (MonadFix m , MonadMask m , MonadST m , MonadSTM m )
831+ (MonadMask m , MonadST m , MonadSTM m )
835832 => Session m h
836- -> V. Vector (WeakBlobRef m ( FS. Handle h ) )
833+ -> V. Vector (WeakBlobRef m h )
837834 -> m (V. Vector SerialisedBlob )
838835retrieveBlobs sesh wrefs =
839836 withOpenSession sesh $ \ seshEnv ->
840- handle (\ (BlobRef. WeakBlobRefInvalid i) -> throwIO (ErrBlobRefInvalid i)) $
841- BlobRef. withWeakBlobRefs wrefs $ \ refs -> do
842-
843- -- Prepare the IOOps:
844- -- We use a single large memory buffer, with appropriate offsets within
845- -- the buffer.
846- let bufSize :: Int
847- ! bufSize = V. sum (V. map BlobRef. blobRefSpanSize refs)
848-
849- {-# INLINE bufOffs #-}
850- bufOffs :: V. Vector Int
851- bufOffs = V. scanl (+) 0 (V. map BlobRef. blobRefSpanSize refs)
852- buf <- P. newPinnedByteArray bufSize
853- let ioops = V. zipWith (BlobRef. readBlobIOOp buf) bufOffs refs
854- hbio = sessionHasBlockIO seshEnv
855-
856- -- Submit the IOOps all in one go:
857- _ <- FS. submitIO hbio ioops
858- -- We do not need to inspect the results because IO errors are
859- -- thrown as exceptions, and the result is just the read length
860- -- which is already known. Short reads can't happen here.
861-
862- -- Construct the SerialisedBlobs results:
863- -- This is just the different offsets within the shared buffer.
864- ba <- P. unsafeFreezeByteArray buf
865- pure $! V. zipWith
866- (\ off len -> SerialisedBlob (RB. fromByteArray off len ba))
867- bufOffs
868- (V. map BlobRef. blobRefSpanSize refs)
837+ let hbio = sessionHasBlockIO seshEnv in
838+ handle (\ (BlobRef. WeakBlobRefInvalid i) ->
839+ throwIO (ErrBlobRefInvalid i)) $
840+ BlobRef. readWeakBlobRefs hbio wrefs
869841
870842{- ------------------------------------------------------------------------------
871843 Cursors
@@ -1023,7 +995,7 @@ closeCursor Cursor {..} = do
1023995 ResolveSerialisedValue
1024996 -> Int
1025997 -> Cursor IO h
1026- -> (SerialisedKey -> SerialisedValue -> Maybe (WeakBlobRef IO (Handle h) ) -> res)
998+ -> (SerialisedKey -> SerialisedValue -> Maybe (WeakBlobRef IO h ) -> res)
1027999 -> IO (V.Vector res) #-}
10281000-- | See 'Database.LSMTree.Normal.readCursor'.
10291001readCursor ::
@@ -1032,7 +1004,7 @@ readCursor ::
10321004 => ResolveSerialisedValue
10331005 -> Int -- ^ Maximum number of entries to read
10341006 -> Cursor m h
1035- -> (SerialisedKey -> SerialisedValue -> Maybe (WeakBlobRef m ( Handle h ) ) -> res )
1007+ -> (SerialisedKey -> SerialisedValue -> Maybe (WeakBlobRef m h ) -> res )
10361008 -- ^ How to map to a query result, different for normal/monoidal
10371009 -> m (V. Vector res )
10381010readCursor resolve n cursor fromEntry =
@@ -1043,7 +1015,7 @@ readCursor resolve n cursor fromEntry =
10431015 -> (SerialisedKey -> Bool)
10441016 -> Int
10451017 -> Cursor IO h
1046- -> (SerialisedKey -> SerialisedValue -> Maybe (WeakBlobRef IO (Handle h) ) -> res)
1018+ -> (SerialisedKey -> SerialisedValue -> Maybe (WeakBlobRef IO h ) -> res)
10471019 -> IO (V.Vector res) #-}
10481020-- | @readCursorWhile _ p n cursor _@ reads elements until either:
10491021--
@@ -1060,7 +1032,7 @@ readCursorWhile ::
10601032 -> (SerialisedKey -> Bool ) -- ^ Only read as long as this predicate holds
10611033 -> Int -- ^ Maximum number of entries to read
10621034 -> Cursor m h
1063- -> (SerialisedKey -> SerialisedValue -> Maybe (WeakBlobRef m ( Handle h ) ) -> res )
1035+ -> (SerialisedKey -> SerialisedValue -> Maybe (WeakBlobRef m h ) -> res )
10641036 -- ^ How to map to a query result, different for normal/monoidal
10651037 -> m (V. Vector res )
10661038readCursorWhile resolve keyIsWanted n Cursor {.. } fromEntry = do
0 commit comments