Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package registry
Container registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
videoag
backend
Commits
66e3f754
Commit
66e3f754
authored
2 months ago
by
Simon Künzel
Browse files
Options
Downloads
Patches
Plain Diff
Improve transaction conflict handling
parent
156be9f5
No related branches found
No related tags found
No related merge requests found
Pipeline
#7572
passed
2 months ago
Stage: build
Stage: run
Pipeline: backend
#7573
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
common_py/src/videoag_common/database/database.py
+5
-0
5 additions, 0 deletions
common_py/src/videoag_common/database/database.py
with
5 additions
and
0 deletions
common_py/src/videoag_common/database/database.py
+
5
−
0
View file @
66e3f754
import
os
import
random
import
sys
import
time
from
enum
import
StrEnum
from
typing
import
Callable
,
TypeVar
,
TypeVarTuple
,
Sequence
...
...
@@ -218,6 +220,9 @@ class Database:
if
attempts
>=
(
self
.
_max_write_attempts
if
writeable
else
self
.
_max_read_attempts
):
self
.
_on_transaction_aborted_after_repeated_conflict
(
writeable
)
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
)
continue
raise
AssertionError
(
"
This should be unreachable code
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment