Skip to content

fix(bigquery-jdbc): clamp LargeResultsDatasetExpirationTime to 1h minimum and handle 409 races - #15332

Open
keshavdandeva wants to merge 1 commit into
jdbc/fix-largeResultDataset-validationfrom
jdbc/large-results-3-dataset-acls
Open

keshavdandeva wants to merge 1 commit into
jdbc/fix-largeResultDataset-validationfrom
jdbc/large-results-3-dataset-acls

Conversation

@keshavdandeva

@keshavdandeva keshavdandeva commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Part 2 of 2 in the LargeResultDataset hardening stack (b/584840569), stacked directly on #15257:

Order PR Scope
1 #15257 Property validation, sink-level log sanitization, temp_table_<epochMs>_<uuid> + WRITE_EMPTY, client JobId, internal statement isolation
2 (this PR) #15332 1h minimum LargeResultsDatasetExpirationTime clamp during parameter parsing, 409 Conflict auto-create handling, and dataset error wrapping

(#15331 was decoupled as a standalone draft PR under b/593045100; broader BigQuery API / ephemeral destinationTable capabilities are tracked in b/592582350 and #15333/#15334 are closed.)


Summary of Changes

  1. 1-hour minimum LargeResultsDatasetExpirationTime clamp at parameter parsing (BigQueryJdbcUrlUtility, DataSource):
    • Added BigQueryJdbcUrlUtility.MIN_DESTINATION_DATASET_EXPIRATION_TIME_VALUE = 3600000L.
    • In DataSource.setDestinationDatasetExpirationTime(long), positive values below 1 hour are clamped to 3600000 ms with a LOG.warning(...) during URL/setter parsing (0 continues to fall back to the 1h default without warning for compatibility with existing =0 URLs), preventing BigQuery HTTP 400 rejections on datasets.insert.
  2. 409 Conflict concurrent creation race handling & error wrapping (BigQueryStatement):
    • In checkIfDatasetExistElseCreate(String), treats HTTP 409 Conflict / "duplicate" on datasets.insert as success so concurrent queries racing to auto-create the same LargeResultDataset proceed cleanly.
    • Wraps BigQueryException from getDataset/create into BigQueryJdbcException and sanitizes datasetName in auto-create logs (replacing the misleading "Creating a hidden dataset" message).
  3. Docs & Tests (USER_GUIDE.md, DataSourceTest, BigQueryStatementTest):
    • Documents the 1h clamp and adds unit tests covering sub-hour clamping (setter + URL), valid >= 1h preservation, 409 race handling, and dataset RPC error wrapping.

Follow-Up Issues

  • b/592582350 — BigQuery API / LargeResultDataset ephemeral destination-table design (multi-user ACL isolation, native per-query TTL, lifecycle cleanup).
  • b/592250778 — Per-connection datasets.get caching with 404 invalidation.

Verification

  • make lint (fmt:2.29), Checkstyle (0 violations)
  • Full unit test suite: 1,472 passed, 0 failed (1 pre-existing skip)
  • Diff: 6 files (+186 / −12; +45 / −10 main code)

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request enhances security and concurrency handling when auto-creating destination datasets for large query results. Specifically, it ensures that auto-created datasets are restricted to creator-only OWNER access by stripping default project-wide group ACLs, and enforces a minimum default table lifetime of 1 hour. It also introduces JVM-wide synchronization to safely coordinate concurrent dataset creations and handles rollback deletions if ACL updates fail. Extensive unit and integration tests have been added to verify these behaviors. There are no review comments to address, so I have no additional feedback to provide.

@keshavdandeva
keshavdandeva force-pushed the jdbc/large-results-3-dataset-acls branch from 7d63e05 to 863e0a5 Compare December 1, 2026 17:51
@keshavdandeva
keshavdandeva force-pushed the jdbc/large-results-3-dataset-acls branch from 863e0a5 to 88ab641 Compare December 1, 2026 20:09
@keshavdandeva
keshavdandeva force-pushed the jdbc/large-results-3-dataset-acls branch from 88ab641 to 417addc Compare December 2, 2026 15:39
@keshavdandeva keshavdandeva changed the title fix(bigquery-jdbc): restrict auto-created LargeResultDataset ACLs to creator and enforce 1h minimum TTL fix(bigquery-jdbc): clamp auto-created LargeResultDataset TTL to 1h and handle 409 races Dec 2, 2026
@keshavdandeva

Copy link
Copy Markdown
Contributor Author

Removed all dataset ACL restrictions and LargeResultDestinations / BigQueryConnection.resolveOwnerEmail() per @logachev's feedback, and filed b/592582350 covering the shared-dataset ACL lockout scenario along with native per-query TTL and broader LargeResultDataset / destinationTable lifecycle design (and closed #15333 and #15334).

This PR is now trimmed down to just the non-ACL checkIfDatasetExistElseCreate fixes (+43/−11 main lines):

  • Clamp auto-created dataset defaultTableLifetime to BigQuery's 1h minimum (3600000 ms) to avoid 400 rejections.
  • Handle 409 Conflict when two queries race to auto-create the same dataset.
  • Wrap BigQueryException into BigQueryJdbcException and check cancel/close before datasets.insert.

@keshavdandeva
keshavdandeva force-pushed the jdbc/large-results-3-dataset-acls branch from 417addc to 08fc921 Compare December 3, 2026 17:16
@keshavdandeva
keshavdandeva removed this pull request from stack #15336 December 3, 2026 17:17
@keshavdandeva keshavdandeva changed the title fix(bigquery-jdbc): clamp auto-created LargeResultDataset TTL to 1h and handle 409 races fix(bigquery-jdbc): clamp LargeResultsDatasetExpirationTime to 1h minimum and handle 409 races Dec 3, 2026
@keshavdandeva
keshavdandeva changed the base branch from jdbc/large-results-2-statement-concurrency to jdbc/fix-largeResultDataset-validation December 3, 2026 17:19
@keshavdandeva

Copy link
Copy Markdown
Contributor Author

Updated per @logachev's review:

  • Moved the 1-hour minimum LargeResultsDatasetExpirationTime clamp out of BigQueryStatement.checkIfDatasetExistElseCreate into DataSource.setDestinationDatasetExpirationTime (parameter parsing, using BigQueryJdbcUrlUtility.MIN_DESTINATION_DATASET_EXPIRATION_TIME_VALUE = 3600000L), with unit tests in DataSourceTest.
  • Rebased directly onto #15257 (#15331 has been decoupled as a standalone draft PR under b/593045100).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants