Skip to content

Commit 4f28ff3

Browse files
committed
Eq instance for LSMTreeTrace and others
As I added this, I noticed `OffsetKey` is included in `CursorTrace`, but this is an internal type, so I changed it to `Maybe RawBytes` instead.
1 parent 89170eb commit 4f28ff3

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/Database/LSMTree/Internal/MergeSchedule.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ import System.FS.BlockIO.API (HasBlockIO)
9292
-------------------------------------------------------------------------------}
9393

9494
data AtLevel a = AtLevel LevelNo a
95-
deriving stock Show
95+
deriving stock (Show, Eq)
9696

9797
data MergeTrace =
9898
TraceFlushWriteBuffer
@@ -118,7 +118,7 @@ data MergeTrace =
118118
-- | This is traced at the latest point the merge could complete.
119119
| TraceExpectCompletedMerge
120120
RunNumber
121-
deriving stock Show
121+
deriving stock (Show, Eq)
122122

123123
{-------------------------------------------------------------------------------
124124
Table content

src/Database/LSMTree/Internal/Unsafe.hs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,15 @@ import Database.LSMTree.Internal.Paths (SessionRoot (..),
140140
SnapshotMetaDataFile (..), SnapshotName)
141141
import qualified Database.LSMTree.Internal.Paths as Paths
142142
import Database.LSMTree.Internal.Range (Range (..))
143+
import Database.LSMTree.Internal.RawBytes (RawBytes)
143144
import Database.LSMTree.Internal.Readers (OffsetKey (..))
144145
import qualified Database.LSMTree.Internal.Readers as Readers
145146
import Database.LSMTree.Internal.Run (Run)
146147
import qualified Database.LSMTree.Internal.Run as Run
147148
import Database.LSMTree.Internal.RunNumber
148149
import Database.LSMTree.Internal.Serialise (ResolveSerialisedValue,
149-
SerialisedBlob (..), SerialisedKey, SerialisedValue)
150+
SerialisedBlob (..), SerialisedKey (SerialisedKey),
151+
SerialisedValue)
150152
import Database.LSMTree.Internal.Snapshot
151153
import Database.LSMTree.Internal.Snapshot.Codec
152154
import Database.LSMTree.Internal.UniqCounter
@@ -206,7 +208,7 @@ data LSMTreeTrace =
206208
-- | Cursors are identified by a unique number.
207209
CursorId
208210
CursorTrace
209-
deriving stock Show
211+
deriving stock (Show, Eq)
210212

211213
-- | Sessions are identified by the path to their root directory.
212214
newtype SessionId = SessionId FsPath
@@ -243,7 +245,7 @@ data SessionTrace =
243245

244246
-- | We are retrieving blobs.
245247
| TraceRetrieveBlobs Int
246-
deriving stock Show
248+
deriving stock (Show, Eq)
247249

248250
-- | Trace messages related to tables.
249251
data TableTrace =
@@ -313,7 +315,7 @@ data TableTrace =
313315
-- | INTERNAL: debug traces for the merge schedule
314316
| TraceMerge (AtLevel MergeTrace)
315317
#endif
316-
deriving stock Show
318+
deriving stock (Show, Eq)
317319

318320
contramapTraceMerge :: Monad m => Tracer m TableTrace -> Tracer m (AtLevel MergeTrace)
319321
#ifdef DEBUG_TRACES
@@ -333,7 +335,9 @@ data CursorTrace =
333335
| TraceNewCursor
334336
-- | The parent table
335337
TableId
336-
OffsetKey
338+
-- | The optional serialised key that is used as the initial offset for
339+
-- the cursor.
340+
(Maybe RawBytes)
337341

338342
-- | We are closing the cursor. A 'TraceClosedCursor' message should follow
339343
-- if successful.
@@ -352,7 +356,7 @@ data CursorTrace =
352356
Int
353357
-- | Actual number of entries read.
354358
Int
355-
deriving stock Show
359+
deriving stock (Show, Eq)
356360

357361
{-------------------------------------------------------------------------------
358362
Session
@@ -1426,7 +1430,9 @@ newCursor !resolve !offsetKey t = withKeepTableOpen t $ \tEnv -> do
14261430
cursorId <- uniqueToCursorId <$>
14271431
incrUniqCounter (tableSessionUniqCounter t)
14281432
let cursorTracer = TraceCursor cursorId `contramap` lsmTreeTracer cursorSession
1429-
traceWith cursorTracer $ TraceNewCursor (tableId t) offsetKey
1433+
traceWith cursorTracer $ TraceNewCursor (tableId t) $ case offsetKey of
1434+
NoOffsetKey -> Nothing
1435+
OffsetKey (SerialisedKey bytes) -> Just bytes
14301436

14311437
-- We acquire a read-lock on the session open-state to prevent races, see
14321438
-- 'sessionOpenTables'.

test/golden-file-data/tracer/golden_traceMessages.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ TraceTable (TableId 0) (TraceUpdated 1)
1414
TraceTable (TableId 0) (TraceLookups 1)
1515
TraceTable (TableId 0) (TraceLookups 1)
1616
TraceTable (TableId 0) (TraceRangeLookup (FromToExcluding (SerialisedKey [0,0,0,0,0,0,0,0]) (SerialisedKey [0,0,0,0,0,0,0,3])))
17-
TraceCursor (CursorId 2) (TraceNewCursor (TableId 0) (OffsetKey (SerialisedKey [0,0,0,0,0,0,0,0])))
17+
TraceCursor (CursorId 2) (TraceNewCursor (TableId 0) (Just [0,0,0,0,0,0,0,0]))
1818
TraceCursor (CursorId 2) (TraceCreatedCursor (SessionId session-dir))
1919
TraceCursor (CursorId 2) (TraceReadingCursor 500)
2020
TraceCursor (CursorId 2) (TraceReadCursor 500 2)
2121
TraceCursor (CursorId 2) TraceCloseCursor
2222
TraceCursor (CursorId 2) TraceClosedCursor
23-
TraceCursor (CursorId 3) (TraceNewCursor (TableId 0) (OffsetKey (SerialisedKey [0,0,0,0,0,0,0,1])))
23+
TraceCursor (CursorId 3) (TraceNewCursor (TableId 0) (Just [0,0,0,0,0,0,0,1]))
2424
TraceCursor (CursorId 3) (TraceCreatedCursor (SessionId session-dir))
2525
TraceCursor (CursorId 3) (TraceReadingCursor 2)
2626
TraceCursor (CursorId 3) (TraceReadCursor 2 1)
@@ -66,7 +66,7 @@ TraceTable (TableId 0) TraceCloseTable
6666
TraceTable (TableId 0) TraceClosedTable
6767
TraceTable (TableId 21) (TraceNewTable (TableConfig {confMergePolicy = LazyLevelling, confMergeSchedule = Incremental, confSizeRatio = Four, confWriteBufferAlloc = AllocNumEntries 20000, confBloomFilterAlloc = AllocRequestFPR 1.0e-3, confFencePointerIndex = OrdinaryIndex, confDiskCachePolicy = DiskCacheAll, confMergeBatchSize = MergeBatchSize 20000}))
6868
TraceTable (TableId 21) (TraceCreatedTable (SessionId session-dir) (TableConfig {confMergePolicy = LazyLevelling, confMergeSchedule = Incremental, confSizeRatio = Four, confWriteBufferAlloc = AllocNumEntries 20000, confBloomFilterAlloc = AllocRequestFPR 1.0e-3, confFencePointerIndex = OrdinaryIndex, confDiskCachePolicy = DiskCacheAll, confMergeBatchSize = MergeBatchSize 20000}))
69-
TraceCursor (CursorId 23) (TraceNewCursor (TableId 21) NoOffsetKey)
69+
TraceCursor (CursorId 23) (TraceNewCursor (TableId 21) Nothing)
7070
TraceCursor (CursorId 23) (TraceCreatedCursor (SessionId session-dir))
7171
TraceSession (SessionId session-dir) TraceCloseSession
7272
TraceCursor (CursorId 23) TraceCloseCursor

0 commit comments

Comments
 (0)