Ma77Ball commented on code in PR #5667:
URL: https://github.com/apache/texera/pull/5667#discussion_r3412650581
##########
amber/src/main/python/pytexera/storage/dataset_file_document.py:
##########
@@ -19,6 +19,34 @@
import os
import requests
import urllib.parse
+from requests.adapters import HTTPAdapter
+from urllib3.util.retry import Retry
+
+# (connect, read) timeout and retry settings for the file-service GETs below.
+_CONNECT_TIMEOUT_SECONDS = 10
+_READ_TIMEOUT_SECONDS = 60
+_REQUEST_TIMEOUT = (_CONNECT_TIMEOUT_SECONDS, _READ_TIMEOUT_SECONDS)
+_MAX_RETRIES = 3
+_RETRY_BACKOFF_FACTOR = 0.5
+_RETRY_STATUS_FORCELIST = (500, 502, 503, 504)
+
+
+def _build_session() -> requests.Session:
+ """Returns a Session that retries GETs on connection errors and 5xx."""
+ retry = Retry(
+ total=_MAX_RETRIES,
+ connect=_MAX_RETRIES,
+ read=_MAX_RETRIES,
+ backoff_factor=_RETRY_BACKOFF_FACTOR,
+ status_forcelist=_RETRY_STATUS_FORCELIST,
+ allowed_methods=frozenset({"GET"}),
+ raise_on_status=False,
+ )
+ adapter = HTTPAdapter(max_retries=retry)
+ session = requests.Session()
+ session.mount("http://", adapter)
+ session.mount("https://", adapter)
+ return session
Review Comment:
Done: moved the timeout/retry constants and `_build_session` into
`DatasetFileDocument` (class attributes + `@classmethod`), so no module-level
state remains.
##########
amber/src/main/python/pytexera/storage/dataset_file_document.py:
##########
@@ -19,6 +19,34 @@
import os
import requests
import urllib.parse
+from requests.adapters import HTTPAdapter
+from urllib3.util.retry import Retry
+
+# (connect, read) timeout and retry settings for the file-service GETs below.
+_CONNECT_TIMEOUT_SECONDS = 10
+_READ_TIMEOUT_SECONDS = 60
+_REQUEST_TIMEOUT = (_CONNECT_TIMEOUT_SECONDS, _READ_TIMEOUT_SECONDS)
+_MAX_RETRIES = 3
+_RETRY_BACKOFF_FACTOR = 0.5
+_RETRY_STATUS_FORCELIST = (500, 502, 503, 504)
+
+
+def _build_session() -> requests.Session:
+ """Returns a Session that retries GETs on connection errors and 5xx."""
+ retry = Retry(
+ total=_MAX_RETRIES,
+ connect=_MAX_RETRIES,
+ read=_MAX_RETRIES,
+ backoff_factor=_RETRY_BACKOFF_FACTOR,
+ status_forcelist=_RETRY_STATUS_FORCELIST,
+ allowed_methods=frozenset({"GET"}),
+ raise_on_status=False,
+ )
+ adapter = HTTPAdapter(max_retries=retry)
+ session = requests.Session()
+ session.mount("http://", adapter)
+ session.mount("https://", adapter)
+ return session
Review Comment:
Yes: `requests.get()` has no retry option; urllib3's `Retry` only applies
when mounted as an `HTTPAdapter` on a `Session`. The alternative is a manual
retry loop. Open to other approaches.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]