Skip to content

Commit fa0d862

Browse files
committed
Allow IOG's contra-tracer
1 parent 6276783 commit fa0d862

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

bench/macro/lsm-tree-bench-wp8.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,21 @@ mkOverrideDiskCachePolicy GlobalOpts{diskCachePolicy} = LSM.OverrideDiskCachePol
194194
mkTracer :: GlobalOpts -> Tracer IO LSM.LSMTreeTrace
195195
mkTracer gopts
196196
| trace gopts =
197+
#if MIN_VERSION_contra_tracer(0,2,0)
197198
-- Don't trace update/lookup messages, because they are too noisy
198199
squelchUnless
199200
(\case
200201
LSM.TraceTable _ LSM.TraceUpdates{} -> False
201202
LSM.TraceTable _ LSM.TraceLookups{} -> False
202203
_ -> True )
203204
(show `contramap` stdoutTracer)
205+
#else
206+
Tracer $
207+
\case
208+
LSM.TraceTable _ LSM.TraceUpdates{} -> pure ()
209+
LSM.TraceTable _ LSM.TraceLookups{} -> pure ()
210+
e -> traceWith (show `contramap` stdoutTracer) e
211+
#endif
204212
| otherwise = nullTracer
205213

206214
-------------------------------------------------------------------------------

lsm-tree.cabal

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,16 @@ source-repository this
484484
location: https://github.com/IntersectMBO/lsm-tree
485485
tag: lsm-tree-0.1.0.0
486486

487+
flag iog-contra-tracer
488+
description:
489+
IOG's contra-tracer (https://chap.intersectmbo.org/package/contra-tracer-0.1.0.2/)
490+
is slightly different than the one on Hackage. This flag is
491+
expected to be switched automatically by Cabal if this library is
492+
used in some project which uses the IOG fork of contra-tracer.
493+
494+
manual: False
495+
default: False
496+
487497
common warnings
488498
ghc-options:
489499
-Wall -Wcompat -Wincomplete-uni-patterns
@@ -582,7 +592,6 @@ library
582592
, bytestring ^>=0.11.4.0 || ^>=0.12.1.0
583593
, cborg ^>=0.2.10.0
584594
, containers ^>=0.6 || ^>=0.7
585-
, contra-tracer ^>=0.2
586595
, crc32c ^>=0.2.1
587596
, deepseq ^>=1.4 || ^>=1.5
588597
, filepath
@@ -600,6 +609,12 @@ library
600609
, vector ^>=0.13
601610
, vector-algorithms ^>=0.9
602611

612+
if flag(iog-contra-tracer)
613+
build-depends: contra-tracer ^>=0.1
614+
615+
else
616+
build-depends: contra-tracer ^>=0.2
617+
603618
if impl(ghc >=9.4)
604619
other-modules: Database.LSMTree.Internal.StrictArray
605620
build-depends: data-elevator ^>=0.1.0.2 || ^>=0.2

src/Database/LSMTree/Internal/Unsafe.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,17 @@ data TableTrace =
202202
| TraceSupplyUnionCredits UnionCredits
203203
deriving stock Show
204204

205+
#if MIN_VERSION_contra_tracer(0,2,0)
205206
contramapTraceMerge :: Monad m => Tracer m TableTrace -> Tracer m (AtLevel MergeTrace)
206207
#ifdef DEBUG_TRACES
207208
contramapTraceMerge t = TraceMerge `contramap` t
208209
#else
209210
contramapTraceMerge t = traceMaybe (const Nothing) t
210211
#endif
212+
#else
213+
contramapTraceMerge :: Applicative m => Tracer m TableTrace -> Tracer m (AtLevel MergeTrace)
214+
contramapTraceMerge _t = nullTracer
215+
#endif
211216

212217
data CursorTrace =
213218
TraceCreateCursor TableId

test-prototypes/Test/ScheduledMerges.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
{-# LANGUAGE CPP #-}
2+
13
module Test.ScheduledMerges (tests) where
24

35
import Control.Exception
46
import Control.Monad (replicateM_, when)
57
import Control.Monad.ST
68
import Control.Tracer (Tracer (Tracer))
9+
#if MIN_VERSION_contra_tracer(0,2,0)
710
import qualified Control.Tracer as Tracer
11+
#endif
812
import Data.Foldable (find, traverse_)
913
import Data.Maybe (fromJust)
1014
import Data.STRef
@@ -526,7 +530,11 @@ genShrinkTrace !n x
526530
runWithTracer :: (Tracer (ST RealWorld) Event -> IO a) -> IO a
527531
runWithTracer action = do
528532
events <- stToIO $ newSTRef []
529-
let tracer = Tracer $ Tracer.emit $ \e -> modifySTRef events (e :)
533+
let tracer = Tracer $
534+
#if MIN_VERSION_contra_tracer(0,2,0)
535+
Tracer.emit $
536+
#endif
537+
\e -> modifySTRef events (e :)
530538
action tracer `catch` \e -> do
531539
if isDiscard e -- don't intercept these
532540
then throwIO e

test/Test/Database/LSMTree.hs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE LambdaCase #-}
23
{-# LANGUAGE OverloadedStrings #-}
34
{-# LANGUAGE RecordWildCards #-}
@@ -134,11 +135,16 @@ prop_openSession_restoreSession =
134135
-- | A tracer that records session open, session new, and session restore
135136
-- messages in a mutable variable.
136137
mkSessionOpenModeTracer :: IORef [String] -> Tracer IO LSMTreeTrace
137-
mkSessionOpenModeTracer var = Tracer $ emit $ \case
138-
TraceOpenSession{} -> modifyIORef var ("Open" :)
139-
TraceNewSession{} -> modifyIORef var ("New" :)
140-
TraceRestoreSession{} -> modifyIORef var ("Restore" :)
141-
_ -> pure ()
138+
mkSessionOpenModeTracer var =
139+
Tracer $
140+
#if MIN_VERSION_contra_tracer(0,2,0)
141+
emit $
142+
#endif
143+
\case
144+
TraceOpenSession{} -> modifyIORef var ("Open" :)
145+
TraceNewSession{} -> modifyIORef var ("New" :)
146+
TraceRestoreSession{} -> modifyIORef var ("Restore" :)
147+
_ -> pure ()
142148

143149
{-------------------------------------------------------------------------------
144150
Session: happy path

0 commit comments

Comments
 (0)