@@ -101,6 +101,9 @@ module Database.LSMTree (
101101 toSnapshotName ,
102102 SnapshotLabel (.. ),
103103
104+ -- * Session Configuration #session_configuration#
105+ Salt ,
106+
104107 -- * Table Configuration #table_configuration#
105108 TableConfig (
106109 confMergePolicy ,
@@ -242,7 +245,7 @@ import Database.LSMTree.Internal.Serialise.Class (SerialiseKey (..),
242245import Database.LSMTree.Internal.Snapshot (SnapshotLabel (.. ))
243246import Database.LSMTree.Internal.Types (BlobRef (.. ), Cursor (.. ),
244247 ResolveAsFirst (.. ), ResolveValue (.. ),
245- ResolveViaSemigroup (.. ), Session (.. ), Table (.. ),
248+ ResolveViaSemigroup (.. ), Salt , Session (.. ), Table (.. ),
246249 resolveAssociativity , resolveCompatibility ,
247250 resolveValidOutput )
248251import Database.LSMTree.Internal.Unsafe (BlobRefInvalidError (.. ),
@@ -263,6 +266,7 @@ import System.FS.API (FsPath, HasFS (..), MountPoint (..), mkFsPath)
263266import System.FS.BlockIO.API (HasBlockIO (.. ), defaultIOCtxParams )
264267import System.FS.BlockIO.IO (ioHasBlockIO , withIOHasBlockIO )
265268import System.FS.IO (HandleIO , ioHasFS )
269+ import System.Random (randomIO )
266270
267271--------------------------------------------------------------------------------
268272-- Usage Notes
@@ -426,6 +430,7 @@ Throws the following exceptions:
426430 Tracer IO LSMTreeTrace ->
427431 HasFS IO HandleIO ->
428432 HasBlockIO IO HandleIO ->
433+ Salt ->
429434 FsPath ->
430435 (Session IO -> IO a) ->
431436 IO a
@@ -436,12 +441,14 @@ withSession ::
436441 Tracer m LSMTreeTrace ->
437442 HasFS m h ->
438443 HasBlockIO m h ->
444+ -- | The session salt.
445+ Salt ->
439446 -- | The session directory.
440447 FsPath ->
441448 (Session m -> m a ) ->
442449 m a
443- withSession tracer hasFS hasBlockIO sessionDir action = do
444- Internal. withSession tracer hasFS hasBlockIO sessionDir (action . Session )
450+ withSession tracer hasFS hasBlockIO sessionSalt sessionDir action = do
451+ Internal. withSession tracer hasFS hasBlockIO sessionSalt sessionDir (action . Session )
445452
446453-- | Variant of 'withSession' that is specialised to 'IO' using the real filesystem.
447454withSessionIO ::
@@ -453,8 +460,9 @@ withSessionIO tracer sessionDir action = do
453460 let mountPoint = MountPoint sessionDir
454461 let sessionDirFsPath = mkFsPath []
455462 let hasFS = ioHasFS mountPoint
463+ sessionSalt <- randomIO
456464 withIOHasBlockIO hasFS defaultIOCtxParams $ \ hasBlockIO ->
457- withSession tracer hasFS hasBlockIO sessionDirFsPath action
465+ withSession tracer hasFS hasBlockIO sessionSalt sessionDirFsPath action
458466
459467{- |
460468Open a session from a session directory.
@@ -480,7 +488,7 @@ Throws the following exceptions:
480488 Tracer IO LSMTreeTrace ->
481489 HasFS IO HandleIO ->
482490 HasBlockIO IO HandleIO ->
483- -- \| The session directory.
491+ Salt ->
484492 FsPath ->
485493 IO (Session IO)
486494 #-}
@@ -490,26 +498,29 @@ openSession ::
490498 Tracer m LSMTreeTrace ->
491499 HasFS m h ->
492500 HasBlockIO m h ->
501+ -- | The session salt.
502+ Salt ->
493503 -- | The session directory.
494504 FsPath ->
495505 m (Session m )
496- openSession tracer hasFS hasBlockIO sessionDir =
497- Session <$> Internal. openSession tracer hasFS hasBlockIO sessionDir
506+ openSession tracer hasFS hasBlockIO sessionSalt sessionDir =
507+ Session <$> Internal. openSession tracer hasFS hasBlockIO sessionSalt sessionDir
498508
499509-- | Variant of 'openSession' that is specialised to 'IO' using the real filesystem.
500510openSessionIO ::
501511 Tracer IO LSMTreeTrace ->
502- -- \ | The session directory.
512+ -- | The session directory.
503513 FilePath ->
504514 IO (Session IO )
505515openSessionIO tracer sessionDir = do
506516 let mountPoint = MountPoint sessionDir
507517 let sessionDirFsPath = mkFsPath []
508518 let hasFS = ioHasFS mountPoint
519+ sessionSalt <- randomIO
509520 let acquireHasBlockIO = ioHasBlockIO hasFS defaultIOCtxParams
510521 let releaseHasBlockIO HasBlockIO {close} = close
511522 bracketOnError acquireHasBlockIO releaseHasBlockIO $ \ hasBlockIO ->
512- openSession tracer hasFS hasBlockIO sessionDirFsPath
523+ openSession tracer hasFS hasBlockIO sessionSalt sessionDirFsPath
513524
514525{- |
515526Close a session.
0 commit comments