adoroszlai commented on code in PR #4628:
URL: https://github.com/apache/ozone/pull/4628#discussion_r1180207650


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/impl/BlockManagerImpl.java:
##########
@@ -222,6 +190,65 @@ public static long persistPutBlock(KeyValueContainer 
container,
     }
   }
 
+  private static boolean updateDBForPutBlock(BlockData data,
+      KeyValueContainerData containerData, DBHandle db, long bcsId,
+      long localID, boolean isBlockInCache,
+      BatchOperation batch) throws IOException {
+    boolean incrBlockCount = false;
+    Table<String, BlockData> blockDataTable = 
db.getStore().getBlockDataTable();
+    String blockKey = containerData.getBlockKey(localID);
+    // If the block does not exist in the pendingPutBlockCache of the
+    // container, then check the DB to ascertain if it exists or not.
+    // If block exists in cache, blockCount should not be incremented.
+    BlockData existingBlockData;
+    if (!isBlockInCache) {
+      existingBlockData = blockDataTable.get(blockKey);
+      if (existingBlockData == null) {
+        // Block does not exist in DB => blockCount needs to be
+        // incremented when the block is added into DB.
+        incrBlockCount = true;
+      }
+    } else {
+      existingBlockData = blockDataTable.get(blockKey);
+    }
+
+    // if the block is new, the BlockData will be stored in its entirety.
+    if (existingBlockData == null) {
+      blockDataTable.putWithBatch(batch, blockKey, data);
+    } else {
+      // otherwise, the chunk is appended to an existing block
+      // create a new list since the existing list may be unmodifiable.
+      List<ContainerProtos.ChunkInfo> updatedChunks =
+          new ArrayList<>(existingBlockData.getChunks());
+      updatedChunks.addAll(data.getChunks());
+      data.setChunks(updatedChunks);

Review Comment:
   I think this should be done only if client is new, i.e. has the optimization 
being introduced.  Old client will send complete list of chunks, resulting in 
duplication in the DB.



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

Reply via email to