Pete Yandell

Results 8 comments of Pete Yandell

It's been a while, and this is complicated, but it goes something like this: You want to grab all your locks at the start of the transaction, and do them...

Or, put another way: You want reliable locking and deadlock handling? Hard things are hard.

Yep. If you don't do all your locking in one place and in a consistent order, you're _way_ more likely to get deadlocks.

I'm not sure whether Postgres behaves the same way.

> Maybe there is a way to improve this API? I don't think there is a way to improve the locking without either a) changing ActiveRecord's behaviour, b) changing MySQL's...

The `AccountBalance` records exist primarily to enable locking! If you don't do per-account locks somehow, the totals in the `lines` table will get out of whack because of race conditions...

@eadz: There's definitely a lot of complexity in there to support lazy creation of account balances. And yes, you could simplify things if you assumed all account balances were created...

Deadlocks are the problem because of ActiveRecord and MySQL having broken behaviour around them. If you get a deadlock in a nested transaction, ActiveRecord behaves as though just the inner...