spacemonkd commented on code in PR #9886: URL: https://github.com/apache/ozone/pull/9886#discussion_r2936912292
########## hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmMultipartPartKey.java: ########## @@ -0,0 +1,194 @@ +/* + * 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.hadoop.ozone.om.helpers; + +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.Objects; +import org.apache.hadoop.hdds.utils.db.Codec; + +/** + * Typed key for multipart parts table. + * Key encoding: + * <pre> + * uploadId(utf8) + '/' + partNumber(int32, big-endian) + * </pre> + * Prefix encoding for iteration: + * <pre> + * uploadId(utf8) + '/' + * </pre> + */ +public final class OmMultipartPartKey { + private static final byte SEPARATOR = (byte) '/'; + private static final Codec<OmMultipartPartKey> CODEC = + new OmMultipartPartKeyCodec(); + + private final String uploadId; + private final Integer partNumber; + + private OmMultipartPartKey(String uploadId, Integer partNumber) { + this.uploadId = Objects.requireNonNull(uploadId, "uploadId is null"); + this.partNumber = partNumber; + } + + public static OmMultipartPartKey of(String uploadId, int partNumber) { + return new OmMultipartPartKey(uploadId, partNumber); + } + + public static OmMultipartPartKey prefix(String uploadId) { + return new OmMultipartPartKey(uploadId, null); + } + + public static Codec<OmMultipartPartKey> getCodec() { + return CODEC; + } + + public String getUploadId() { + return uploadId; + } + + public Integer getPartNumber() { + return partNumber; + } + + public boolean hasPartNumber() { + return partNumber != null; + } + + @Override + public String toString() { + return hasPartNumber() ? uploadId + "/" + partNumber : uploadId; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof OmMultipartPartKey)) { + return false; + } + OmMultipartPartKey that = (OmMultipartPartKey) o; + return Objects.equals(uploadId, that.uploadId) + && Objects.equals(partNumber, that.partNumber); + } + + @Override + public int hashCode() { + return Objects.hash(uploadId, partNumber); + } + + private static final class OmMultipartPartKeyCodec + implements Codec<OmMultipartPartKey> { Review Comment: Implemented this in the current change itself, added new tests to validate that the change is working fine. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
