Skip to content

[Fix][Connector-V2] Fix hive client thread unsafe #9282

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

corgy-w
Copy link
Contributor

@corgy-w corgy-w commented May 7, 2025

Purpose of this pull request

Does this PR introduce any user-facing change?

How was this patch tested?

Check list

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request fixes a thread safety issue with the Hive client used by the Hive connector by refactoring resource management and removing the singleton pattern. The changes include:

  • Replacing a singleton instance with a try-with-resources block in HiveTableUtils.java.
  • Refactoring HiveMetaStoreProxy to implement Closeable and Serializable with explicit client initialization.
  • Updating HiveSinkAggregatedCommitter to use the new HiveMetaStoreProxy instance and manage its lifecycle appropriately.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveTableUtils.java Refactored to use try-with-resources for HiveMetaStoreProxy, helping ensure proper resource cleanup.
seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreProxy.java Removed singleton pattern, added explicit client initialization, and updated resource closing logic.
seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/commit/HiveSinkAggregatedCommitter.java Integrated usage of the new HiveMetaStoreProxy instance and adjusted resource management.
Comments suppressed due to low confidence (1)

seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreProxy.java:183

  • After closing hiveClient in the close() method, consider setting hiveClient to null to prevent accidental reuse of a closed client in subsequent calls.
if (Objects.nonNull(hiveClient)) { hiveClient.close(); }

hailin0
hailin0 previously approved these changes May 8, 2025
return new HiveMetaStoreClient(hiveConf);
});
return;
private HiveMetaStoreClient hiveClient;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private HiveMetaStoreClient hiveClient;
private transient HiveMetaStoreClient hiveClient;

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.

3 participants