Repository navigation
fix(bigquery-jdbc): delete generated LargeResultDataset temp tables on close and re-execution - #15334
Open
keshavdandeva wants to merge 1 commit into
Conversation
This was referenced Dec 1, 2026
fix(bigquery-jdbc): validate LargeResult properties and use UUID temp tables with WRITE_EMPTY
#15257
Open
Contributor
There was a problem hiding this comment.
Code Review
This pull request implements best-effort automatic deletion of generated temporary destination tables when a ResultSet or Statement is closed, or during Statement re-execution. It updates the user guide, introduces tracking of temporary tables and memoization of delete permission failures on the connection to avoid redundant RPCs, and adds comprehensive unit and integration tests to verify the lifecycle and cleanup behavior under various execution and error scenarios. There are no review comments, and I have no additional feedback to provide.
keshavdandeva
force-pushed
the
jdbc/large-results-5-temp-table-cleanup
branch
from
December 1, 2026 17:51
a8961e9 to
866d40e
Compare
…n close and re-execution
keshavdandeva
force-pushed
the
jdbc/large-results-5-temp-table-cleanup
branch
from
December 1, 2026 20:09
866d40e to
30eb6eb
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
b/584840569
Summary of Changes
BigQueryBaseResultSet,BigQueryStatement):BigQueryBaseResultSetownsprivate final AtomicReference<TableId> generatedTempTableId(attachGeneratedTempTable/claimGeneratedTempTable).SELECT,BigQueryStatement.runQuerytransfers ownership undercancelLockto theResultSet. When theResultSetcloses (directly, viacloseOnCompletion, via re-execution /PreparedStatement.executeBatch(), via non-singularexecuteQuery, or viaStatement.close()/Connection.close()),BigQueryJsonResultSet.close()/BigQueryArrowResultSet.close()cancel background reader workers first, thensuper.close()→onResultSetClosedInternalatomically claims (getAndSet(null)) and deletes the temp table once.runQueryunwinds without handing off aResultSet(DML, non-terminal error, concurrentcancel()/close()),runQuery'sfinallydeletes the temp table once — skipping guaranteed-404tables.delete/tables.updateon terminal400job failures where BigQuery never created the table.LargeResultTabletables are never attached and never deleted.LargeResultDestinations,BigQueryConnection):LargeResultDestinationsruns best-effortbigQuery.delete(tableId)on a driver-scoped bounded daemonThreadPoolExecutor(4max threads withallowCoreThreadTimeOut(true),60skeep-alive,1024-entry queue with warning-only rejection handler), bindingBigQueryJdbcMdc.registerInstance(connectionId)for log correlation.ResultSet.close(),Statement.close(),Connection.close(), andConnection.resetForReuse()never block ontables.deleteRPCs.403 accessDeniedper connection (tempTableDeleteForbidden, cleared onresetForReuse()); non-IAM failures (503,403 rateLimitExceeded) are logged once without poisoning the connection or accumulating retry queues (table expiration from PR 3/PR 4 handles stragglers). If delete fails or is forbidden on an aborted no-TTL execution before per-table expiration ran, appliesapplyTempTableExpirationBestEffortas fallback on the background task.@VisibleForTestingpackage-private constructorBigQueryConnection(String url, DataSource ds, Executor tempTableCleanupExecutor)(delegated to by existing package-private constructors usingCLEANUP_EXECUTOR) so unit tests run deterministically without cross-thread Mockito races while keepinglargeResultDestinationsstrictlyfinal.USER_GUIDE.md,BigQueryStatementTest,ITStatementTest):closeOnCompletion/ non-singular DML /PreparedStatement.executeBatch(), concurrent close/cancel unwind + expiration fallback, terminal400skip vs. non-terminal503cleanup,403 accessDeniedmemoization +resetForReuse(), non-IAM error non-retry, and a realCLEANUP_EXECUTORtest provingrs.close()/resetForReuse()/conn.close()never block on a hungtables.deleteand preserve MDCconnectionId.ITStatementTest(testTemporaryDatasetLocation+testLargeResultDatasetLifecycleAndExplicitTableRetention) with anawaitTableDeletedpoll helper for async deletion.Decisions Taken & Open Review Points
trackedTempTables/IdentityHashMap/finalSweepretry loop and synchronous close-path blocking. If a singletables.deletefails transiently, table TTL (PR 3/PR 4) reaps it; if the JVM exits during a queued delete, daemon threads allow clean shutdown and TTL reaps it.Connection.close(): VerifiedBigQueryConnection.closeImpl()only closes gRPC Read/Write clients (bigQueryReadClient/bigQueryWriteClient) and does not closethis.bigQuery, so background HTTPtables.deletecalls finish cleanly even afterConnection.close()returns.