module Database.LSMTree.Common (
IOLike
, Internal.SessionDirDoesNotExistError (..)
, Internal.SessionDirLockedError (..)
, Internal.SessionDirCorruptedError (..)
, Internal.SessionClosedError (..)
, Internal.TableClosedError (..)
, Internal.TableCorruptedError (..)
, Internal.TableTooLargeError (..)
, Internal.TableUnionNotCompatibleError (..)
, Internal.SnapshotExistsError (..)
, Internal.SnapshotDoesNotExistError (..)
, Internal.SnapshotCorruptedError (..)
, Internal.SnapshotNotCompatibleError (..)
, Internal.BlobRefInvalidError (..)
, Internal.CursorClosedError (..)
, Internal.FileFormat (..)
, Internal.FileCorruptedError (..)
, Internal.InvalidSnapshotNameError (..)
, Internal.LSMTreeTrace (..)
, Internal.TableTrace (..)
, Internal.MergeTrace (..)
, Session
, withSession
, openSession
, closeSession
, SerialiseKey (..)
, SerialiseValue (..)
, Internal.Range (..)
, Internal.SnapshotLabel (..)
, Internal.SnapshotTableType (..)
, deleteSnapshot
, listSnapshots
, SnapshotName
, Internal.toSnapshotName
, Internal.isValidSnapshotName
, BlobRef (..)
, Internal.TableConfig (..)
, Internal.defaultTableConfig
, Internal.SizeRatio (..)
, Internal.MergePolicy (..)
, Internal.WriteBufferAlloc (..)
, Internal.NumEntries (..)
, Internal.BloomFilterAlloc (..)
, Internal.defaultBloomFilterAlloc
, Internal.FencePointerIndexType (..)
, Internal.DiskCachePolicy (..)
, Internal.MergeSchedule (..)
, Internal.defaultMergeSchedule
, Internal.TableConfigOverride
, Internal.configNoOverride
, Internal.configOverrideDiskCachePolicy
, UnionDebt (..)
, UnionCredits (..)
) where
import Control.Concurrent.Class.MonadMVar.Strict
import Control.Concurrent.Class.MonadSTM (STM)
import Control.Monad.Class.MonadAsync
import Control.Monad.Class.MonadST
import Control.Monad.Class.MonadThrow
import Control.Monad.Primitive (PrimMonad)
import Control.Tracer (Tracer)
import Data.Kind (Type)
import Data.Typeable (Typeable)
import qualified Database.LSMTree.Internal as Internal
import qualified Database.LSMTree.Internal.BlobRef as Internal
import qualified Database.LSMTree.Internal.Config as Internal
import qualified Database.LSMTree.Internal.Entry as Internal
import qualified Database.LSMTree.Internal.MergeSchedule as Internal
import Database.LSMTree.Internal.Paths (SnapshotName)
import qualified Database.LSMTree.Internal.Paths as Internal
import qualified Database.LSMTree.Internal.Range as Internal
import Database.LSMTree.Internal.Serialise.Class
import qualified Database.LSMTree.Internal.Snapshot as Internal
import System.FS.API (FsPath, HasFS)
import System.FS.BlockIO.API (HasBlockIO)
import System.FS.IO (HandleIO)
type IOLike m = (
MonadAsync m, MonadMVar m, MonadThrow (STM m), MonadThrow m
, MonadCatch m , MonadMask m, PrimMonad m, MonadST m
)
type Session :: (Type -> Type) -> Type
type Session = Internal.Session'
{-# SPECIALISE withSession ::
Tracer IO Internal.LSMTreeTrace
-> HasFS IO HandleIO
-> HasBlockIO IO HandleIO
-> FsPath
-> (Session IO -> IO a)
-> IO a #-}
withSession ::
(IOLike m, Typeable h)
=> Tracer m Internal.LSMTreeTrace
-> HasFS m h
-> HasBlockIO m h
-> FsPath
-> (Session m -> m a)
-> m a
withSession :: forall (m :: * -> *) h a.
(IOLike m, Typeable h) =>
Tracer m LSMTreeTrace
-> HasFS m h
-> HasBlockIO m h
-> FsPath
-> (Session m -> m a)
-> m a
withSession Tracer m LSMTreeTrace
tr HasFS m h
hfs HasBlockIO m h
hbio FsPath
dir Session m -> m a
action = Tracer m LSMTreeTrace
-> HasFS m h
-> HasBlockIO m h
-> FsPath
-> (Session m h -> m a)
-> m a
forall (m :: * -> *) h a.
(MonadMask m, MonadSTM m, MonadMVar m, PrimMonad m) =>
Tracer m LSMTreeTrace
-> HasFS m h
-> HasBlockIO m h
-> FsPath
-> (Session m h -> m a)
-> m a
Internal.withSession Tracer m LSMTreeTrace
tr HasFS m h
hfs HasBlockIO m h
hbio FsPath
dir (Session m -> m a
action (Session m -> m a)
-> (Session m h -> Session m) -> Session m h -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Session m h -> Session m
forall (m :: * -> *) h. Typeable h => Session m h -> Session' m
Internal.Session')
{-# SPECIALISE openSession ::
Tracer IO Internal.LSMTreeTrace
-> HasFS IO HandleIO
-> HasBlockIO IO HandleIO
-> FsPath
-> IO (Session IO) #-}
openSession ::
forall m h. (IOLike m, Typeable h)
=> Tracer m Internal.LSMTreeTrace
-> HasFS m h
-> HasBlockIO m h
-> FsPath
-> m (Session m)
openSession :: forall (m :: * -> *) h.
(IOLike m, Typeable h) =>
Tracer m LSMTreeTrace
-> HasFS m h -> HasBlockIO m h -> FsPath -> m (Session m)
openSession Tracer m LSMTreeTrace
tr HasFS m h
hfs HasBlockIO m h
hbio FsPath
dir = Session m h -> Session' m
forall (m :: * -> *) h. Typeable h => Session m h -> Session' m
Internal.Session' (Session m h -> Session' m) -> m (Session m h) -> m (Session' m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Tracer m LSMTreeTrace
-> HasFS m h -> HasBlockIO m h -> FsPath -> m (Session m h)
forall (m :: * -> *) h.
(MonadSTM m, MonadMVar m, PrimMonad m, MonadMask m) =>
Tracer m LSMTreeTrace
-> HasFS m h -> HasBlockIO m h -> FsPath -> m (Session m h)
Internal.openSession Tracer m LSMTreeTrace
tr HasFS m h
hfs HasBlockIO m h
hbio FsPath
dir
{-# SPECIALISE closeSession :: Session IO -> IO () #-}
closeSession :: IOLike m => Session m -> m ()
closeSession :: forall (m :: * -> *). IOLike m => Session m -> m ()
closeSession (Internal.Session' Session m h
sesh) = Session m h -> m ()
forall (m :: * -> *) h.
(MonadMask m, MonadSTM m, MonadMVar m, PrimMonad m) =>
Session m h -> m ()
Internal.closeSession Session m h
sesh
{-# SPECIALISE deleteSnapshot ::
Session IO
-> SnapshotName
-> IO () #-}
deleteSnapshot ::
IOLike m
=> Session m
-> SnapshotName
-> m ()
deleteSnapshot :: forall (m :: * -> *). IOLike m => Session m -> SnapshotName -> m ()
deleteSnapshot (Internal.Session' Session m h
sesh) = Session m h -> SnapshotName -> m ()
forall (m :: * -> *) h.
(MonadMask m, MonadSTM m) =>
Session m h -> SnapshotName -> m ()
Internal.deleteSnapshot Session m h
sesh
{-# SPECIALISE listSnapshots ::
Session IO
-> IO [SnapshotName] #-}
listSnapshots ::
IOLike m
=> Session m
-> m [SnapshotName]
listSnapshots :: forall (m :: * -> *). IOLike m => Session m -> m [SnapshotName]
listSnapshots (Internal.Session' Session m h
sesh) = Session m h -> m [SnapshotName]
forall (m :: * -> *) h.
(MonadMask m, MonadSTM m) =>
Session m h -> m [SnapshotName]
Internal.listSnapshots Session m h
sesh
type BlobRef :: (Type -> Type) -> Type -> Type
type role BlobRef nominal nominal
data BlobRef m b where
BlobRef :: Typeable h
=> Internal.WeakBlobRef m h
-> BlobRef m b
instance Show (BlobRef m b) where
showsPrec :: Int -> BlobRef m b -> ShowS
showsPrec Int
d (BlobRef WeakBlobRef m h
b) = Int -> WeakBlobRef m h -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
d WeakBlobRef m h
b
newtype UnionDebt = UnionDebt Int
deriving stock (Int -> UnionDebt -> ShowS
[UnionDebt] -> ShowS
UnionDebt -> String
(Int -> UnionDebt -> ShowS)
-> (UnionDebt -> String)
-> ([UnionDebt] -> ShowS)
-> Show UnionDebt
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UnionDebt -> ShowS
showsPrec :: Int -> UnionDebt -> ShowS
$cshow :: UnionDebt -> String
show :: UnionDebt -> String
$cshowList :: [UnionDebt] -> ShowS
showList :: [UnionDebt] -> ShowS
Show, UnionDebt -> UnionDebt -> Bool
(UnionDebt -> UnionDebt -> Bool)
-> (UnionDebt -> UnionDebt -> Bool) -> Eq UnionDebt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UnionDebt -> UnionDebt -> Bool
== :: UnionDebt -> UnionDebt -> Bool
$c/= :: UnionDebt -> UnionDebt -> Bool
/= :: UnionDebt -> UnionDebt -> Bool
Eq, Eq UnionDebt
Eq UnionDebt =>
(UnionDebt -> UnionDebt -> Ordering)
-> (UnionDebt -> UnionDebt -> Bool)
-> (UnionDebt -> UnionDebt -> Bool)
-> (UnionDebt -> UnionDebt -> Bool)
-> (UnionDebt -> UnionDebt -> Bool)
-> (UnionDebt -> UnionDebt -> UnionDebt)
-> (UnionDebt -> UnionDebt -> UnionDebt)
-> Ord UnionDebt
UnionDebt -> UnionDebt -> Bool
UnionDebt -> UnionDebt -> Ordering
UnionDebt -> UnionDebt -> UnionDebt
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: UnionDebt -> UnionDebt -> Ordering
compare :: UnionDebt -> UnionDebt -> Ordering
$c< :: UnionDebt -> UnionDebt -> Bool
< :: UnionDebt -> UnionDebt -> Bool
$c<= :: UnionDebt -> UnionDebt -> Bool
<= :: UnionDebt -> UnionDebt -> Bool
$c> :: UnionDebt -> UnionDebt -> Bool
> :: UnionDebt -> UnionDebt -> Bool
$c>= :: UnionDebt -> UnionDebt -> Bool
>= :: UnionDebt -> UnionDebt -> Bool
$cmax :: UnionDebt -> UnionDebt -> UnionDebt
max :: UnionDebt -> UnionDebt -> UnionDebt
$cmin :: UnionDebt -> UnionDebt -> UnionDebt
min :: UnionDebt -> UnionDebt -> UnionDebt
Ord)
newtype UnionCredits = UnionCredits Int
deriving stock (Int -> UnionCredits -> ShowS
[UnionCredits] -> ShowS
UnionCredits -> String
(Int -> UnionCredits -> ShowS)
-> (UnionCredits -> String)
-> ([UnionCredits] -> ShowS)
-> Show UnionCredits
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UnionCredits -> ShowS
showsPrec :: Int -> UnionCredits -> ShowS
$cshow :: UnionCredits -> String
show :: UnionCredits -> String
$cshowList :: [UnionCredits] -> ShowS
showList :: [UnionCredits] -> ShowS
Show, UnionCredits -> UnionCredits -> Bool
(UnionCredits -> UnionCredits -> Bool)
-> (UnionCredits -> UnionCredits -> Bool) -> Eq UnionCredits
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UnionCredits -> UnionCredits -> Bool
== :: UnionCredits -> UnionCredits -> Bool
$c/= :: UnionCredits -> UnionCredits -> Bool
/= :: UnionCredits -> UnionCredits -> Bool
Eq, Eq UnionCredits
Eq UnionCredits =>
(UnionCredits -> UnionCredits -> Ordering)
-> (UnionCredits -> UnionCredits -> Bool)
-> (UnionCredits -> UnionCredits -> Bool)
-> (UnionCredits -> UnionCredits -> Bool)
-> (UnionCredits -> UnionCredits -> Bool)
-> (UnionCredits -> UnionCredits -> UnionCredits)
-> (UnionCredits -> UnionCredits -> UnionCredits)
-> Ord UnionCredits
UnionCredits -> UnionCredits -> Bool
UnionCredits -> UnionCredits -> Ordering
UnionCredits -> UnionCredits -> UnionCredits
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: UnionCredits -> UnionCredits -> Ordering
compare :: UnionCredits -> UnionCredits -> Ordering
$c< :: UnionCredits -> UnionCredits -> Bool
< :: UnionCredits -> UnionCredits -> Bool
$c<= :: UnionCredits -> UnionCredits -> Bool
<= :: UnionCredits -> UnionCredits -> Bool
$c> :: UnionCredits -> UnionCredits -> Bool
> :: UnionCredits -> UnionCredits -> Bool
$c>= :: UnionCredits -> UnionCredits -> Bool
>= :: UnionCredits -> UnionCredits -> Bool
$cmax :: UnionCredits -> UnionCredits -> UnionCredits
max :: UnionCredits -> UnionCredits -> UnionCredits
$cmin :: UnionCredits -> UnionCredits -> UnionCredits
min :: UnionCredits -> UnionCredits -> UnionCredits
Ord)