GoogleCloudPlatform / GoogleCloudPlatform/professional-services-data-validator
Configure modified retry for uploading partition yamls to GCS
- Dominant language
- Python
- Stars
- 524
- Forks
- 171
- Avg merge
- 5d 15h
- Merged PRs (30d)
- 4
Description
When uploading a large number of yamls to GCS (10,000) we are encountering a 503 error. This indicates the connection to GCS was interrupted, and is commonly encountered when uploading a large number of files via python.
The exact error message:
'Request failed with status code', 503, 'Expected one of',
The recommendation with 5xx errors is to retry, and we have some sample code as a reference: https://github.com/googleapis/python-storage/blob/main/samples/snippets/storage_configure_retries.py#L55
The request is to please modify _write_gcs_file in gcs_helper.py to use retries.
Suggestion (based on above sample code):
```
from google.cloud import storage
from google.cloud.storage.retry import DEFAULT_RETRY
def _write_gcs_file(file_path: str, data: str):
gcs_bucket = get_gcs_bucket(file_path)
blob = gcs_bucket.blob(_get_gcs_file_path(file_path))
modified_retry = DEFAULT_RETRY.with_deadline(500.0)
modified_retry = modified_retry.with_delay(initial=1.5, multiplier=1.2, maximum=45.0)
blob.upload_from_string(data, **retry=modified_retry**)
```
Ideally, the values (deadline, initial, multiplier, maximum) can be parameterized, so that end users can modify the values to get optimal performance.
Contributor guide
Assessment
This issue has not been assessed yet.