Skip to content

Commit 12e87a4

Browse files
mark-majorFokko
andauthored
Boto Glue standard retry policy with configuration (#1307)
* boto glue standard retry policy configurable max retry * Update configuration.md Co-authored-by: Fokko Driesprong <[email protected]> * Update glue.py Co-authored-by: Fokko Driesprong <[email protected]> * boto glue retry mode configurable --------- Co-authored-by: Fokko Driesprong <[email protected]>
1 parent 150fa0c commit 12e87a4

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

mkdocs/docs/configuration.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -331,16 +331,18 @@ catalog:
331331

332332
<!-- markdown-link-check-disable -->
333333

334-
| Key | Example | Description |
335-
| ---------------------- | ------------------------------------ | ------------------------------------------------------------------------------- |
336-
| glue.id | 111111111111 | Configure the 12-digit ID of the Glue Catalog |
337-
| glue.skip-archive | true | Configure whether to skip the archival of older table versions. Default to true |
334+
| Key | Example | Description |
335+
|------------------------|----------------------------------------|---------------------------------------------------------------------------------|
336+
| glue.id | 111111111111 | Configure the 12-digit ID of the Glue Catalog |
337+
| glue.skip-archive | true | Configure whether to skip the archival of older table versions. Default to true |
338338
| glue.endpoint | <https://glue.us-east-1.amazonaws.com> | Configure an alternative endpoint of the Glue service for GlueCatalog to access |
339-
| glue.profile-name | default | Configure the static profile used to access the Glue Catalog |
340-
| glue.region | us-east-1 | Set the region of the Glue Catalog |
341-
| glue.access-key-id | admin | Configure the static access key id used to access the Glue Catalog |
342-
| glue.secret-access-key | password | Configure the static secret access key used to access the Glue Catalog |
343-
| glue.session-token | AQoDYXdzEJr... | Configure the static session token used to access the Glue Catalog |
339+
| glue.profile-name | default | Configure the static profile used to access the Glue Catalog |
340+
| glue.region | us-east-1 | Set the region of the Glue Catalog |
341+
| glue.access-key-id | admin | Configure the static access key id used to access the Glue Catalog |
342+
| glue.secret-access-key | password | Configure the static secret access key used to access the Glue Catalog |
343+
| glue.session-token | AQoDYXdzEJr... | Configure the static session token used to access the Glue Catalog |
344+
| glue.max-retries | 10 | Configure the maximum number of retries for the Glue service calls |
345+
| glue.retry-mode | standard | Configure the retry mode for the Glue service. Default to standard. |
344346

345347
<!-- markdown-link-check-enable-->
346348

pyiceberg/catalog/glue.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
)
3030

3131
import boto3
32+
from botocore.config import Config
3233
from mypy_boto3_glue.client import GlueClient
3334
from mypy_boto3_glue.type_defs import (
3435
ColumnTypeDef,
@@ -128,6 +129,14 @@
128129
GLUE_ACCESS_KEY_ID = "glue.access-key-id"
129130
GLUE_SECRET_ACCESS_KEY = "glue.secret-access-key"
130131
GLUE_SESSION_TOKEN = "glue.session-token"
132+
GLUE_MAX_RETRIES = "glue.max-retries"
133+
GLUE_RETRY_MODE = "glue.retry-mode"
134+
135+
MAX_RETRIES = 10
136+
STANDARD_RETRY_MODE = "standard"
137+
ADAPTIVE_RETRY_MODE = "adaptive"
138+
LEGACY_RETRY_MODE = "legacy"
139+
EXISTING_RETRY_MODES = [STANDARD_RETRY_MODE, ADAPTIVE_RETRY_MODE, LEGACY_RETRY_MODE]
131140

132141

133142
def _construct_parameters(
@@ -297,6 +306,8 @@ class GlueCatalog(MetastoreCatalog):
297306
def __init__(self, name: str, **properties: Any):
298307
super().__init__(name, **properties)
299308

309+
retry_mode_prop_value = get_first_property_value(properties, GLUE_RETRY_MODE)
310+
300311
session = boto3.Session(
301312
profile_name=properties.get(GLUE_PROFILE_NAME),
302313
region_name=get_first_property_value(properties, GLUE_REGION, AWS_REGION),
@@ -305,7 +316,16 @@ def __init__(self, name: str, **properties: Any):
305316
aws_secret_access_key=get_first_property_value(properties, GLUE_SECRET_ACCESS_KEY, AWS_SECRET_ACCESS_KEY),
306317
aws_session_token=get_first_property_value(properties, GLUE_SESSION_TOKEN, AWS_SESSION_TOKEN),
307318
)
308-
self.glue: GlueClient = session.client("glue", endpoint_url=properties.get(GLUE_CATALOG_ENDPOINT))
319+
self.glue: GlueClient = session.client(
320+
"glue",
321+
endpoint_url=properties.get(GLUE_CATALOG_ENDPOINT),
322+
config=Config(
323+
retries={
324+
"max_attempts": properties.get(GLUE_MAX_RETRIES, MAX_RETRIES),
325+
"mode": retry_mode_prop_value if retry_mode_prop_value in EXISTING_RETRY_MODES else STANDARD_RETRY_MODE,
326+
}
327+
),
328+
)
309329

310330
if glue_catalog_id := properties.get(GLUE_ID):
311331
_register_glue_catalog_id_with_glue_client(self.glue, glue_catalog_id)

tests/catalog/test_glue.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ def test_list_tables(
442442
moto_endpoint_url: str,
443443
table_schema_nested: Schema,
444444
database_name: str,
445-
table_name: str,
446445
table_list: List[str],
447446
) -> None:
448447
test_catalog = GlueCatalog("glue", **{"s3.endpoint": moto_endpoint_url, "warehouse": f"s3://{BUCKET_NAME}/"})

0 commit comments

Comments
 (0)