yihua commented on code in PR #12866:
URL: https://github.com/apache/hudi/pull/12866#discussion_r2105453576


##########
hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileBlock.java:
##########
@@ -68,43 +77,38 @@ static class Header {
   }
 
   protected final HFileContext context;
-  protected final byte[] byteBuff;
-  protected final int startOffsetInBuff;
-  protected final int sizeCheckSum;
-  protected final int uncompressedEndOffset;
   private final HFileBlockType blockType;
-  protected final int onDiskSizeWithoutHeader;
-  protected final int uncompressedSizeWithoutHeader;
-  protected final int bytesPerChecksum;
-  private boolean isUnpacked = false;
-  protected byte[] compressedByteBuff;
-  protected int startOffsetInCompressedBuff;
 
+  protected Option<HFileBlockReadAttributes> readAttributesOpt;
+  protected Option<HFileBlockWriteAttributes> writeAttributesOpt;
+
+  /**
+   * Initialize HFileBlock for read.
+   */
   protected HFileBlock(HFileContext context,
                        HFileBlockType blockType,
                        byte[] byteBuff,
                        int startOffsetInBuff) {
     this.context = context;
     this.blockType = blockType;
-    this.onDiskSizeWithoutHeader = readInt(
-        byteBuff, startOffsetInBuff + 
Header.ON_DISK_SIZE_WITHOUT_HEADER_INDEX);
-    this.uncompressedSizeWithoutHeader = readInt(
-        byteBuff, startOffsetInBuff + 
Header.UNCOMPRESSED_SIZE_WITHOUT_HEADER_INDEX);
-    this.bytesPerChecksum = readInt(
-        byteBuff, startOffsetInBuff + Header.BYTES_PER_CHECKSUM_INDEX);
-    this.sizeCheckSum = numChecksumBytes(getOnDiskSizeWithHeader(), 
bytesPerChecksum);
-    if (CompressionCodec.NONE.equals(context.getCompressionCodec())) {
-      isUnpacked = true;
-      this.startOffsetInBuff = startOffsetInBuff;
-      this.byteBuff = byteBuff;
-    } else {
-      this.startOffsetInCompressedBuff = startOffsetInBuff;
-      this.compressedByteBuff = byteBuff;
-      this.startOffsetInBuff = 0;
-      this.byteBuff = allocateBufferForUnpacking();
-    }
-    this.uncompressedEndOffset =
-        this.startOffsetInBuff + HFILEBLOCK_HEADER_SIZE + 
uncompressedSizeWithoutHeader;
+    HFileBlockReadAttributes readAttributes =
+        new HFileBlockReadAttributes(this.context, byteBuff, 
startOffsetInBuff);
+    this.readAttributesOpt = Option.of(readAttributes);

Review Comment:
   ```suggestion
       this.readAttributesOpt = Option.of(new 
HFileBlockReadAttributes(this.context, byteBuff, startOffsetInBuff));
   ```



##########
hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileBlockWriteAttributes.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.hudi.io.hfile;
+
+public class HFileBlockWriteAttributes {
+  public static final int DEFAULT_BYTES_PER_CHECKSUM = 16 * 1024;
+  public static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
+  public static final ChecksumType CHECKSUM_TYPE = ChecksumType.NULL;

Review Comment:
   ```suggestion
     public static final ChecksumType DEFAULT_CHECKSUM_TYPE = ChecksumType.NULL;
   ```



##########
hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileBlockWriteAttributes.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.hudi.io.hfile;
+
+public class HFileBlockWriteAttributes {

Review Comment:
   This class does not seem to provide much value.  Could you shed light on how 
this makes the logic better?



##########
hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileBlockReadAttributes.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.hudi.io.hfile;
+
+import org.apache.hudi.io.compress.CompressionCodec;
+
+import static org.apache.hudi.io.hfile.HFileBlock.HFILEBLOCK_HEADER_SIZE;
+import static org.apache.hudi.io.util.IOUtils.readInt;
+
+public class HFileBlockReadAttributes {

Review Comment:
   `HFileBlockReadAttributes` and `HFileBlockWriteAttributes` are only used by 
`HFileBlock` so let's have these two classes as nested classes in `HFileBlock` 
without being public outside.  Similarly, make these member variables default 
visibility.



##########
hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileBlock.java:
##########
@@ -68,43 +77,38 @@ static class Header {
   }
 
   protected final HFileContext context;
-  protected final byte[] byteBuff;
-  protected final int startOffsetInBuff;
-  protected final int sizeCheckSum;
-  protected final int uncompressedEndOffset;
   private final HFileBlockType blockType;
-  protected final int onDiskSizeWithoutHeader;
-  protected final int uncompressedSizeWithoutHeader;
-  protected final int bytesPerChecksum;
-  private boolean isUnpacked = false;
-  protected byte[] compressedByteBuff;
-  protected int startOffsetInCompressedBuff;
 
+  protected Option<HFileBlockReadAttributes> readAttributesOpt;
+  protected Option<HFileBlockWriteAttributes> writeAttributesOpt;

Review Comment:
   Let's make these final as before so it's easier to guarantee immutability 
and correctness.



##########
hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileBlockWriteAttributes.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.hudi.io.hfile;
+
+public class HFileBlockWriteAttributes {
+  public static final int DEFAULT_BYTES_PER_CHECKSUM = 16 * 1024;
+  public static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
+  public static final ChecksumType CHECKSUM_TYPE = ChecksumType.NULL;
+  protected long startOffsetInBuff = -1;
+  protected long previousBlockOffset = -1;
+  protected int blockSize;

Review Comment:
   Use default visibility in nested class



##########
hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileBlockWriteAttributes.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.hudi.io.hfile;
+
+public class HFileBlockWriteAttributes {
+  public static final int DEFAULT_BYTES_PER_CHECKSUM = 16 * 1024;
+  public static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
+  public static final ChecksumType CHECKSUM_TYPE = ChecksumType.NULL;
+  protected long startOffsetInBuff = -1;
+  protected long previousBlockOffset = -1;
+  protected int blockSize;

Review Comment:
   Should all of these be final?



##########
hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileBlockWriteAttributes.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.hudi.io.hfile;
+
+public class HFileBlockWriteAttributes {
+  public static final int DEFAULT_BYTES_PER_CHECKSUM = 16 * 1024;
+  public static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
+  public static final ChecksumType CHECKSUM_TYPE = ChecksumType.NULL;
+  protected long startOffsetInBuff = -1;
+  protected long previousBlockOffset = -1;
+  protected int blockSize;
+
+  public HFileBlockWriteAttributes(long startOffsetInBuff, long 
previousBlockOffset, int blockSize) {
+    this.startOffsetInBuff = startOffsetInBuff;
+    this.previousBlockOffset = -1;

Review Comment:
   `previousBlockOffset` not used?



-- 
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]

Reply via email to