Jackie-Jiang commented on code in PR #9994: URL: https://github.com/apache/pinot/pull/9994#discussion_r1065260703
########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/tablestate/TableStateUtils.java: ########## @@ -39,37 +39,56 @@ private TableStateUtils() { } /** - * Checks if all segments for the given @param tableNameWithType are succesfully loaded - * This function will get all segments in IDEALSTATE and CURRENTSTATE for the given table, - * and then check if all ONLINE segments in IDEALSTATE match with CURRENTSTATE. - * @param helixManager helix manager for the server instance - * @param tableNameWithType table name for which segment state is to be checked - * @return true if all segments for the given table are succesfully loaded. False otherwise + * Returns all segments in a given state for a given table. + * + * @param helixManager instance of Helix manager + * @param tableNameWithType table for which we are obtaining ONLINE segments + * @param state state of the segments to be returned + * + * @return List of segment names in a given state. */ - public static boolean isAllSegmentsLoaded(HelixManager helixManager, String tableNameWithType) { + public static Set<String> getSegmentsInGivenStateForThisInstance(HelixManager helixManager, String tableNameWithType, + String state) { HelixDataAccessor dataAccessor = helixManager.getHelixDataAccessor(); PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder(); IdealState idealState = dataAccessor.getProperty(keyBuilder.idealStates(tableNameWithType)); + Set<String> segmentsInGivenState = new HashSet<>(); if (idealState == null) { LOGGER.warn("Failed to find ideal state for table: {}", tableNameWithType); - return false; + return segmentsInGivenState; } // Get all ONLINE segments from idealState String instanceName = helixManager.getInstanceName(); - List<String> onlineSegments = new ArrayList<>(); Map<String, Map<String, String>> idealStatesMap = idealState.getRecord().getMapFields(); for (Map.Entry<String, Map<String, String>> entry : idealStatesMap.entrySet()) { String segmentName = entry.getKey(); Map<String, String> instanceStateMap = entry.getValue(); String expectedState = instanceStateMap.get(instanceName); // Only track ONLINE segments assigned to the current instance - if (!CommonConstants.Helix.StateModel.SegmentStateModel.ONLINE.equals(expectedState)) { + if (!state.equals(expectedState)) { Review Comment: ^^ ########## pinot-core/src/main/java/org/apache/pinot/core/data/manager/InstanceDataManager.java: ########## @@ -183,4 +184,11 @@ void addOrReplaceSegment(String tableNameWithType, String segmentName) * Immediately stop consumption and start committing the consuming segments. */ void forceCommit(String tableNameWithType, Set<String> segmentNames); + + /** + * Enables the installation of a method to determine if a server is ready to server queries. + * + * @param isServerReadyToServeQueries supplier to retrieve state of server. + */ + void setSupplierOfIsServerReadyToServeQueries(Supplier<Boolean> isServerReadyToServeQueries); Review Comment: ^^ ########## pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/IngestionDelayTracker.java: ########## @@ -0,0 +1,361 @@ +/** + * 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.pinot.core.data.manager.realtime; + +import com.google.common.annotations.VisibleForTesting; +import java.time.Clock; +import java.util.ArrayList; +import java.util.Set; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Supplier; +import org.apache.pinot.common.metrics.ServerGauge; +import org.apache.pinot.common.metrics.ServerMetrics; +import org.apache.pinot.spi.utils.builder.TableNameBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * A Class to track realtime ingestion delay for a given table on a given server. + * Highlights: + * 1-An object of this class is hosted by each RealtimeTableDataManager. + * 2-The object tracks ingestion delays for all partitions hosted by the current server for the given Realtime table. + * 3-Partition delays are updated by all LLRealtimeSegmentDataManager objects hosted in the corresponding + * RealtimeTableDataManager. + * 4-A Metric is derived from reading the maximum tracked by this class. In addition, individual metrics are associated + * with each partition being tracked. + * 5-Delays reported for partitions that do not have events to consume are reported as zero. + * 6-We track the time at which each delay sample was collected so that delay can be increased when partition stops + * consuming for any reason other than no events being available for consumption. + * 7-Partitions whose Segments go from CONSUMING to DROPPED state stop being tracked so their delays do not cloud + * delays of active partitions. + * 8-When a segment goes from CONSUMING to ONLINE, we start a timeout for the corresponding partition. + * If no consumption is noticed after the timeout, we then read ideal state to confirm the server still hosts the + * partition. If not, we stop tracking the respective partition. + * 9-A timer thread is started by this object to track timeouts of partitions and drive the reading of their ideal + * state. + * + * The following diagram illustrates the object interactions with main external APIs + * + * (CONSUMING -> ONLINE state change) + * | + * markPartitionForConfirmation(partitionId) + * | |<-updateIngestionDelay()-{LLRealtimeSegmentDataManager(Partition 0}} + * | | + * ___________V_________________________V_ + * | (Table X) |<-updateIngestionDelay()-{LLRealtimeSegmentDataManager(Partition 1}} + * | IngestionDelayTracker | ... + * |____________________________________|<-updateIngestionDelay()-{LLRealtimeSegmentDataManager (Partition n}} + * ^ ^ + * | \ + * timeoutInactivePartitions() stopTrackingPartitionIngestionDelay(partitionId) + * _________|__________ \ + * | TimerTrackingTask | (CONSUMING -> DROPPED state change) + * |___________________| + * + * TODO: handle bug situations like the one where a partition is not allocated to a given server due to a bug. + */ + +public class IngestionDelayTracker { + + // Sleep interval for timer thread that triggers read of ideal state + private static final int TIMER_THREAD_TICK_INTERVAL_MS = 300000; // 5 minutes +/- precision in timeouts + // Once a partition is marked for verification, we wait 10 minutes to pull its ideal state. + private static final int PARTITION_TIMEOUT_MS = 600000; // 10 minutes timeouts + // Delay Timer thread for this amount of time after starting timer + private static final int INITIAL_TIMER_THREAD_DELAY_MS = 100; + private static final Logger _logger = LoggerFactory.getLogger(IngestionDelayTracker.class.getSimpleName()); + + /* + * Class to keep an ingestion delay measure and the time when the sample was taken (i.e. sample time) + * We will use the sample time to increase ingestion delay when a partition stops consuming: the time + * difference between the sample time and current time will be added to the metric when read. + */ + static private class DelayMeasure { Review Comment: ^^ -- 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org