[storm] recovering from a transactionrollbackerror
Stuart Bishop
stuart at stuartbishop.net
Thu May 14 06:35:50 BST 2009
On Mon, May 11, 2009 at 11:05 PM, Martin DeMello
<martindemello at gmail.com> wrote:
> Nevermind, thought a bit about this and unless storm keeps track of
> the "dirty" status of individual columns in a row, it's probably not
> doable. Would still like to hear about people's general strategies for
> handling rows that need to be updated concurrently by multiple
> processes.
The general pattern is:
success = False
while not success:
try:
do_stuff()
store.commit()
transaction_succeeded = True
except retry_exceptions:
pass
def do_stuff():
try:
[do something]
except:
[cleanup non-DB stuff and revert non-DB changes]
raise
retry_exceptions is the list of exceptions you want to retry on -
serializable if you are running in serializable isolation,
disconnection exceptions, failed commit. For our main application, we
also retry integrityerrors a few times in case they where triggered by
other concurrent connections changing data. Add some exponentially
backing off sleeps to avoid death spirals when, say, the DB has run
out of disk space if you want.
--
Stuart Bishop <stuart at stuartbishop.net>
http://www.stuartbishop.net/
More information about the storm
mailing list