Skip to content

Commit

Permalink
refactor storage.py
Browse files Browse the repository at this point in the history
  • Loading branch information
eukaryo committed Jun 18, 2024
1 parent 92ab3f2 commit 15836b8
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions optuna/storages/_rdb/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,9 @@ def _create_new_trial(
"""

# Retry a couple of times. Deadlocks may occur in distributed environments.
# Retry maximum five times. Deadlocks may occur in distributed environments.
error_obj: Exception | None = None
MAX_RETRIES = 5
for n_retries in range(MAX_RETRIES):
for n_retries in range(5):
if n_retries != 0:
# This backoff is to solve retries caused by deadlock.
# This is not an EXPONENTIAL backoff that reduces DB server congestion,
Expand Down Expand Up @@ -492,12 +491,11 @@ def _create_new_trial(
)

return frozen
except sqlalchemy_exc.OperationalError as e:
error_obj = e
raise # It is caught within the function.
except Exception as e:
# `sqlalchemy_exc.OperationalError` will be caught within the function.
# The others will be immediately propagated to the caller.
error_obj = e
raise # The exception is immediately propagated to the caller.
raise
except sqlalchemy_exc.OperationalError:
# Note: According to SQLAlchemy specifications,
# `sqlalchemy_exc.OperationalError` can be raised in situations where
Expand Down

0 comments on commit 15836b8

Please sign in to comment.