jugomezv commented on code in PR #9994: URL: https://github.com/apache/pinot/pull/9994#discussion_r1060800029
########## pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/ConsumptionDelayTracker.java: ########## @@ -0,0 +1,295 @@ +/** + * 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.util.HashSet; +import java.util.List; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.ConcurrentHashMap; +import org.apache.pinot.common.metrics.ServerGauge; +import org.apache.pinot.common.metrics.ServerMetrics; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * A Class to track maximum realtime 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-The class tracks the maximum of all ingestion delays observed for all partitions of the given table. + * 5-A Metric is derived from reading the maximum tracked by this class. + * 6-Delay reported for partitions that do not have events to consume is reported as zero. + * 7-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. + * 8-Segments that go from CONSUMING to DROPPED states stop being tracked so their delays do not cloud + * delays of active partitions. + * 9-When a segment goes from CONSUMING to ONLINE, we start ticking time for the corresponding partition. + * If no consumption is noticed after a timeout, then we read ideal state to confirm the server still hosts the + * partition. If not, we stop tracking the respective partition. + * 10-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) + * | + * markPartition(partitionId) |<-recordPinotConsumptionDelay()-{LLRealtimeSegmentDataManager(Partition 0}} + * | | + * ___________V_________________________V_ + * | (Table X) |<-recordPinotConsumptionDelay()-{LLRealtimeSegmentDataManager(Partition 1}} + * | ConsumptionDelayTracker| ... + * |____________________________________|<-recordPinotConsumptionDelay()-{LLRealtimeSegmentDataManager (Partition n}} + * ^ ^ + * | \ + * timeoutInactivePartitions() stopTrackingPinotConsumptionDelay(partitionId) + * _________|__________ \ + * | TimerTrackingTask | (CONSUMING -> DROPPED state change) + * |___________________| + * + */ + +public class ConsumptionDelayTracker { + /* + * Class to handle timer thread that will track inactive partitions + */ + private class TrackingTimerTask extends TimerTask { + private String _name; + private ConsumptionDelayTracker _tracker; + + public TrackingTimerTask(String name, ConsumptionDelayTracker tracker) { + _name = name; + _tracker = tracker; + } + + @Override + public void run() { + // tick inactive partitions every interval of time to keep tracked partitions up to date + _tracker.timeoutInactivePartitions(); + } + } + + /* + * Class to keep a Pinot Consumption Delay measure and the time when the sample was taken (i.e. sample time) + * We will use the sample time to increase consumption 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 { + public DelayMeasure(long t, long d) { + _delayMilliseconds = d; + _sampleTime = t; + } + public long _delayMilliseconds; Review Comment: Done -- 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