jhungund commented on code in PR #6250:
URL: https://github.com/apache/hbase/pull/6250#discussion_r1767977754


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketProtoUtils.java:
##########
@@ -62,31 +61,29 @@ static BucketCacheProtos.BucketCacheEntry toPB(BucketCache 
cache,
       .build();
   }
 
-  public static void serializeAsPB(BucketCache cache, FileOutputStream fos, 
long chunkSize,
-    long numChunks) throws IOException {
+  public static void serializeAsPB(BucketCache cache, FileOutputStream fos, 
long chunkSize)
+    throws IOException {
+    // Write the new version of magic number.
+    fos.write(PB_MAGIC_V2);
+
     int blockCount = 0;
-    int chunkCount = 0;
     int backingMapSize = cache.backingMap.size();
     BucketCacheProtos.BackingMap.Builder builder = 
BucketCacheProtos.BackingMap.newBuilder();
-
-    fos.write(PB_MAGIC_V2);
-    fos.write(Bytes.toBytes(chunkSize));
-    fos.write(Bytes.toBytes(numChunks));
-
+    boolean firstChunkPersisted = false;
     BucketCacheProtos.BackingMapEntry.Builder entryBuilder =
       BucketCacheProtos.BackingMapEntry.newBuilder();
+
     for (Map.Entry<BlockCacheKey, BucketEntry> entry : 
cache.backingMap.entrySet()) {
       blockCount++;
       entryBuilder.clear();
       entryBuilder.setKey(BucketProtoUtils.toPB(entry.getKey()));
       entryBuilder.setValue(BucketProtoUtils.toPB(entry.getValue()));
       builder.addEntry(entryBuilder.build());
-
       if (blockCount % chunkSize == 0 || (blockCount == backingMapSize)) {
-        chunkCount++;
-        if (chunkCount == 1) {
+        if (firstChunkPersisted == false) {
           // Persist all details along with the first chunk into 
BucketCacheEntry
           BucketProtoUtils.toPB(cache, builder.build()).writeDelimitedTo(fos);
+          firstChunkPersisted = true;
         } else {
           // Directly persist subsequent backing-map chunks.
           builder.build().writeDelimitedTo(fos);

Review Comment:
   ack!



-- 
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: issues-unsubscr...@hbase.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to