[Haskell-cafe] STM commit hooks

Joel Reymont joelr1 at gmail.com
Mon Dec 12 05:40:49 EST 2005


I haven't seen a reply on this but would be really interested in one.

Simon?

On Nov 29, 2005, at 12:39 PM, Einar Karttunen wrote:

> Hello
>
> I have been playing with STM and want to log transactions to disk.
> Defining a logging function like:
>
> log h act = unsafeIOToSTM $ hPrint h act
>
> works most the time. Aborts can be handled with:
>
> abort h = log h Abort >> retry
> atomic' h act = atomically (act `orElse` abort h)
>
> But is it possible to handle a commit?
>
> commit h = unsafeIOToSTM (hPrint h Commit >> hSync h)
> atomically2 h act = atomically ((act >> commit h) `orElse` abort h)
>
> This won't work because the transaction is validated and
> maybe aborted after the commit is logged to disk.
>
> Another alternative would be:
>
> atomically3 h act = atomically (act `orElse` abort h) >> atomically  
> (commit h)
>
> But this does not work either. Given Trx1 and Trx2, the following  
> may occur:
>
> 1) Trx1 commits
> <thread switch>
> 2) Trx2 commits (and depends on Trx1)
> 3) Trx2 commit is logged to disk
> <system crash>
>
> This means that the log would be inconsistent. Is there a way to  
> implement
> the commit that works?

--
http://wagerlabs.com/







More information about the Haskell-Cafe mailing list