Rushabh S Shah created HDFS-10663:
-------------------------------------
Summary: Comparison of two System.nanoTimes methods return values
are against standard java recoemmendations.
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
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 upgraded to new software.
While debugging, I came across this heartbeat check code where the comparison
of two System.nanoTime is against the java 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
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]