Pengzna commented on code in PR #16886: URL: https://github.com/apache/iotdb/pull/16886#discussion_r2744344323
########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/DelayAnalyzer.java: ########## @@ -0,0 +1,346 @@ +/* + * 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.iotdb.db.tools; + +import org.apache.iotdb.commons.utils.TestOnly; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +/** + * DelayAnalyzer: Calculate watermarks for in-order and out-of-order data based on statistics and + * models + * + * <p>This implementation is based on the paper "Separation or Not: On Handling Out-of-Order + * Time-Series Data" (ICDE 2022) proposed method, which dynamically calculates safe watermarks by + * analyzing the Cumulative Distribution Function (CDF) of data arrival delays. + * + * <p>Core concepts: + * + * <ul> + * <li>Record the generation time (Event Time) and arrival time (System Time) of each data point + * <li>Calculate delay: delay = arrivalTime - generationTime + * <li>Maintain a sliding window to store recent delay samples + * <li>Use CDF to calculate delay quantiles (e.g., P99) at specific confidence levels + * <li>Safe watermark = Current system time - P99 delay + * </ul> + * + * <p>Key formulas from the paper: + * + * <ul> + * <li>Delay calculation: p.t_d = p.t_a - p.t_g (Formula 160) + * <li>Use F(x) (CDF) to estimate the probability of out-of-order data (Reference 110) + * <li>Dynamic delay distribution: Use sliding window to maintain recent delay samples + * </ul> + * + * <p>Features: + * + * <ul> + * <li>Thread-safe: Uses ReadWriteLock to support high-concurrency read/write operations + * <li>Memory efficient: Uses circular buffer with fixed memory footprint + * <li>Clock skew handling: Automatically handles negative delays (clock rollback) + * <li>Dynamic adaptation: Sliding window automatically adapts to changes in delay distribution + * </ul> + * + * @see <a href="https://ieeexplore.ieee.org/document/9835234">ICDE 2022 Paper</a> + */ +public class DelayAnalyzer { + + private static final Logger LOGGER = LoggerFactory.getLogger(DelayAnalyzer.class); + + /** Default window size, empirical value: 10000 sample points */ + public static final int DEFAULT_WINDOW_SIZE = 10000; + + /** Recommended window size range */ + public static final int MIN_WINDOW_SIZE = 1000; + + public static final int MAX_WINDOW_SIZE = 100000; + + /** Default confidence level: 99% */ + public static final double DEFAULT_CONFIDENCE_LEVEL = 0.99; Review Comment: fixed -- 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]
