dengzhhu653 commented on code in PR #6595: URL: https://github.com/apache/hive/pull/6595#discussion_r4594827505
########## standalone-metastore/metastore-search/src/main/java/org/apache/hive/search/metastore/MetastoreEventHandler.java: ########## @@ -0,0 +1,375 @@ +/* + * 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.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.common.DatabaseName; +import org.apache.hadoop.hive.common.TableName; +import org.apache.hadoop.hive.metastore.api.NotificationEvent; +import org.apache.hadoop.hive.metastore.api.NotificationEventRequest; +import org.apache.hadoop.hive.metastore.api.NotificationEventResponse; +import org.apache.hadoop.hive.metastore.api.Table; +import org.apache.hadoop.hive.metastore.messaging.AlterTableMessage; +import org.apache.hadoop.hive.metastore.messaging.CreateTableMessage; +import org.apache.hadoop.hive.metastore.messaging.MessageBuilder; +import org.apache.hadoop.hive.metastore.messaging.MessageDeserializer; +import org.apache.hadoop.hive.metastore.messaging.MessageFactory; +import org.apache.hive.search.exception.IndexNotHealthyException; +import org.apache.hive.search.config.IndexOptions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Polls HMS notification events, coalesces them into batches, and dispatches index mutations. + * + * <p>On repeated batch failure the handler falls back to single-event apply so one poison event + * does not block the entire batch forever. If a poison event still cannot be applied, the index + * is marked unhealthy and search is blocked until the root cause is fixed. + */ +public class MetastoreEventHandler implements Closeable { + private static final Logger LOG = LoggerFactory.getLogger(MetastoreEventHandler.class); + private final AtomicBoolean stopped = new AtomicBoolean(false); + private final List<MetastoreEventListener> listeners = Collections.synchronizedList(new ArrayList<>()); + private final IndexOptions indexConfig; + private final MetastoreClientProvider clientProvider; + private final MessageDeserializer deserializer; + private Thread eventPoller; + private long lastEventId; + + /** Consecutive batch failures at {@link #failedBatchStartId}. */ + private int consecutiveBatchFailures; + private long failedBatchStartId = -1; + + MetastoreEventHandler(Configuration configuration, MetastoreClientProvider clientProvider) { + Configuration conf = new Configuration(Objects.requireNonNull(configuration)); + this.indexConfig = new IndexOptions(conf); + this.clientProvider = Objects.requireNonNull(clientProvider); + this.deserializer = MessageFactory.getDefaultInstance(conf).getDeserializer(); Review Comment: ack -- 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]
