acid-state-0.14.2: Add ACID guarantees to any serializable Haskell data structure.

Copyright | PublicDomain
Maintainer | lemmih@gmail.com
Portability | non-portable (uses GHC extensions)
Safe Haskell | None
Language | Haskell2010

Data.Acid.Local

Description

AcidState container using a transaction log on disk. The term 'Event' is loosely used for transactions with ACID guarantees. 'Method' is loosely used for state operations without ACID guarantees (see Data.Acid.Core).

Synopsis

- openLocalState :: (Typeable st, IsAcidic st) => st -> IO (AcidState st)
- openLocalStateFrom :: IsAcidic st => FilePath -> st -> IO (AcidState st)
- prepareLocalState :: (Typeable st, IsAcidic st) => st -> IO (IO (AcidState st))
- prepareLocalStateFrom :: IsAcidic st => FilePath -> st -> IO (IO (AcidState st))
- scheduleLocalUpdate' :: UpdateEvent event => LocalState (EventState event) -> event -> MVar (EventResult event) -> IO (IO ())
- scheduleLocalColdUpdate' :: LocalState st -> Tagged ByteString -> MVar ByteString -> IO (IO ())
- createCheckpointAndClose :: (SafeCopy st, Typeable st) => AcidState st -> IO ()
- data LocalState st = LocalState {
  - localCore :: Core st
  - localCopy :: IORef st
  - localEvents :: FileLog (Tagged ByteString)
  - localCheckpoints :: FileLog Checkpoint
  - localLock :: PrefixLock
  }
- data Checkpoint = Checkpoint EntryId ByteString

# Documentation

openLocalState Source #

Arguments

:: (Typeable st, IsAcidic st) |
=> st | Initial state value. This value is only used if no checkpoint is found.
-> IO (AcidState st) |

Create an AcidState given an initial value.

This will create or resume a log found in the "state/[typeOf state]/" directory.

openLocalStateFrom Source #

Arguments

:: IsAcidic st |
=> FilePath | Location of the checkpoint and transaction files.
-> st | Initial state value. This value is only used if no checkpoint is found.
-> IO (AcidState st) |

Create an AcidState given a log directory and an initial value.

This will create or resume a log found in `directory`. Running two AcidState's from the same directory is an error but will not result in dataloss.

prepareLocalState Source #

Arguments

:: (Typeable st, IsAcidic st) |
=> st | Initial state value. This value is only used if no checkpoint is found.
-> IO (IO (AcidState st)) |

Create an AcidState given an initial value.

This will create or resume a log found in the "state/[typeOf state]/" directory. The most recent checkpoint will be loaded immediately but the AcidState will not be opened until the returned function is executed.

prepareLocalStateFrom Source #

Arguments

:: IsAcidic st |
=> FilePath | Location of the checkpoint and transaction files.
-> st | Initial state value. This value is only used if no checkpoint is found.
-> IO (IO (AcidState st)) |

Create an AcidState given an initial value.

This will create or resume a log found in `directory`. The most recent checkpoint will be loaded immediately but the AcidState will not be opened until the returned function is executed.

scheduleLocalUpdate' :: UpdateEvent event => LocalState (EventState event) -> event -> MVar (EventResult event) -> IO (IO ()) Source #

Same as scheduleLocalUpdate but does not immediately change the localCopy and return the result mvar - returns an IO action to do this instead. Take care to run actions of multiple Updates in the correct order as otherwise Queries will operate on outdated state.

scheduleLocalColdUpdate' :: LocalState st -> Tagged ByteString -> MVar ByteString -> IO (IO ()) Source #

Same as scheduleLocalColdUpdate but does not immediately change the localCopy and return the result mvar - returns an IO action to do this instead. Take care to run actions of multiple Updates in the correct order as otherwise Queries will operate on outdated state.

createCheckpointAndClose :: (SafeCopy st, Typeable st) => AcidState st -> IO () Source #

Save a snapshot to disk and close the AcidState as a single atomic action. This is useful when you want to make sure that no events are saved to disk after a checkpoint.

data LocalState st Source #

State container offering full ACID (Atomicity, Consistency, Isolation and Durability) guarantees.

`Atomicity`
  State changes are all-or-nothing. This is what you'd expect of any state variable in Haskell and AcidState doesn't change that.
`Consistency`
  No event or set of events will break your data invariants.
`Isolation`
  Transactions cannot interfere with each other even when issued in parallel.
`Durability`
  Successful transaction are guaranteed to survive system failure (both hardware and software).

Constructors

LocalState |

Fields

- localCore :: Core st
- localCopy :: IORef st
- localEvents :: FileLog (Tagged ByteString)
- localCheckpoints :: FileLog Checkpoint
- localLock :: PrefixLock

data Checkpoint Source #

Constructors

Checkpoint EntryId ByteString |

Instances

SafeCopy Checkpoint Source # |
Methods version :: Version Checkpoint # kind :: Kind Checkpoint # getCopy :: Contained (Get Checkpoint) # putCopy :: Checkpoint -> Contained Put # internalConsistency :: Consistency Checkpoint # objectProfile :: Profile Checkpoint # errorTypeName :: Proxy Checkpoint -> String #