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

Fix ReadAllFromBigQuery leak temp dataset #31895

Merged
merged 2 commits into from
Jul 16, 2024
Merged

Conversation

Abacn
Copy link
Contributor

@Abacn Abacn commented Jul 15, 2024

Caught by CleanupGCPResource workflow. There are many stale "bq_read_all_" datasets in the test project.

There is a consistent temp dataset leaking for Python SDK's ReadAllFromBigQuery. Each run will leave an empty dataset prefixed "bq_read_all_"

Cause:

  • ReadFromBigQuery sets a default dataset of prefix "bq_read_all_"

self.temp_dataset = temp_dataset or 'bq_read_all_%s' % uuid.uuid4().hex

  • BigQueryWrapper thinks this is a user configured dataset and won't delete it

not self.temp_dataset_id.startswith(self.TEMP_DATASET))

Solution:

Remove the prefix so BigQueryWrapper will use the default temp_dataset_* prefix and will delete it when clean_up_temporary_dataset called

However, this will now create each dataset for each element. To reduce the overload, move create/delete dataset into setup/teardown so that they are per worker basis.

Please add a meaningful description for your change here


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@Abacn
Copy link
Contributor Author

Abacn commented Jul 15, 2024

Tested with
pytest -r s --log-cli-level=INFO --capture=no apache_beam/io/gcp/bigquery_read_it_test.py::ReadAllBQTests::test_read_queries --test-pipeline-options='--runner=DirectRunner --project=... --region=us-central1 --temp_location=gs://.../tmp'

Previously, there is a "bq_read_all..." dataset left

Now, it created one dataset

INFO     apache_beam.io.gcp.bigquery_tools:bigquery_tools.py:816 Dataset ...:beam_temp_dataset_f4dfd535a5ac4d4f9ccd961eb9a084fb does not exist so we will create it as temporary with location=US

and after test run, checked that this dataset no longer exists.

@@ -302,7 +303,7 @@ def _execute_query(
self._job_name,
self._source_uuid,
bigquery_tools.BigQueryJobTypes.QUERY,
'%s_%s' % (int(time.time()), random.randint(0, 1000)))
'%s_%s' % (int(time.time()), secrets.token_hex(3)))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

in alignment with

self.obj_id = '%d_%s' % (int(time.time()), secrets.token_hex(3))

likely the cause of #26343

Copy link
Contributor

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @damccorm for label python.
R: @shunping for label io.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@Abacn
Copy link
Contributor Author

Abacn commented Jul 16, 2024

R: @ahmedabu98

Copy link
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

Copy link
Contributor

@ahmedabu98 ahmedabu98 left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! LGTM

@Abacn Abacn merged commit d74a2f5 into apache:master Jul 16, 2024
89 checks passed
@Abacn Abacn deleted the fixbqreadallleak branch July 16, 2024 15:31
acrites pushed a commit to acrites/beam that referenced this pull request Jul 17, 2024
* Fix ReadAllFromBigQuery leak temp dataset

* Fix potential duplicate job name
@Abacn
Copy link
Contributor Author

Abacn commented Jul 23, 2024

After this change there is still dataset leak. Found that on Dataflow runner DoFn.teardown is never called even if the job ended successfully (on Direct Runner, teardown is called, however).

reeba212 pushed a commit to reeba212/beam that referenced this pull request Dec 4, 2024
* Fix ReadAllFromBigQuery leak temp dataset

* Fix potential duplicate job name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants