[ 
https://issues.apache.org/jira/browse/HDFS-14104?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16722224#comment-16722224
 ] 

Lokesh Jain edited comment on HDFS-14104 at 12/15/18 5:56 PM:
--------------------------------------------------------------

[~belugabehr] Thanks for working on this! The patch looks good to me. I think 
we can avoid creating new set and list by using the stream api.
{code:java}
long toSkip =
    images.size() - Math.min(numCheckpointsToRetain, images.size());
return images.stream().map(FSImageFile::getCheckpointTxId)
    .sorted()
    .skip(toSkip)
    .findFirst()
    .orElse(0L);
{code}
 


was (Author: ljain):
[~belugabehr] Thanks for working on this! The patch looks good to me. I think 
we can avoid creating new set and list by using the stream api.
{code:java}
long toSkip =
    images.size() - Math.min(numCheckpointsToRetain, images.size());
return images.stream().map(FSImageFile::getCheckpointTxId)
    .sorted(Collections.reverseOrder())
    .skip(toSkip)
    .findFirst()
    .orElse(0L);
{code}
 

> Review getImageTxIdToRetain
> ---------------------------
>
>                 Key: HDFS-14104
>                 URL: https://issues.apache.org/jira/browse/HDFS-14104
>             Project: Hadoop HDFS
>          Issue Type: Improvement
>          Components: namenode
>    Affects Versions: 3.0.0
>            Reporter: BELUGA BEHR
>            Assignee: BELUGA BEHR
>            Priority: Minor
>         Attachments: HDFS-14104.1.patch, HDFS-14104.1.patch, 
> HDFS-14104.1.patch
>
>
> {code:java|title=NNStorageRetentionManager.java}
>   private long getImageTxIdToRetain(FSImageTransactionalStorageInspector 
> inspector) {
>       
>     List<FSImageFile> images = inspector.getFoundImages();
>     TreeSet<Long> imageTxIds = Sets.newTreeSet();
>     for (FSImageFile image : images) {
>       imageTxIds.add(image.getCheckpointTxId());
>     }
>     
>     List<Long> imageTxIdsList = Lists.newArrayList(imageTxIds);
>     if (imageTxIdsList.isEmpty()) {
>       return 0;
>     }
>     
>     Collections.reverse(imageTxIdsList);
>     int toRetain = Math.min(numCheckpointsToRetain, imageTxIdsList.size());   
>  
>     long minTxId = imageTxIdsList.get(toRetain - 1);
>     LOG.info("Going to retain " + toRetain + " images with txid >= " +
>         minTxId);
>     return minTxId;
>   }
> {code}
> # Fix check style issues
> # Use SLF4J paramaterized logging
> # A lot of work gets done before checking if the list actually contains any 
> entries and returning a 0.  That should be the first thing that happens
> # Instead of building up the {{TreeSet}} in its natural order, then reversing 
> the collection, simply use a reverse natural ordering to begin with and save 
> a step.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: hdfs-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: hdfs-issues-h...@hadoop.apache.org

Reply via email to