HesandaLiyanage commented on code in PR #3193: URL: https://github.com/apache/james-project/pull/3193#discussion_r4070309208
########## server/blob/blob-compaction/src/main/java/org/apache/james/blob/compaction/BlobSlot.java: ########## @@ -0,0 +1,81 @@ +/**************************************************************** + * 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.james.blob.compaction; + +import java.util.Arrays; +import java.util.Objects; +import java.util.zip.CRC32C; + +import org.apache.james.blob.api.ObjectStoreIOException; + +import com.github.luben.zstd.Zstd; + +public record BlobSlot(long contentStart, int crc32c, long originalSize, byte[] compressedContent) { + public byte[] decompress() throws ObjectStoreIOException { + if (originalSize < 0 || originalSize > Integer.MAX_VALUE) { + throw new ObjectStoreIOException("Invalid original size in chunk slot: " + originalSize); + } + byte[] decompressed; + if (originalSize == 0) { + decompressed = new byte[0]; + } else { + try { + decompressed = Zstd.decompress(compressedContent, (int) originalSize); + } catch (Exception e) { + throw new ObjectStoreIOException("Failed to decompress slot content at " + contentStart, e); + } + } + + if (decompressed.length != originalSize) { + throw new ObjectStoreIOException("Decompressed size " + decompressed.length + " does not match expected " + originalSize); + } + + CRC32C crc = new CRC32C(); + crc.update(decompressed); + int computedCrc = (int) crc.getValue(); + if (computedCrc != crc32c) { + throw new ObjectStoreIOException(String.format("CRC mismatch for chunk slot at offset %d: expected %d, got %d", + contentStart, crc32c, computedCrc)); + } + + return decompressed; + } Review Comment: Done. Decompression has been removed from `BlobSlot` and `ChunkedBlobStoreDAO`, preserving the original `content-encoding` and `content-original-size` metadata in chunk slots so that `ZstdBlobStoreDAO` handles decompression transparently. -- 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]
