diff --git a/common_py/src/videoag_common/database/database.py b/common_py/src/videoag_common/database/database.py index 079c9b7dc1dfd47e97605e24514d8b8edb8038a1..a306e647964af4bbd7d752ea041c41c1afb50378 100644 --- a/common_py/src/videoag_common/database/database.py +++ b/common_py/src/videoag_common/database/database.py @@ -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