File tree Expand file tree Collapse file tree 5 files changed +49
-7
lines changed
src/Database/LSMTree/Internal Expand file tree Collapse file tree 5 files changed +49
-7
lines changed Original file line number Diff line number Diff line change @@ -194,13 +194,21 @@ mkOverrideDiskCachePolicy GlobalOpts{diskCachePolicy} = LSM.OverrideDiskCachePol
194194mkTracer :: GlobalOpts -> Tracer IO LSM. LSMTreeTrace
195195mkTracer 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-------------------------------------------------------------------------------
Original file line number Diff line number Diff 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+
487497common 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
Original file line number Diff line number Diff 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)
205206contramapTraceMerge :: Monad m => Tracer m TableTrace -> Tracer m (AtLevel MergeTrace )
206207#ifdef DEBUG_TRACES
207208contramapTraceMerge t = TraceMerge `contramap` t
208209#else
209210contramapTraceMerge 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
212217data CursorTrace =
213218 TraceCreateCursor TableId
Original file line number Diff line number Diff line change 1+ {-# LANGUAGE CPP #-}
2+
13module Test.ScheduledMerges (tests ) where
24
35import Control.Exception
46import Control.Monad (replicateM_ , when )
57import Control.Monad.ST
68import Control.Tracer (Tracer (Tracer ))
9+ #if MIN_VERSION_contra_tracer(0,2,0)
710import qualified Control.Tracer as Tracer
11+ #endif
812import Data.Foldable (find , traverse_ )
913import Data.Maybe (fromJust )
1014import Data.STRef
@@ -526,7 +530,11 @@ genShrinkTrace !n x
526530runWithTracer :: (Tracer (ST RealWorld ) Event -> IO a ) -> IO a
527531runWithTracer 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
Original file line number Diff line number Diff line change 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.
136137mkSessionOpenModeTracer :: 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
You can’t perform that action at this time.
0 commit comments