flink checkpoint 指标的源码解析

1、 CheckpointMetricsBuilder是计算checkpoint相关指标信息

@NotThreadSafe
public class CheckpointMetricsBuilder {
    private CompletableFuture<Long> bytesProcessedDuringAlignment = new CompletableFuture<>();
    private long bytesPersistedDuringAlignment = -1L;
    private CompletableFuture<Long> alignmentDurationNanos = new CompletableFuture<>();
    private long syncDurationMillis = -1L;
    private long asyncDurationMillis = -1L;
    private long checkpointStartDelayNanos = -1L;
    private boolean unalignedCheckpoint = false;
    private long totalBytesPersisted = -1L;

    public CheckpointMetricsBuilder setBytesProcessedDuringAlignment(
            long bytesProcessedDuringAlignment) {
        checkState(
                this.bytesProcessedDuringAlignment.complete(bytesProcessedDuringAlignment),
                "bytesProcessedDuringAlignment has already been completed by someone else");
        return this;
    }

    public CheckpointMetricsBuilder setBytesProcessedDuringAlignment(
            CompletableFuture<Long> bytesProcessedDuringAlignment) {
        this.bytesProcessedDuringAlignment = bytesProcessedDuringAlignment;
        return this;
    }

    public CompletableFuture<Long> getBytesProcessedDuringAlignment() {
        return bytesProcessedDuringAlignment;
    }

    public CheckpointMetricsBuilder setBytesPersistedDuringAlignment(
            long bytesPersistedDuringAlignment) {
        this.bytesPersistedDuringAlignment = bytesPersistedDuringAlignment;
        return this;
    }

    public long getAlignmentDurationNanosOrDefault() {
        return FutureUtils.getOrDefault(alignmentDurationNanos, -1L);
    }

    public CheckpointMetricsBuilder setAlignmentDurationNanos(long alignmentDurationNanos) {
        checkState(
                this.alignmentDurationNanos.complete(alignmentDurationNanos),
                "alignmentDurationNanos has already been completed by someone else");
        return this;
    }

    public CheckpointMetricsBuilder setAlignmentDurationNanos(
            CompletableFuture<Long> alignmentDurationNanos) {
        checkState(
                !this.alignmentDurationNanos.isDone(),
                "alignmentDurationNanos has already been completed by someone else");
        this.alignmentDurationNanos = alignmentDurationNanos;
        return this;
    }

    public CompletableFuture<Long> getAlignmentDurationNanos() {
        return alignmentDurationNanos;
    }

    public CheckpointMetricsBuilder setSyncDurationMillis(long syncDurationMillis) {
        this.syncDurationMillis = syncDurationMillis;
        return this;
    }

    public long getSyncDurationMillis() {
        return syncDurationMillis;
    }

    public CheckpointMetricsBuilder setAsyncDurationMillis(long asyncDurationMillis) {
        this.asyncDurationMillis = asyncDurationMillis;
        return this;
    }

    public long getAsyncDurationMillis() {
        return asyncDurationMillis;
    }

    public CheckpointMetricsBuilder setCheckpointStartDelayNanos(long checkpointStartDelayNanos) {
        this.checkpointStartDelayNanos = checkpointStartDelayNanos;
        return this;
    }

    public long getCheckpointStartDelayNanos() {
        return checkpointStartDelayNanos;
    }

    public CheckpointMetricsBuilder setUnalignedCheckpoint(boolean unalignedCheckpoint) {
        this.unalignedCheckpoint = unalignedCheckpoint;
        return this;
    }

    public CheckpointMetricsBuilder setTotalBytesPersisted(long totalBytesPersisted) {
        this.totalBytesPersisted = totalBytesPersisted;
        return this;
    }

    public CheckpointMetrics build() {
        return new CheckpointMetrics(
                checkStateAndGet(bytesProcessedDuringAlignment),
                bytesPersistedDuringAlignment,
                checkStateAndGet(alignmentDurationNanos),
                syncDurationMillis,
                asyncDurationMillis,
                checkpointStartDelayNanos,
                unalignedCheckpoint,
                totalBytesPersisted);
    }

    public CheckpointMetrics buildIncomplete() {
        return new CheckpointMetrics(
                bytesProcessedDuringAlignment.getNow(CheckpointMetrics.UNSET),
                bytesPersistedDuringAlignment,
                alignmentDurationNanos.getNow(CheckpointMetrics.UNSET),
                syncDurationMillis,
                asyncDurationMillis,
                checkpointStartDelayNanos,
                unalignedCheckpoint,
                totalBytesPersisted);
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值