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


##########
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();
+      this.indexer = indexer;
+      this.indexManager = indexManager;
+      this.flushIndexListener = new FlushIndexListener(configuration);
+      this.handler = new MetastoreEventHandler(configuration, clientProvider);
+      this.handler.addListeners(flushIndexListener, indexManager);
+      this.cluster = new MetastoreCluster(configuration, flushIndexListener);
+      this.lastEventId = initialize();

Review Comment:
   initialize() runs inside the constructor, so HMS startup waits for either a 
full bootstrap (2.5+ days for 2M tables, per the PR description) or 
waitForRemoteBackup(), which loops on sleep(3000) with no timeout until a 
remote manifest appears or this node becomes leader. Without a remote store 
configured, followers spin forever. The design doc (ยง4.3) says the instance 
should report not-ready instead. 
   
   Could initialization run on a background thread, with isReady() false until 
it completes and a bounded wait or a fallback to a local rebuild?



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