aryangupta1998 commented on a change in pull request #1885:
URL: https://github.com/apache/ozone/pull/1885#discussion_r592785877



##########
File path: 
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/RandomContainerDeletionChoosingPolicy.java
##########
@@ -40,33 +41,51 @@
       LoggerFactory.getLogger(RandomContainerDeletionChoosingPolicy.class);
 
   @Override
-  public List<ContainerData> chooseContainerForBlockDeletion(int count,
-      Map<Long, ContainerData> candidateContainers)
+  public List<ContainerBlockInfo> chooseContainerForBlockDeletion(
+      int blockCount, Map<Long, ContainerData> candidateContainers)
       throws StorageContainerException {
     Preconditions.checkNotNull(candidateContainers,
         "Internal assertion: candidate containers cannot be null");
 
-    int currentCount = 0;
-    List<ContainerData> result = new LinkedList<>();
+    List<ContainerBlockInfo> result = new ArrayList<>();
     ContainerData[] values = new ContainerData[candidateContainers.size()];
     // to get a shuffle list
     ContainerData[] shuffled = candidateContainers.values().toArray(values);
     ArrayUtils.shuffle(shuffled);
+
+    // Here we are returning containers based on totalBlocks which is basically
+    // number of blocks to be deleted in an interval. We are also considering
+    // the boundary case where the blocks of the last container exceeds the
+    // number of blocks to be deleted in an interval, there we return that
+    // container but with container we also return an integer so that total
+    // blocks don't exceed the number of blocks to be deleted in an interval.
+
+    int flag = 0;
     for (ContainerData entry : shuffled) {
-      if (currentCount < count) {
-        result.add(entry);
-        currentCount++;
+      if (((KeyValueContainerData) entry).getNumPendingDeletionBlocks() > 0) {
+        blockCount -=
+            ((KeyValueContainerData) entry).getNumPendingDeletionBlocks();
+        if (blockCount >= 0) {
+          result.add(new ContainerBlockInfo(entry,
+              ((KeyValueContainerData) entry).getNumPendingDeletionBlocks()));
+        } else if (flag == 0 && blockCount < 0) {
+          result.add(new ContainerBlockInfo(entry,
+              ((KeyValueContainerData) entry).getNumPendingDeletionBlocks()
+                  + blockCount));
+          flag = 1;
+        } else {
+          break;
+        }

Review comment:
       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.

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