Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry when the BQ job error can be retried #31350

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions sdks/python/apache_beam/io/gcp/bigquery_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,9 +651,19 @@ def wait_for_bq_job(self, job_reference, sleep_duration_sec=5, max_retries=0):
job_reference.projectId, job_reference.jobId, job_reference.location)
logging.info('Job %s status: %s', job.id, job.status.state)
if job.status.state == 'DONE' and job.status.errorResult:
raise RuntimeError(
'BigQuery job {} failed. Error Result: {}'.format(
job_reference.jobId, job.status.errorResult))
if 'Retrying may solve the problem.' in job.status.errorResult.message:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood correctly, at this point the job is already completed as "DONE" and with error.

self.get_job(...) is just a GET call to get. the BigQuery load job status. It won't retry the load job.

The current retry logic is to poll existing job, and this poll API call can intermittently fail and get retried

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So retry poll job when a job status returned DONE with errorResult, it won't actually retry the load job.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. Close this.

logging.info(
'BigQuery job %s failed but can be retried. '
'Error Result: %s',
job_reference.jobId,
job.status.errorResult)
time.sleep(sleep_duration_sec)
if max_retries != 0 and retry >= max_retries:
raise RuntimeError('The maximum number of retries has been reached')
else:
raise RuntimeError(
'BigQuery job {} failed. Error Result: {}'.format(
job_reference.jobId, job.status.errorResult))
elif job.status.state == 'DONE':
return True
else:
Expand Down
Loading