deniskuzZ commented on code in PR #6595:
URL: https://github.com/apache/hive/pull/6595#discussion_r4587977315


##########
standalone-metastore/metastore-search/src/main/java/org/apache/hive/search/metastore/MetastoreIndexer.java:
##########
@@ -0,0 +1,370 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.search.metastore;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.common.DatabaseName;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.RetryingMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.NotificationEventRequest;
+import org.apache.hadoop.hive.metastore.leader.LeaderElection;
+import org.apache.hive.search.mapping.TableDocument;
+import org.apache.hive.search.exception.IndexNotHealthyException;
+import org.apache.hive.search.config.IndexOptions;
+import org.apache.hive.search.index.Indexer;
+import org.apache.hive.search.index.IndexManager;
+import org.apache.hive.search.index.store.IndexManifest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class MetastoreIndexer implements Closeable {
+  private static final Logger LOG = 
LoggerFactory.getLogger(MetastoreIndexer.class);
+
+  private final MetastoreClientProvider clientProvider;
+  private final long lastEventId;
+  private final Indexer indexer;
+  private final MetastoreCluster cluster;
+  private final MetastoreEventHandler handler;
+  private final IndexManager indexManager;
+  private final FlushIndexListener flushIndexListener;
+  private final IMetaStoreClient client;
+
+  public static MetastoreIndexer getMetastoreIndexer(Configuration 
configuration,
+      IndexManager indexManager, Indexer indexer, MetastoreClientProvider 
clientProvider)
+      throws Exception {
+    if (clientProvider == null) {
+      IMetaStoreClient client = 
RetryingMetaStoreClient.getProxy(configuration, true);
+      Thread currentThread = Thread.currentThread();
+      clientProvider = conf -> {
+        if (currentThread == Thread.currentThread()) {
+          return new MetastoreClientProvider.MetastoreClientBundle(client, 
false);
+        }
+        return new 
MetastoreClientProvider.MetastoreClientBundle(RetryingMetaStoreClient.getProxy(conf,
 true), true);
+      };
+    }
+    return new MetastoreIndexer(configuration, indexManager, indexer, 
clientProvider);
+  }
+
+  private MetastoreIndexer(Configuration configuration,
+                           IndexManager indexManager,
+                           Indexer indexer,
+                           MetastoreClientProvider clientProvider) throws 
Exception {
+    try {
+      this.clientProvider = clientProvider;
+      this.client = clientProvider.getMetastoreClient(configuration).client();

Review Comment:
   If getMetastoreClient throws here, client stays null, and close() in the 
catch block throws an NPE at client.close(), which replaces the original 
exception. Also, releaseAfterUse is ignored, so an injected shared client 
always gets closed. 
   
   Could you keep the bundle itself and close it null-safely?



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to