From: Gavin_King/Cirrus%<CI...@ci...> - 2002-02-20 08:21:39
|
> thanx 4 your prompt reply. NP, we are in same timezone :) > regarding the HiLoGenerator, there were two things. > 1. the sychronised block through me - which u have explained already > 2. i wasn't sure if the RDBMS would hold a lock between the select and the > update. (whenever i have had to this in the past it has been through stored > procedures where the locking was explicitely specified.) True, this all depends upon your transaction isolation level. Read Committed + Read Uncommitted: broken, you can't use HiLoGenerator Repeatable Read + Serializable: works fine. (Very) slight risk of a transaction rollback Of course, there is only a slight risk of two machines reading the HiLo table simultaneously. There are many other much bigger dangers in using read committed as your isolation level. However, for certain kinds of applications read committed is often used (and stupid oracle doesn't even support repeatable read). hmmmm...I suppose it also breaks HiLoGenerator if you turn off transactions and use optimistic locking! Okay then. Possible solutions: (0) simply document the fact that HiLoGenerator is meant to be used where the isolation level is at least repeatable read. (otherwise use the UUID generator) (1) use a select for update. but "for update" is not supported on all platforms (specifically not sybase, one of my favorites) (2) add a where clause to the update "update hilo set next=10 where next=9" and retry if no rows are updated. I will implement (2) it seems like a good solution. I am ccing this to the devel mailing list. Thanks for drawing it to my attention. Gavin |