eolivelli commented on a change in pull request #704: BOOKKEEPER-1040: Use 
separate log for compaction and add transaction support
URL: https://github.com/apache/bookkeeper/pull/704#discussion_r149358372
 
 

 ##########
 File path: 
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java
 ##########
 @@ -423,51 +337,26 @@ private void doGcEntryLogs() {
      */
     @VisibleForTesting
     void doCompactEntryLogs(double threshold) {
-        LOG.info("Do compaction to compact those files lower than " + 
threshold);
+        LOG.info("Do compaction to compact those files lower than {}", 
threshold);
         // sort the ledger meta by occupied unused space
-        Comparator<EntryLogMetadata> sizeComparator = new 
Comparator<EntryLogMetadata>() {
-            @Override
-            public int compare(EntryLogMetadata m1, EntryLogMetadata m2) {
-                long unusedSize1 = m1.getTotalSize() - m1.getRemainingSize();
-                long unusedSize2 = m2.getTotalSize() - m2.getRemainingSize();
-                if (unusedSize1 > unusedSize2) {
-                    return -1;
-                } else if (unusedSize1 < unusedSize2) {
-                    return 1;
-                } else {
-                    return 0;
-                }
-            }
+        // sort the ledger meta by occupied unused space
+        Comparator<EntryLogMetadata> usageComparator = (m1, m2) -> {
+            double usage1 = m1.getUsage();
+            double usage2 = m2.getUsage();
+            return Double.compare(usage1, usage2);
         };
         List<EntryLogMetadata> logsToCompact = new 
ArrayList<EntryLogMetadata>();
         logsToCompact.addAll(entryLogMetaMap.values());
-        Collections.sort(logsToCompact, sizeComparator);
+        Collections.sort(logsToCompact, usageComparator);
 
 Review comment:
   what about something like this ?
   
   `logsToCompact.sort(Comparator.comparing(EntryLogMetadata::getUsage)`
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to