linliu-code commented on code in PR #12866:
URL: https://github.com/apache/hudi/pull/12866#discussion_r2105905577


##########
hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileMetaBlock.java:
##########
@@ -34,6 +36,44 @@ protected HFileMetaBlock(HFileContext context,
   public ByteBuffer readContent() {
     return ByteBuffer.wrap(
         getByteBuff(),
-        startOffsetInBuff + HFILEBLOCK_HEADER_SIZE, 
uncompressedSizeWithoutHeader);
+        readAttributesOpt.get().startOffsetInBuff + HFILEBLOCK_HEADER_SIZE,
+        readAttributesOpt.get().uncompressedSizeWithoutHeader);
+  }
+
+  // ================ Below are for Write ================
+
+  protected final List<KeyValueEntry> entries = new ArrayList<>();
+
+  public HFileMetaBlock(HFileContext context) {
+    super(context, HFileBlockType.META, -1L);
+  }
+
+  public byte[] getFirstKey() {
+    return entries.get(0).key;
+  }
+
+  public void add(byte[] key, byte[] value) {
+    KeyValueEntry kv = new KeyValueEntry(key, value);
+    add(kv, false);
+  }
+
+  protected void add(KeyValueEntry kv, boolean sorted) {
+    entries.add(kv);
+    if (sorted) {
+      entries.sort(KeyValueEntry::compareTo);
+    }
+  }
+
+  @Override
+  public ByteBuffer getPayload() {
+    ByteBuffer dataBuf = ByteBuffer.allocate(context.getBlockSize());
+    // Rule 1: there must be only one key-value entry.
+    assert (1 == entries.size())
+        : "only 1 value is allowed in meta block";
+    // Rule 2: only value should be store in the block.
+    // The key is stored in the meta index block.
+    dataBuf.put(entries.get(0).value);

Review Comment:
   Right. Done.



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