skywalker0618 commented on code in PR #20219:
URL: https://github.com/apache/hudi/pull/20219#discussion_r4250725379


##########
hudi-sync/hudi-hive-sync/src/main/java/org/apache/hudi/hive/HoodieHiveSyncClient.java:
##########
@@ -167,10 +170,44 @@ public HoodieHiveSyncClient(HiveSyncConfig config, 
HoodieTableMetaClient metaCli
       // such window; both close() methods are idempotent, so overlapping with 
the
       // executor's cleanup (or buildHiveQueryDDLExecutor's rollback) is 
harmless.
       closePartitionPoolsQuietly();
+      closeClient();
       throw new HoodieHiveSyncException("Failed to create 
HiveMetaStoreClient", e);
     }
   }
 
+  /**
+   * Takes the instance that owns {@link #client} out of Hive's cache for this 
thread, if it is
+   * there. Hive replaces the cached instance, closing its client, when a Hive 
session on the thread
+   * brings a different metastore conf, as a HiveQL-mode Driver's session does 
on its first
+   * statement, by setting the metastore filter hook for authorization. Until 
then the client stays
+   * cached, so that the session's teardown reuses it rather than opening a 
connection of its own.
+   */
+  private void releaseClientFromHiveCache() {
+    if (clientCachedOnThread == Thread.currentThread()) {
+      Hive.set(null);
+      clientCachedOnThread = null;
+    }
+  }
+
+  /**
+   * Closes {@link #client}, which only closing it directly releases once it 
is out of Hive's cache,
+   * including an underlying client that RetryingMetaStoreClient rebuilt after 
a transient
+   * TException. Hive.closeCurrent() then closes whatever instance is left in 
the cache.
+   */
+  private void closeClient() {
+    if (client == null) {
+      return;

Review Comment:
   Keeping closeClient(). The method doesn't close a cache. It closes our 
client and then whatever Hive instance is left in the thread's cache. Added 
Javadoc to explain this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to