Hello.
I have a problem with python implementation in transaction and deadlock handling. The sequence is simple:
1. I'm making the transaction, and then run the reading query and handle deadlocks using DB_TXN_NOWAIT and lazy context evaluation. I'm doing this in one single try-except block. Something like that
try:
context = manager.createQueryContext()
context.setEvaluationType(context.Lazy)
result = query.execute(txn, context)
except XmlException, exp:
# some deadlock and other error handling here
2. In the other try-except block I'm trying to fetch the results using result.next like this:
try:
res = result.next()
except StopIteration:
# No result handling here
So, the problem is that in lazy context the database is queried again, but I cannot catch the XmlException, because only RuntimeError throws if i.e. deadlock happen here like this way:
try:
res = result.next()
except StopIteration:
# No result handling here
except XmlException, exp:
# Deadlock could be here, but this block will never be run
RuntimeError has only string variable, even not having an error code, and I have to parse this string to detect if it is a deadlock error or any other.
I've found a small, but not good-enough(as I think) workaround here:
try:
if result.hasNext():
res = result.next()
else:
# No result handling here
except XmlException, exp:
# Deadlock handling here
In this code I'm still not sure, the operation is atomic, and - as I understand - the possibility of catching RuntimeError instead of XmlException still exists. In addition, I have 2 reading operations instead of 1, so more deadlocks will happen.
Thanks in advance.
UPDATE: Forgot to say, that I'm using the latest release 2.4.16.1