|
4 | 4 | {- HLINT ignore "Use unless" -} |
5 | 5 |
|
6 | 6 | module Database.LSMTree.Internal.BlobRef ( |
7 | | - RawBlobRef (..) |
8 | | - , BlobSpan (..) |
9 | | - , blobRefSpanSize |
| 7 | + BlobSpan (..) |
| 8 | + , RawBlobRef (..) |
10 | 9 | , WeakBlobRef (..) |
11 | | - , withWeakBlobRef |
12 | | - , withWeakBlobRefs |
13 | | - , deRefWeakBlobRef |
14 | | - , deRefWeakBlobRefs |
15 | 10 | , WeakBlobRefInvalid (..) |
16 | 11 | , rawToWeakBlobRef |
17 | | - , removeReference |
18 | | - , removeReferences |
19 | 12 | , readRawBlobRef |
20 | 13 | , readWeakBlobRef |
21 | 14 | , readWeakBlobRefs |
22 | 15 | ) where |
23 | 16 |
|
24 | | -import Control.DeepSeq (NFData (..)) |
25 | 17 | import Control.Monad (when) |
26 | 18 | import Control.Monad.Class.MonadThrow (Exception, MonadMask, |
27 | 19 | MonadThrow (..), bracket, throwIO) |
@@ -56,12 +48,6 @@ data RawBlobRef m h = RawBlobRef { |
56 | 48 | } |
57 | 49 | deriving stock (Show) |
58 | 50 |
|
59 | | -instance NFData h => NFData (RawBlobRef m h) where |
60 | | - rnf (RawBlobRef a b) = rnf a `seq` rnf b |
61 | | - |
62 | | -blobRefSpanSize :: StrongBlobRef m h -> Int |
63 | | -blobRefSpanSize = fromIntegral . blobSpanSize . strongBlobRefSpan |
64 | | - |
65 | 51 | -- | A \"weak\" reference to a blob within a blob file. These are the ones we |
66 | 52 | -- can return in the public API and can outlive their parent table. |
67 | 53 | -- |
@@ -105,37 +91,6 @@ newtype WeakBlobRefInvalid = WeakBlobRefInvalid Int |
105 | 91 | deriving stock (Show) |
106 | 92 | deriving anyclass (Exception) |
107 | 93 |
|
108 | | -{-# SPECIALISE withWeakBlobRef :: |
109 | | - WeakBlobRef IO h |
110 | | - -> (StrongBlobRef IO h -> IO a) |
111 | | - -> IO a #-} |
112 | | --- | 'WeakBlobRef's are weak references. They do not keep the blob file open. |
113 | | --- Dereference a 'WeakBlobRef' to a strong 'BlobRef' to allow I\/O using |
114 | | --- 'readBlob' or 'readBlobIOOp'. Use 'removeReference' when the 'BlobRef' is |
115 | | --- no longer needed. |
116 | | --- |
117 | | --- Throws 'WeakBlobRefInvalid' if the weak reference has become invalid. |
118 | | --- |
119 | | -withWeakBlobRef :: |
120 | | - (MonadMask m, PrimMonad m) |
121 | | - => WeakBlobRef m h |
122 | | - -> (StrongBlobRef m h -> m a) |
123 | | - -> m a |
124 | | -withWeakBlobRef wref = bracket (deRefWeakBlobRef wref) removeReference |
125 | | - |
126 | | -{-# SPECIALISE withWeakBlobRefs :: |
127 | | - V.Vector (WeakBlobRef IO h) |
128 | | - -> (V.Vector (StrongBlobRef IO h) -> IO a) |
129 | | - -> IO a #-} |
130 | | --- | The same as 'withWeakBlobRef' but for many references in one go. |
131 | | --- |
132 | | -withWeakBlobRefs :: |
133 | | - (MonadMask m, PrimMonad m) |
134 | | - => V.Vector (WeakBlobRef m h) |
135 | | - -> (V.Vector (StrongBlobRef m h) -> m a) |
136 | | - -> m a |
137 | | -withWeakBlobRefs wrefs = bracket (deRefWeakBlobRefs wrefs) removeReferences |
138 | | - |
139 | 94 | {-# SPECIALISE deRefWeakBlobRef :: |
140 | 95 | WeakBlobRef IO h |
141 | 96 | -> IO (StrongBlobRef IO h) #-} |
@@ -178,10 +133,6 @@ deRefWeakBlobRefs wrefs = do |
178 | 133 | removeReference :: (MonadMask m, PrimMonad m) => StrongBlobRef m h -> m () |
179 | 134 | removeReference = BlobFile.removeReference . strongBlobRefFile |
180 | 135 |
|
181 | | -{-# SPECIALISE removeReferences :: V.Vector (StrongBlobRef IO h) -> IO () #-} |
182 | | -removeReferences :: (MonadMask m, PrimMonad m) => V.Vector (StrongBlobRef m h) -> m () |
183 | | -removeReferences = V.mapM_ removeReference |
184 | | - |
185 | 136 | {-# INLINE readRawBlobRef #-} |
186 | 137 | readRawBlobRef :: |
187 | 138 | (MonadThrow m, PrimMonad m) |
@@ -246,3 +197,5 @@ readWeakBlobRefs hbio wrefs = |
246 | 197 | (\off len -> SerialisedBlob (RB.fromByteArray off len ba)) |
247 | 198 | bufOffs |
248 | 199 | (V.map blobRefSpanSize refs) |
| 200 | + where |
| 201 | + blobRefSpanSize = fromIntegral . blobSpanSize . strongBlobRefSpan |
0 commit comments