zodb/relstorage — pull request #18 by jamadden (2014-09-03 15:04:09+00:00)
Title: Raise a specific exception when acquiring the commit lock fails.

Like other issues and pull requests have noted, the global commit lock can sometimes become a bottleneck. Because this issue is most often due to transient issues like high write loads which in certain scenarios may be recoverable (e.g., by backing off and retrying), it can be useful to specifically catch the exception thrown in that case. A plain `StorageError` can have many meanings, and the different text messages used between databases means it's not necessarily portably reliable to try to distinguish this case based on the message alone.

This PR adds a specific exception that the `ILocker` instances throw when getting a commit lock fails. For backwards compatibility, it is a subclass of `StorageError`. It does not mixin `transaction.interfaces.TransientError` (even though it *is* probably transient) because that would probably result in behaviour changes as middleware transaction managers would start retrying on this case, which may actually increase database load and commit lock failures. Therefore, users would still need to account for this case explicitly.

Internally, we've been using a monkey-patched version of this technique and it has been useful for us to be able to distinguish this case. Although we haven't had a use case for them, I can add specific exception subclasses for the other errors thrown by locker.py in this or another PR. I'm very open to any comments or suggestions.