[Haskell-cafe] STM commit hooks
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.
On Nov 29, 2005, at 12:39 PM, Einar Karttunen wrote:
> 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
> the commit that works?
More information about the Haskell-Cafe