Skip to content

feat(bigquery-jdbc): migrate statement execution thread tracking to connection-scoped executor#13454

Open
Neenu1995 wants to merge 7 commits into
mainfrom
per-conn-thread-3
Open

feat(bigquery-jdbc): migrate statement execution thread tracking to connection-scoped executor#13454
Neenu1995 wants to merge 7 commits into
mainfrom
per-conn-thread-3

Conversation

@Neenu1995

@Neenu1995 Neenu1995 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

b/519201498

This PR migrates the asynchronous processing tasks of the JDBC driver away from the legacy static global thread pool (queryTaskExecutor) to the modern, connection-scoped ExecutorService (connection.getExecutorService()).

Key Changes

  1. Statement & Stream Refactoring:

    • Removed the static queryTaskExecutor from BigQueryStatement.
    • Updated populateArrowBufferedQueue to submit streaming and buffering tasks to the connection-scoped executor pool.
    • Converted background thread tracking in BigQueryStatement and BigQueryArrowResultSet from raw Thread references to modern, cancelable Future<?> task handles.
  2. Isolated Backward-Compatibility Wrapper:

    • Isolated the legacy raw thread wrapping to BigQueryDatabaseMetaData (which is still pending future refactoring to the executor pool).
    • Implemented a temporary wrapThread(Thread) helper method inside BigQueryDatabaseMetaData to wrap raw background threads into cancelable Future<?> adapters on the fly before passing them to the result set.
    • Hardened the anonymous Future wrapper state tracking to strictly satisfy the Future specification contract (handling cancel, isCancelled, and isDone correctly using a volatile boolean flag to prevent duplicate cancellation triggers).

@Neenu1995 Neenu1995 requested review from a team as code owners June 12, 2026 17:21

@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 refactors the asynchronous background task management in the BigQuery JDBC driver by replacing raw Thread references with Future<?> objects. This allows tasks to be managed and cancelled via the connection's ExecutorService rather than spawning unmanaged threads. The review feedback highlights a critical issue in the temporary wrapThread compatibility bridge in BigQueryDatabaseMetaData.java, where the anonymous Future implementation violates the standard Future contract regarding cancellation and completion states, which could lead to incorrect state tracking during resource cleanup.

@Neenu1995

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 refactors the asynchronous execution model of the BigQuery JDBC driver by replacing raw Thread objects with Future<?> tasks managed by a connection-scoped ExecutorService. Feedback focuses on a potential deadlock risk when executing interdependent tasks on a limited executor, contract violations in the temporary wrapThread Future adapter (specifically around isDone, cancel, and swallowing InterruptedException), and opportunities to simplify redundant Future status checks before cancellation.

@Neenu1995

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 refactors the JDBC driver to manage background tasks using Future objects and a bounded cached thread pool instead of raw threads, preventing potential OutOfMemoryErrors under heavy load. Feedback focuses on fixing the Future contract implementation in the temporary wrapThread bridge to ensure it blocks correctly for unstarted threads, and ensuring that already-submitted tasks are cancelled if a thread allocation failure occurs during JSON result set processing.

@Neenu1995

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 refactors thread management in the BigQuery JDBC driver by replacing raw Thread usage with Future<?> tasks and transitioning to a connection-scoped bounded cached thread pool to prevent unbounded thread creation and OOMs. Feedback focuses on improving the temporary wrapThread compatibility bridge in BigQueryDatabaseMetaData to avoid busy-spinning when a thread is in the NEW state and to prevent race conditions in cancel(). Additionally, the exception handling in BigQueryStatement.processJsonResultSet should be broadened to catch all exceptions to prevent thread leaks and avoid swallowing InterruptedException.

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.

1 participant