[Nitro] Og, serialized transactions?

Reid Thompson reid.thompson at ateb.com
Sun Feb 25 19:42:48 EST 2007


On 13:59 Sat 24 Feb     , Bill Kelly wrote:
> From: "Judson Lester" <nyarly at gmail.com>
> >
> > On 2/22/07, Jonathan Buch <john at oxyliquit.de> wrote:
> >
> >> I'm not sure we can make MySQL thread safe (as I think the standard table
> >> type doesn't react on 'transaction' anyway).  Maybe we put a ruby-level
> >> synchronized around that part?
> >
> > Trouble is, when you have a db involved, process level locks aren't
> > really enough. Slows down execution without real benefit.  This is why
> > MySQL's eternal claim that transactions were unnecessary has always
> > galled me.
>
> Hi,
>
> On a related note, I'm wanting to use Og with postgres and
> have dozens of processes all interacting with the same
> database.
>
> If several processes all happened to do a find_or_create
> at the same time with the same name:
>
>   playername = Playername.find_or_create_by_playername("fred")
>
> ...I'm concerned about how to eliminate the possibility of
> a race condition where I could end up with more than one
> "fred" player record being created.
>
> I haven't tried this yet, but I'm hoping something like the
> following would work:
>
>   store = Playername.ogstore
>   store.transaction {
>     store.exec "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE"
>     playername = Playername.find_or_create_by_playername("fred")
>   }
>
> Am I on the right track here?  (I presume I'll have to deal
> with catching an exception and retrying the transaction if
> it fails.)
>
>
> Thanks,
>
> Bill
>
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general
make playername unique - return an approprite response to the process
that attempts to create a duplicate player, and handle it
appropriately.l



More information about the Nitro-general mailing list