Github user poornachandra commented on a diff in the pull request:

    https://github.com/apache/incubator-tephra/pull/62#discussion_r140183601
  
    --- Diff: 
tephra-hbase-compat-1.1-base/src/main/java/org/apache/tephra/hbase/txprune/InvalidListPruningDebugTool.java
 ---
    @@ -204,16 +204,19 @@ public int compare(RegionPruneInfo o1, 
RegionPruneInfo o2) {
             return Long.compare(o1.getPruneUpperBound(), 
o2.getPruneUpperBound());
           }
         };
    -    Queue<RegionPruneInfoPretty> lowestPrunes =
    +    MinMaxPriorityQueue<RegionPruneInfoPretty> lowestPrunes =
           
MinMaxPriorityQueue.orderedBy(comparator).maximumSize(numRegions).create();
     
         for (RegionPruneInfo pruneInfo : regionPruneInfos) {
           lowestPrunes.add(new RegionPruneInfoPretty(pruneInfo));
         }
     
    -    TreeSet<RegionPruneInfoPretty> regionSet = new TreeSet<>(comparator);
    -    regionSet.addAll(lowestPrunes);
    -    return regionSet;
    +    List<RegionPruneInfoPretty> regions = new ArrayList<>(numRegions);
    +    RegionPruneInfoPretty e;
    +    while ((e = lowestPrunes.pollFirst()) != null) {
    --- End diff --
    
    I noticed that `addAll()` can use a for loop to iterate over the elements 
of the priority queue, and adds the element to the destination collection.
    
    The javadoc for the `MinMaxPriorityQueue.iterator()` says - 
    ```
    Returns an iterator over the elements contained in this collection, in no 
particular order
    ```
    Hence `addAll()` may not be safe for preserving the order when adding to 
the list. But since we are moving back to `TreeSet`, we can use `addAll()` 
again.


---

Reply via email to