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

Safe Haskell | None
Language | Haskell2010

Data.Acid.Abstract

Synopsis

- data AcidState st = AcidState {
  - _scheduleUpdate :: forall event. (UpdateEvent event, EventState event ~ st) => event -> IO (MVar (EventResult event))
  - scheduleColdUpdate :: Tagged ByteString -> IO (MVar ByteString)
  - _query :: forall event. (QueryEvent event, EventState event ~ st) => event -> IO (EventResult event)
  - queryCold :: Tagged ByteString -> IO ByteString
  - createCheckpoint :: IO ()
  - createArchive :: IO ()
  - closeAcidState :: IO ()
  - acidSubState :: AnyState st
  }
- scheduleUpdate :: UpdateEvent event => AcidState (EventState event) -> event -> IO (MVar (EventResult event))
- groupUpdates :: UpdateEvent event => AcidState (EventState event) -> [event] -> IO ()
- update :: UpdateEvent event => AcidState (EventState event) -> event -> IO (EventResult event)
- update' :: (UpdateEvent event, MonadIO m) => AcidState (EventState event) -> event -> m (EventResult event)
- query :: QueryEvent event => AcidState (EventState event) -> event -> IO (EventResult event)
- query' :: (QueryEvent event, MonadIO m) => AcidState (EventState event) -> event -> m (EventResult event)
- mkAnyState :: Typeable sub_st => sub_st st -> AnyState st
- downcast :: (Typeable sub, Typeable st) => AcidState st -> sub st

# Documentation

data AcidState 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 unexpected system shutdowns (both those caused by hardware and software).

Constructors

AcidState |

Fields

- _scheduleUpdate :: forall event. (UpdateEvent event, EventState event ~ st) => event -> IO (MVar (EventResult event))
- scheduleColdUpdate :: Tagged ByteString -> IO (MVar ByteString)
- _query :: forall event. (QueryEvent event, EventState event ~ st) => event -> IO (EventResult event)
- queryCold :: Tagged ByteString -> IO ByteString
- createCheckpoint :: IO ()

  Take a snapshot of the state and save it to disk. Creating checkpoints makes it faster to resume AcidStates and you're free to create them as often or seldom as fits your needs. Transactions can run concurrently with this call.

  This call will not return until the operation has succeeded.

- createArchive :: IO ()

  Move all log files that are no longer necessary for state restoration into the `Archive` folder in the state directory. This folder can then be backed up or thrown out as you see fit. Reverting to a state before the last checkpoint will not be possible if the `Archive` folder has been thrown out.

  This method is idempotent and does not block the normal operation of the AcidState.

- closeAcidState :: IO ()

  Close an AcidState and associated resources. Any subsequent usage of the AcidState will throw an exception.

- acidSubState :: AnyState st

scheduleUpdate :: UpdateEvent event => AcidState (EventState event) -> event -> IO (MVar (EventResult event)) Source #

Issue an Update event and return immediately. The event is not durable before the MVar has been filled but the order of events is honored. The behavior in case of exceptions is exactly the same as for `update`.

If EventA is scheduled before EventB, EventA will be executed before EventB:

    do scheduleUpdate acid EventA
       scheduleUpdate acid EventB

groupUpdates :: UpdateEvent event => AcidState (EventState event) -> [event] -> IO () Source #

Schedule multiple Update events and wait for them to be durable, but throw away their results. This is useful for importing existing datasets into an AcidState.

update :: UpdateEvent event => AcidState (EventState event) -> event -> IO (EventResult event) Source #

Issue an Update event and wait for its result. Once this call returns, you are guaranteed that the changes to the state are durable. Events may be issued in parallel.

It's a run-time error to issue events that aren't supported by the AcidState.

update' :: (UpdateEvent event, MonadIO m) => AcidState (EventState event) -> event -> m (EventResult event) Source #

Same as `update` but lifted into any monad capable of doing IO.

query :: QueryEvent event => AcidState (EventState event) -> event -> IO (EventResult event) Source #

Issue a Query event and wait for its result. Events may be issued in parallel.

query' :: (QueryEvent event, MonadIO m) => AcidState (EventState event) -> event -> m (EventResult event) Source #

Same as `query` but lifted into any monad capable of doing IO.

mkAnyState :: Typeable sub_st => sub_st st -> AnyState st Source #

downcast :: (Typeable sub, Typeable st) => AcidState st -> sub st Source #