kafka LagInfo 源码

  • 2022-10-20
  • 浏览 (105)

kafka LagInfo 代码


 * 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,
 * See the License for the specific language governing permissions and
 * limitations under the License.
package org.apache.kafka.streams;

import java.util.Objects;

 * Encapsulates information about lag, at a store partition replica (active or standby). This information is constantly changing as the
 * tasks process records and thus, they should be treated as simply instantaenous measure of lag.
public class LagInfo {

    private final long currentOffsetPosition;

    private final long endOffsetPosition;

    private final long offsetLag;

    LagInfo(final long currentOffsetPosition, final long endOffsetPosition) {
        this.currentOffsetPosition = currentOffsetPosition;
        this.endOffsetPosition = endOffsetPosition;
        this.offsetLag = Math.max(0, endOffsetPosition - currentOffsetPosition);

     * Get the current maximum offset on the store partition's changelog topic, that has been successfully written into
     * the store partition's state store.
     * @return current consume offset for standby/restoring store partitions &   simply endoffset for active store partition replicas
    public long currentOffsetPosition() {
        return this.currentOffsetPosition;

     * Get the end offset position for this store partition's changelog topic on the Kafka brokers.
     * @return last offset written to the changelog topic partition
    public long endOffsetPosition() {
        return this.endOffsetPosition;

     * Get the measured lag between current and end offset positions, for this store partition replica
     * @return lag as measured by message offsets
    public long offsetLag() {
        return this.offsetLag;

    public boolean equals(final Object obj) {
        if (!(obj instanceof LagInfo)) {
            return false;
        final LagInfo other = (LagInfo) obj;
        return currentOffsetPosition == other.currentOffsetPosition
            && endOffsetPosition == other.endOffsetPosition
            && this.offsetLag == other.offsetLag;

    public int hashCode() {
        return Objects.hash(currentOffsetPosition, endOffsetPosition, offsetLag);

    public String toString() {
        return "LagInfo {" +
            " currentOffsetPosition=" + currentOffsetPosition +
            ", endOffsetPosition=" + endOffsetPosition +
            ", offsetLag=" + offsetLag +


kafka 源码目录


kafka KafkaClientSupplier 源码

kafka KafkaStreams 源码

kafka KeyQueryMetadata 源码

kafka KeyValue 源码

kafka StoreQueryParameters 源码

kafka StreamsBuilder 源码

kafka StreamsConfig 源码

kafka StreamsMetadata 源码

kafka StreamsMetrics 源码

kafka TaskMetadata 源码

0  赞