Skip to content
Snippets Groups Projects
Commit d6f59dc8 authored by Simon Künzel's avatar Simon Künzel
Browse files

Improve database conflict logging

parent cc919e54
No related branches found
No related tags found
No related merge requests found
......@@ -201,6 +201,8 @@ class Database:
transaction.rollback()
except Exception:
pass
if attempts > 1:
print(f"Reattempt of transaction which had conflict was successful after {attempts} attempts")
return result
except Exception as e:
is_conflict = Database._is_transaction_conflict_exception(e)
......@@ -220,12 +222,13 @@ class Database:
self._on_transaction_conflict(writeable)
if attempts >= (self._max_write_attempts if writeable else self._max_read_attempts):
self._on_transaction_aborted_after_repeated_conflict(writeable)
print(f"Warning: Transaction failed due to conflict after {attempts} attempts", file=sys.stderr)
raise TransactionConflictError(e)
# Sleep a random time for up to 500ms to increase chance that next attempt succeeds (The randomness makes
# it more likely that we reattempt at a different time than the one with which we are in conflict right now)
time.sleep(random.random() / 2)
print("Warning: Reattempting transaction after commit conflict", file=sys.stderr)
print("Warning: Reattempting transaction after commit conflict:", file=sys.stderr)
traceback.print_exception(e)
continue
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment