dengzhhu653 commented on code in PR #6595: URL: https://github.com/apache/hive/pull/6595#discussion_r4290094889
########## standalone-metastore/metastore-search/src/main/java/org/apache/hive/search/metastore/MetastoreIndexer.java: ########## @@ -0,0 +1,359 @@ +/* + * 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.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 IMetaStoreClient client; + 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 boolean shareBootstrapFetchClient; + + public MetastoreIndexer(Configuration configuration, IndexManager indexManager, Indexer indexer) + throws Exception { + this(configuration, indexManager, indexer, + RetryingMetaStoreClient.getProxy(configuration, true), false); + } + + MetastoreIndexer(Configuration configuration, IndexManager indexManager, Indexer indexer, + IMetaStoreClient client) throws Exception { + this(configuration, indexManager, indexer, client, true); + } + + MetastoreIndexer(Configuration configuration, IndexManager indexManager, Indexer indexer, + IMetaStoreClient client, boolean shareBootstrapFetchClient) throws Exception { + this.client = client; + this.shareBootstrapFetchClient = shareBootstrapFetchClient; + this.indexer = indexer; + this.indexManager = indexManager; + this.flushIndexListener = new FlushIndexListener(configuration); + this.handler = new MetastoreEventHandler(configuration, client); + this.handler.addListeners(flushIndexListener, indexManager); + this.cluster = new MetastoreCluster(configuration, flushIndexListener); + this.lastEventId = initialize(); + this.indexManager.setNid(lastEventId); + } + + private boolean rebuildIndex() throws Exception { + indexManager.resolveInterruptedRestore(); + if (isIndexValid(indexManager.readLocalManifest().orElse(null))) { + return false; + } + if (isIndexValid(indexManager.readRemoteManifest().orElse(null))) { + if (indexManager.restoreBackup()) { + return false; + } + LOG.warn("Failed to restore index from remote backup; clearing partial local index"); + indexManager.clearLocalIndex(); + return true; + } + indexManager.clearLocalIndex(); + return true; + } + + private boolean isIndexValid(IndexManifest indexManifest) Review Comment: I get the idea, it means the index schema version(index mapping), it might be changed, we need to rebuild(bootstrap) the index if the old index is not compatible with the new schema. Filed HIVE-30193 as the follow-up task. -- 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]
