At 12:40 PM 7/30/2006, you wrote:
Hello!

Am 30.07.2006 um 18:40 schrieb mos:

The Cayenne framework is using a a single table to keep the primary
keys (PK) for its objects. The method accessing this table is
surrounded by lock / unlock commands, so no other thread can read the
same PK from the table while another thread is currently reading and
incrementing the PK. Each thread accessing the table is incrementing
the value by 20 for caching PK values to reduce the load on the
database.

I assume you are using WRITE locks and not READ locks, correct?
Because READ locks won't prevent other threads from reading the
table value. Something like this should work: (I'm using MyISAM but
it should still work with InnoDb.)

It's also a read lock, no thread can read the table until the the
unlock command has been issued. This has been tested in functionality
as well as load tests already.

Really?? Here it is from the MySQL manual (horse's mouth):

http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html
>>If a thread obtains a READ lock on a table, that thread (and all other threads) can only read from the table. If a thread obtains a WRITE lock on a table, only the thread holding the lock can write to the table. Other threads are blocked from reading or writing the table until the lock has been released. <<

I interpreted that to mean other threads can still read from the table if there is a read lock. A write lock, like the one I used in my sample code that I posted, will prevent others from *reading* the table while someone else is updating it and getting the next rcd_id. This isolates the rcd_id so only 1 thread can read or write to it at a time (the thread can only read it when it is available to be updated-no write lock). I tried my code and it works just fine by forcing the other thread to wait until the other thread's lock has completed.

Mike



When you lose the connection and reconnect, can you not clear the
cache for the autoinc table so it gets the current value?

The framework does that, after reconnecting it does reread the PK
values. The problem must be somewhere else...

Christian






--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to