[ https://issues.apache.org/jira/browse/HDFS-10663?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16920888#comment-16920888 ]
hemanthboyina commented on HDFS-10663: -------------------------------------- hi [~shahrs87] can i take up this Jira ? > Comparison of two System.nanoTime methods return values are against standard > java recommendations. > -------------------------------------------------------------------------------------------------- > > Key: HDFS-10663 > URL: https://issues.apache.org/jira/browse/HDFS-10663 > Project: Hadoop HDFS > Issue Type: Bug > Components: namenode > Reporter: Rushabh S Shah > Assignee: Rushabh S Shah > Priority: Major > > I was chasing a bug where the namenode didn't declare a datanode dead even > when the last contact time was 2.5 hours before. > Before I could debug, the datanode was re-imaged (all the logs were deleted) > and the namenode was restarted and upgraded to new software. > While debugging, I came across this heartbeat check code where the comparison > of two System.nanoTime is against the java's recommended way. > Here is the hadoop code: > {code:title=DatanodeManager.java|borderStyle=solid} > /** Is the datanode dead? */ > boolean isDatanodeDead(DatanodeDescriptor node) { > return (node.getLastUpdateMonotonic() < > (monotonicNow() - heartbeatExpireInterval)); > } > {code} > The montonicNow() is calculated as: > {code:title=Time.java|borderStyle=solid} > public static long monotonicNow() { > final long NANOSECONDS_PER_MILLISECOND = 1000000; > return System.nanoTime() / NANOSECONDS_PER_MILLISECOND; > } > {code} > As per javadoc of System.nanoTime, it is clearly stated that we should > subtract two nano time output > {noformat} > To compare two nanoTime values > long t0 = System.nanoTime(); > ... > long t1 = System.nanoTime(); > one should use t1 - t0 < 0, not t1 < t0, because of the possibility of > numerical overflow. > {noformat} -- This message was sent by Atlassian Jira (v8.3.2#803003) --------------------------------------------------------------------- To unsubscribe, e-mail: hdfs-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: hdfs-issues-h...@hadoop.apache.org