Safe Haskell | None |
---|---|
Language | Haskell2010 |
The logged
primitive is used to save the results of the subcomputations
of a transient computation (including all its threads) in a log buffer. At
any point, a suspend
or checkpoint
can be used to save the accumulated
log on a persistent storage. A restore
reads the saved logs and resumes
the computation from the saved checkpoint. On resumption, the saved results
are used for the computations which have already been performed. The log
contains purely application level state, and is therefore independent of the
underlying machine architecture. The saved logs can be sent across the wire
to another machine and the computation can then be resumed on that machine.
We can also save the log to gather diagnostic information.
The following example illustrates the APIs. In its first run suspend
saves
the state in a directory named logs
and exits, in the second run it
resumes from that point and then stops at the checkpoint
, in the third run
it resumes from the checkpoint and then finishes.
main= keep $ restore $ do r <- logged $ choose [1..10 :: Int] logged $ liftIO $ print ("A",r) suspend () logged $ liftIO $ print ("B",r) checkpoint liftIO $ print ("C",r)
Synopsis
- class (Show a, Read a, Typeable a) => Loggable a where
- serialize :: a -> Builder
- deserializePure :: ByteString -> Maybe (a, ByteString)
- deserialize :: TransIO a
- logged :: Loggable a => TransIO a -> TransIO a
- received :: (Loggable a, Eq a) => a -> TransIO ()
- param :: (Loggable a, Typeable a) => TransIO a
- getLog :: TransMonad m => m Log
- exec :: Builder
- wait :: Builder
- emptyLog :: Log
- suspend :: Typeable a => a -> TransIO a
- checkpoint :: TransIO ()
- rerun :: String -> TransIO a -> TransIO a
- restore :: TransIO a -> TransIO a
- data Log = Log {
- recover :: Bool
- buildLog :: Builder
- fulLog :: Builder
- lengthFull :: Int
- hashClosure :: Int
- toLazyByteString :: Builder -> ByteString
- byteString :: ByteString -> Builder
- lazyByteString :: ByteString -> Builder
- newtype Raw = Raw ByteString
Documentation
class (Show a, Read a, Typeable a) => Loggable a where Source #
Nothing
serialize :: a -> Builder Source #
deserializePure :: ByteString -> Maybe (a, ByteString) Source #
deserialize :: TransIO a Source #
Instances
logged :: Loggable a => TransIO a -> TransIO a Source #
Run the computation, write its result in a log in the state
and return the result. If the log already contains the result of this
computation (restore
d from previous saved state) then that result is used
instead of running the computation again.
logged
can be used for computations inside a nother logged
computation. Once
the parent computation is finished its internal (subcomputation) logs are
discarded.
getLog :: TransMonad m => m Log Source #
suspend :: Typeable a => a -> TransIO a Source #
Saves the logged state of the current computation that has been
accumulated using logged
, and then exit
s using the passed parameter as
the exit code. Note that all the computations before a suspend
must be
logged
to have a consistent log state. The logs are saved in the logs
subdirectory of the current directory. Each thread's log is saved in a
separate file.
checkpoint :: TransIO () Source #
Saves the accumulated logs of the current computation, like suspend
, but
does not exit.
rerun :: String -> TransIO a -> TransIO a Source #
Reads the saved logs from the logs
subdirectory of the current
directory, restores the state of the computation from the logs, and runs the
computation. The log files are maintained.
It could be used for the initial configuration of a program.
restore :: TransIO a -> TransIO a Source #
Reads the saved logs from the logs
subdirectory of the current
directory, restores the state of the computation from the logs, and runs the
computation. The log files are removed after the state has been restored.
toLazyByteString :: Builder -> ByteString #
Execute a Builder
and return the generated chunks as a lazy ByteString
.
The work is performed lazy, i.e., only when a chunk of the lazy ByteString
is forced.
byteString :: ByteString -> Builder #
Create a Builder
denoting the same sequence of bytes as a strict
ByteString
.
The Builder
inserts large ByteString
s directly, but copies small ones
to ensure that the generated chunks are large on average.
lazyByteString :: ByteString -> Builder #
Create a Builder
denoting the same sequence of bytes as a lazy
ByteString
.
The Builder
inserts large chunks of the lazy ByteString
directly,
but copies small ones to ensure that the generated chunks are large on
average.