|
77 | 77 | from pyiceberg.typedef import EMPTY_DICT, UTF8, IcebergBaseModel, Identifier, Properties |
78 | 78 | from pyiceberg.types import transform_dict_value_to_str |
79 | 79 | from pyiceberg.utils.deprecated import deprecation_message |
80 | | -from pyiceberg.utils.properties import get_first_property_value, get_header_properties, property_as_bool |
| 80 | +from pyiceberg.utils.properties import get_first_property_value, get_header_properties, property_as_bool, property_as_int |
81 | 81 |
|
82 | 82 | if TYPE_CHECKING: |
83 | 83 | import pyarrow as pa |
@@ -223,6 +223,10 @@ class IdentifierKind(Enum): |
223 | 223 | SIGV4 = "rest.sigv4-enabled" |
224 | 224 | SIGV4_REGION = "rest.signing-region" |
225 | 225 | SIGV4_SERVICE = "rest.signing-name" |
| 226 | +SIGV4_MAX_RETRIES = "rest.sigv4.max-retries" |
| 227 | +SIGV4_DEFAULT_MAX_RETRIES = 10 |
| 228 | +SIGV4_RETRY_BACKOFF_FACTOR = 0.5 |
| 229 | +SIGV4_RETRY_STATUS_CODES = (429, 500, 502, 503, 504) |
226 | 230 | EMPTY_BODY_SHA256: str = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" |
227 | 231 | OAUTH2_SERVER_URI = "oauth2-server-uri" |
228 | 232 | SNAPSHOT_LOADING_MODE = "snapshot-loading-mode" |
@@ -680,11 +684,25 @@ def _init_sigv4(self, session: Session) -> None: |
680 | 684 | from botocore.awsrequest import AWSRequest |
681 | 685 | from requests import PreparedRequest |
682 | 686 | from requests.adapters import HTTPAdapter |
| 687 | + from urllib3.util.retry import Retry |
683 | 688 |
|
684 | 689 | class SigV4Adapter(HTTPAdapter): |
685 | 690 | def __init__(self, **properties: str): |
686 | | - super().__init__() |
687 | 691 | self._properties = properties |
| 692 | + max_retries = property_as_int(self._properties, SIGV4_MAX_RETRIES, SIGV4_DEFAULT_MAX_RETRIES) |
| 693 | + super().__init__( |
| 694 | + max_retries=Retry( |
| 695 | + total=max_retries, |
| 696 | + status=max_retries, |
| 697 | + connect=max_retries, |
| 698 | + read=max_retries, |
| 699 | + # Keep retries conservative for idempotent calls. |
| 700 | + allowed_methods=frozenset({"GET", "HEAD", "OPTIONS"}), |
| 701 | + status_forcelist=SIGV4_RETRY_STATUS_CODES, |
| 702 | + backoff_factor=SIGV4_RETRY_BACKOFF_FACTOR, |
| 703 | + respect_retry_after_header=True, |
| 704 | + ) |
| 705 | + ) |
688 | 706 | self._boto_session = boto3.Session( |
689 | 707 | region_name=get_first_property_value(self._properties, AWS_REGION), |
690 | 708 | botocore_session=self._properties.get(BOTOCORE_SESSION), |
|
0 commit comments