|
| 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, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package org.apache.paimon.metrics; |
| 20 | + |
| 21 | +import org.apache.paimon.annotation.Public; |
| 22 | +import org.apache.paimon.utils.JsonSerdeUtil; |
| 23 | + |
| 24 | +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonCreator; |
| 25 | +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonGetter; |
| 26 | +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
| 27 | +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonProperty; |
| 28 | + |
| 29 | +import javax.annotation.Nullable; |
| 30 | + |
| 31 | +import java.io.Serializable; |
| 32 | +import java.util.Objects; |
| 33 | + |
| 34 | +/** @since 1.4.0 */ |
| 35 | +@Public |
| 36 | +@JsonIgnoreProperties(ignoreUnknown = true) |
| 37 | +public class CompactMetric implements Serializable { |
| 38 | + |
| 39 | + private static final long serialVersionUID = 1L; |
| 40 | + |
| 41 | + public static final long FIRST_SNAPSHOT_ID = 1; |
| 42 | + |
| 43 | + public static final int TABLE_STORE_02_VERSION = 1; |
| 44 | + protected static final int CURRENT_VERSION = 3; |
| 45 | + |
| 46 | + protected static final String FIELD_VERSION = "version"; |
| 47 | + protected static final String FIELD_SNAPSHOT_ID = "snapshotId"; |
| 48 | + protected static final String FIELD_COMMIT_TIME = "commitTime"; |
| 49 | + protected static final String FIELD_COMPACT_AVG_DURATION = "compactAvgDuration"; |
| 50 | + protected static final String FIELD_COMPACTION_MAX_DURATION = "compactMaxDuration"; |
| 51 | + protected static final String FIELD_COMPACTION_MIN_DURATION = "compactMinDuration"; |
| 52 | + protected static final String FIELD_BUCKETS = "compactBuckets"; |
| 53 | + protected static final String FIELD_COMPACTION_TYPE = "compactType"; |
| 54 | + protected static final String FIELD_IDENTIFIER = "identifier"; |
| 55 | + protected static final String FIELD_COMMIT_USER = "commitUser"; |
| 56 | + |
| 57 | + @JsonProperty(FIELD_VERSION) |
| 58 | + @Nullable |
| 59 | + protected final Integer version; |
| 60 | + |
| 61 | + @JsonProperty(FIELD_SNAPSHOT_ID) |
| 62 | + protected final long snapshotId; |
| 63 | + |
| 64 | + @JsonProperty(FIELD_COMMIT_TIME) |
| 65 | + protected final long commitTime; |
| 66 | + |
| 67 | + @JsonProperty(FIELD_COMPACT_AVG_DURATION) |
| 68 | + protected final long compactDuration; |
| 69 | + |
| 70 | + // a manifest list recording all new changes occurred in this snapshot |
| 71 | + // for faster expire and streaming reads |
| 72 | + @JsonProperty(FIELD_COMPACTION_MAX_DURATION) |
| 73 | + protected final long compactMaxDuration; |
| 74 | + |
| 75 | + @JsonProperty(FIELD_COMPACTION_MIN_DURATION) |
| 76 | + protected final long compactMinDuration; |
| 77 | + |
| 78 | + // a manifest list recording all changelog produced in this snapshot |
| 79 | + // null if no changelog is produced, or for paimon <= 0.2 |
| 80 | + @JsonProperty(FIELD_BUCKETS) |
| 81 | + protected final String buckets; |
| 82 | + |
| 83 | + @JsonProperty(FIELD_IDENTIFIER) |
| 84 | + protected final long identifier; |
| 85 | + |
| 86 | + @JsonProperty(FIELD_COMMIT_USER) |
| 87 | + protected final String commitUser; |
| 88 | + |
| 89 | + @JsonProperty(FIELD_COMPACTION_TYPE) |
| 90 | + protected final String compactType; |
| 91 | + |
| 92 | + public CompactMetric( |
| 93 | + long snapshotId, |
| 94 | + long commitTime, |
| 95 | + long compactDuration, |
| 96 | + long compactMaxDuration, |
| 97 | + long compactMinDuration, |
| 98 | + String buckets, |
| 99 | + String compactType, |
| 100 | + long identifier, |
| 101 | + String commitUser) { |
| 102 | + this( |
| 103 | + CURRENT_VERSION, |
| 104 | + snapshotId, |
| 105 | + commitTime, |
| 106 | + compactDuration, |
| 107 | + compactMaxDuration, |
| 108 | + compactMinDuration, |
| 109 | + buckets, |
| 110 | + compactType, |
| 111 | + identifier, |
| 112 | + commitUser); |
| 113 | + } |
| 114 | + |
| 115 | + @JsonCreator |
| 116 | + public CompactMetric( |
| 117 | + @JsonProperty(FIELD_VERSION) @Nullable Integer version, |
| 118 | + @JsonProperty(FIELD_SNAPSHOT_ID) long snapshotId, |
| 119 | + @JsonProperty(FIELD_COMMIT_TIME) long commitTime, |
| 120 | + @JsonProperty(FIELD_COMPACT_AVG_DURATION) long compactDuration, |
| 121 | + @JsonProperty(FIELD_COMPACTION_MAX_DURATION) long compactMaxDuration, |
| 122 | + @JsonProperty(FIELD_COMPACTION_MIN_DURATION) long compactMinDuration, |
| 123 | + @JsonProperty(FIELD_BUCKETS) @Nullable String buckets, |
| 124 | + @JsonProperty(FIELD_COMPACTION_TYPE) @Nullable String compactType, |
| 125 | + @JsonProperty(FIELD_IDENTIFIER) long identifier, |
| 126 | + @JsonProperty(FIELD_COMMIT_USER) String commitUser) { |
| 127 | + this.version = version; |
| 128 | + this.snapshotId = snapshotId; |
| 129 | + this.commitTime = commitTime; |
| 130 | + this.compactDuration = compactDuration; |
| 131 | + this.compactMaxDuration = compactMaxDuration; |
| 132 | + this.compactMinDuration = compactMinDuration; |
| 133 | + this.buckets = buckets; |
| 134 | + this.compactType = compactType; |
| 135 | + this.identifier = identifier; |
| 136 | + this.commitUser = commitUser; |
| 137 | + } |
| 138 | + |
| 139 | + @JsonGetter(FIELD_VERSION) |
| 140 | + public int version() { |
| 141 | + // there is no version field for paimon <= 0.2 |
| 142 | + return version == null ? TABLE_STORE_02_VERSION : version; |
| 143 | + } |
| 144 | + |
| 145 | + @JsonGetter(FIELD_SNAPSHOT_ID) |
| 146 | + public long snapshotId() { |
| 147 | + return snapshotId; |
| 148 | + } |
| 149 | + |
| 150 | + @JsonGetter(FIELD_COMMIT_TIME) |
| 151 | + public long commitTime() { |
| 152 | + return commitTime; |
| 153 | + } |
| 154 | + |
| 155 | + @JsonGetter(FIELD_COMPACT_AVG_DURATION) |
| 156 | + public long compactDuration() { |
| 157 | + return compactDuration; |
| 158 | + } |
| 159 | + |
| 160 | + @JsonGetter(FIELD_COMPACTION_MAX_DURATION) |
| 161 | + public long compactMaxDuration() { |
| 162 | + return compactMaxDuration; |
| 163 | + } |
| 164 | + |
| 165 | + @JsonGetter(FIELD_COMPACTION_MIN_DURATION) |
| 166 | + public long compactMinDuration() { |
| 167 | + return compactMinDuration; |
| 168 | + } |
| 169 | + |
| 170 | + @JsonGetter(FIELD_BUCKETS) |
| 171 | + public String buckets() { |
| 172 | + return buckets == null ? "{}" : buckets; |
| 173 | + } |
| 174 | + |
| 175 | + @JsonGetter(FIELD_COMPACTION_TYPE) |
| 176 | + public String compactType() { |
| 177 | + return compactType; |
| 178 | + } |
| 179 | + |
| 180 | + @JsonGetter(FIELD_IDENTIFIER) |
| 181 | + public long identifier() { |
| 182 | + return identifier; |
| 183 | + } |
| 184 | + |
| 185 | + @JsonGetter(FIELD_COMMIT_USER) |
| 186 | + public String commitUser() { |
| 187 | + return commitUser; |
| 188 | + } |
| 189 | + |
| 190 | + public String toJson() { |
| 191 | + return JsonSerdeUtil.toJson(this); |
| 192 | + } |
| 193 | + |
| 194 | + @Override |
| 195 | + public int hashCode() { |
| 196 | + return Objects.hash( |
| 197 | + version, |
| 198 | + snapshotId, |
| 199 | + commitTime, |
| 200 | + compactDuration, |
| 201 | + compactMaxDuration, |
| 202 | + compactMinDuration, |
| 203 | + buckets, |
| 204 | + compactType, |
| 205 | + identifier, |
| 206 | + commitUser); |
| 207 | + } |
| 208 | + |
| 209 | + @Override |
| 210 | + public boolean equals(Object o) { |
| 211 | + if (this == o) { |
| 212 | + return true; |
| 213 | + } |
| 214 | + if (o == null || getClass() != o.getClass()) { |
| 215 | + return false; |
| 216 | + } |
| 217 | + CompactMetric that = (CompactMetric) o; |
| 218 | + return Objects.equals(version, that.version) |
| 219 | + && snapshotId == that.snapshotId |
| 220 | + && commitTime == that.commitTime |
| 221 | + && Objects.equals(compactDuration, that.compactDuration) |
| 222 | + && Objects.equals(compactMaxDuration, that.compactMaxDuration) |
| 223 | + && Objects.equals(compactMinDuration, that.compactMinDuration) |
| 224 | + && Objects.equals(buckets, that.buckets) |
| 225 | + && Objects.equals(compactType, that.compactType) |
| 226 | + && Objects.equals(identifier, that.identifier) |
| 227 | + && Objects.equals(commitUser, that.commitUser); |
| 228 | + } |
| 229 | + |
| 230 | + public static CompactMetric fromJson(String json) { |
| 231 | + return JsonSerdeUtil.fromJson(json, CompactMetric.class); |
| 232 | + } |
| 233 | +} |
0 commit comments