Skip to content

Commit

Permalink
Added the exponential backoff code
Browse files Browse the repository at this point in the history
  • Loading branch information
jprakash-db committed Nov 11, 2024
1 parent ecdddba commit 42a1b0a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/databricks/sql/auth/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,27 @@ def sleep_for_retry(self, response: BaseHTTPResponse) -> bool:
"""
retry_after = self.get_retry_after(response)
if retry_after:
backoff = self.get_backoff_time()
backoff = self.get_exponential_backoff()
proposed_wait = max(backoff, retry_after)
self.check_proposed_wait(proposed_wait)
time.sleep(proposed_wait)
return True

return False

def get_exponential_backoff(self) -> float:
"""
This method implements the exponential backoff algorithm to calculate the delay between retries.
:return:
"""

current_attempt = self.stop_after_attempts_count - self.total
proposed_backoff = (2**current_attempt) * self.delay_min
proposed_backoff = min(proposed_backoff, self.delay_max)
self.check_proposed_wait(proposed_backoff)

return proposed_backoff

def get_backoff_time(self) -> float:
"""Calls urllib3's built-in get_backoff_time.
Expand Down
4 changes: 2 additions & 2 deletions src/databricks/sql/thrift_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
# - 900s attempts-duration lines up w ODBC/JDBC drivers (for cluster startup > 10 mins)
_retry_policy = { # (type, default, min, max)
"_retry_delay_min": (float, 1, 0.1, 60),
"_retry_delay_max": (float, 60, 5, 3600),
"_retry_stop_after_attempts_count": (int, 30, 1, 60),
"_retry_delay_max": (float, 30, 5, 3600),
"_retry_stop_after_attempts_count": (int, 5, 1, 60),
"_retry_stop_after_attempts_duration": (float, 900, 1, 86400),
"_retry_delay_default": (float, 5, 1, 60),
}
Expand Down

0 comments on commit 42a1b0a

Please sign in to comment.