Thomas Steinacher schrieb:
> James Bennett wrote:
>> On 10/16/06, gabor <[EMAIL PROTECTED]> wrote:
>>> would you use something in the db? (from what i know about transactions
>>> (very little :), they "solve" the potential conflicts by simply
>>> reporting an error-condition to one of the "writers", so then he has to
>>> retry. but is there some simply (multiprocess-usable) way to lock (as in
>>> "wait until this guy is finished")?
>> http://www.postgresql.org/docs/8.1/static/sql-lock.html
> 
> This is PostgreSQL specific. There seems also to be something like that
> for MySQL: http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html (it
> looks like you have to do an UNLOCK TABLES on MySQL, whereas PostgreSQL
> releases the lock at transaction end).

Speaking of this, I also miss a way to do SELECT ... FOR UPDATE.

> Shouldn't there be a function built-in into Django that locks the table
> (if the database supports it)? IMHO functions like get_or_create()
> should try to lock and unlock the table automatically.

Oh no! Are you aware of the impact you can get when you lock a 
table under heavy load? This is really very specific of your 
application. Maybe for your case it's fine to lock the entire 
table. Others might specify more rigid unique constraints and 
deal with the exceptions; sometimes a SELECT ... FOR UPDATE is 
the right thing.

> I am not doing critical operations like transferring money, but I
> noticed that the race condition happens quite often when using
> get_or_create and a lot of AJAX requests, so I need to find a solution.

It seems you need to spend more thoughts on multi user issues 
within your application. It's easy to fall for that in the 
beginning, but you need to deal with concurrent access. You must 
be aware for all transactions what impact other transactions can 
have. There is no silver bullet ... (please repeat ;-)

> I will try using PostgreSQL instead of SQLite, maybe this will reduce
> the probability of the race condition to happen ;-)

Hmm, this might be a first step, but it won't magically solve all 
multi user issues. This *is* hard stuff.

Michael


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to