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

Konstantin Shvachko edited comment on HDFS-7831 at 2/24/15 7:34 AM:
--------------------------------------------------------------------

{{binarySearch(diffs, snapshotId)}} returns {{i == -insertPoint-1}}, where 
{{insertPoint}} is the index of the first element greater than the key. So if 
the {{snapshotId}} is not found then we can start searching backwards from 
{{insertPoint-1 == -i-2}}.
Current code start with {{-i == insertPoint+1}} and unnecessarily checks two 
extra elements.


was (Author: shv):
{{binarySearch(diffs, snapshotId)}} returns {{i == -insertPoint-1}}, where 
{{insertPoint}} is the index of the first element greater than the key. So if 
the {{snapshotId}} is not found then we can start searching backwards from 
{{insertPoint-1 == -i-2}}.
So we are checking two extra elements.

> Fix the starting index of the loop in 
> FileDiffList.findEarlierSnapshotBlocks().
> -------------------------------------------------------------------------------
>
>                 Key: HDFS-7831
>                 URL: https://issues.apache.org/jira/browse/HDFS-7831
>             Project: Hadoop HDFS
>          Issue Type: Bug
>    Affects Versions: 2.7.0
>            Reporter: Konstantin Shvachko
>
> Currently the loop in {{FileDiffList.findEarlierSnapshotBlocks()}} starts 
> from {{insertPoint + 1}}. It should start from {{insertPoint - 1}}. As noted 
> in [Jing's 
> comment|https://issues.apache.org/jira/browse/HDFS-7056?focusedCommentId=14333864&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14333864]



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to