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.State.Acid.Core).
- data AcidState st
- data Event st where
- type EventResult ev = MethodResult ev
- class Method ev => UpdateEvent ev
- class Method ev => QueryEvent ev
- data Update st a
- data Query st a
- mkAcidState :: (Typeable st, Binary st) => [Event st] -> st -> IO (AcidState st)
- closeAcidState :: AcidState st -> IO ()
- createCheckpoint :: Binary st => AcidState st -> IO ()
- update :: UpdateEvent event => AcidState st -> event -> IO (EventResult event)
- query :: QueryEvent event => AcidState st -> event -> IO (EventResult event)
State container offering full ACID (Atomicity, Consistency, Isolation and Durability) guarantees.
- State changes are all-or-nothing. This is what you'd expect of any state variable in Haskell and AcidState doesn't change that.
- No event or set of events will break your data invariants. This includes power outages,
- Transactions cannot interfere with each other even when issued in parallel.
- Successful transaction are guaranteed to survive system failure (both hardware and software).
We distinguish between events that modify the state and those that do not.
UpdateEvents are executed in a MonadState context and have to be serialized to disk before they are considered durable.
QueryEvents are executed in a MonadReader context and obviously do not have to be serialized to disk.
Events return the same thing as Methods. The exact type of
depends on the event.
|:: (Typeable st, Binary st)|
|=> [Event st]|
List of events capable of updating or querying the state.
Initial state value. This value is only used if no checkpoint is found.
|-> IO (AcidState st)|
Create an AcidState given a list of events (aka. transactions) and an initial value.
This will create or resume a log found in the "state/[typeOf state]/" directory.
Close an AcidState and associated logs. Any subsequent usage of the AcidState will throw an exception.
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.
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.