|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.apache.flink.cdc.connectors.iceberg.sink.v2; |
| 20 | + |
| 21 | +import org.apache.flink.shaded.guava31.com.google.common.base.MoreObjects; |
| 22 | + |
| 23 | +import java.io.Serializable; |
| 24 | +import java.util.Arrays; |
| 25 | +import java.util.Objects; |
| 26 | + |
| 27 | +/** |
| 28 | + * The aggregated results of a single checkpoint which should be committed. Containing the |
| 29 | + * serialized {@link org.apache.iceberg.flink.sink.DeltaManifests} file - which contains the commit |
| 30 | + * data, and the jobId, operatorId, checkpointId triplet which helps identifying the specific commit |
| 31 | + * |
| 32 | + * <p>{@link IcebergCommittableSerializer} is used for serializing the objects between the Writer |
| 33 | + * and the Aggregator operator and between the Aggregator and the Committer as well. |
| 34 | + */ |
| 35 | +public class IcebergCommittable implements Serializable { |
| 36 | + private final byte[] manifest; |
| 37 | + private final String jobId; |
| 38 | + private final String operatorId; |
| 39 | + private final long checkpointId; |
| 40 | + |
| 41 | + public IcebergCommittable(byte[] manifest, String jobId, String operatorId, long checkpointId) { |
| 42 | + this.manifest = manifest; |
| 43 | + this.jobId = jobId; |
| 44 | + this.operatorId = operatorId; |
| 45 | + this.checkpointId = checkpointId; |
| 46 | + } |
| 47 | + |
| 48 | + byte[] manifest() { |
| 49 | + return manifest; |
| 50 | + } |
| 51 | + |
| 52 | + String jobId() { |
| 53 | + return jobId; |
| 54 | + } |
| 55 | + |
| 56 | + String operatorId() { |
| 57 | + return operatorId; |
| 58 | + } |
| 59 | + |
| 60 | + Long checkpointId() { |
| 61 | + return checkpointId; |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public String toString() { |
| 66 | + return MoreObjects.toStringHelper(this) |
| 67 | + .add("jobId", jobId) |
| 68 | + .add("checkpointId", checkpointId) |
| 69 | + .add("operatorId", operatorId) |
| 70 | + .toString(); |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public boolean equals(Object o) { |
| 75 | + if (this == o) { |
| 76 | + return true; |
| 77 | + } |
| 78 | + |
| 79 | + if (o == null || getClass() != o.getClass()) { |
| 80 | + return false; |
| 81 | + } |
| 82 | + |
| 83 | + IcebergCommittable that = (IcebergCommittable) o; |
| 84 | + return checkpointId == that.checkpointId |
| 85 | + && Arrays.equals(manifest, that.manifest) |
| 86 | + && Objects.equals(jobId, that.jobId) |
| 87 | + && Objects.equals(operatorId, that.operatorId); |
| 88 | + } |
| 89 | + |
| 90 | + @Override |
| 91 | + public int hashCode() { |
| 92 | + int result = Objects.hash(jobId, operatorId, checkpointId); |
| 93 | + result = 31 * result + Arrays.hashCode(manifest); |
| 94 | + return result; |
| 95 | + } |
| 96 | +} |
0 commit comments