Thursday, March 05, 2009

The Optimistic Oracle

Every now and then we get the error "ORA-08177: can't serialize access for this transaction" in an application at work. It's usually on small bits of code that are AJAX like (I never write true AJAX and I'm not sure it happens all that often) and could be run frequently by the user by just clicking a button a few times. My assumption is that its an over zealous person double clicking and therefore double running the code that causes the problem. Anyway, I looked up the issue and just thought this was interesting:

You'll get this message whenever you try to update a row that has changed since your transaction began. (Note that Oracle tries to do this purely at the row level, but you may receive an ORA-01877 error even when the row you're interested in modifying hasn't been modified. The ORA-01877 may happen due to some other row(s) being modified on the block that contains your row.)

Oracle Database takes an optimistic approach to serialization: it gambles on the fact that the data your transaction wants to update won't be updated by any other transaction. This is typically the way it happens, and usually the gamble pays off, especially in quick transaction, OLTP-type systems. If no one else updates your data during your transaction, this isolation level, which will generally decrease concurrency in other systems, will provide the same degree of concurrency as it would without SERIALIZABLE transactions. The downside is that you may get the ORA-08177 error if the gamble doesn't pay off. If you think about it, however, it's worth the risk. If you're using SERIALIZABLE transaction, you shouldn't expect to update the same information as other transactions.


http://www.oracle.com/technology/oramag/oracle/05-nov/o65asktom.html

No comments: