[
https://issues.apache.org/jira/browse/HADOOP-17463?focusedWorklogId=606159&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-606159
]
ASF GitHub Bot logged work on HADOOP-17463:
-------------------------------------------
Author: ASF GitHub Bot
Created on: 03/Jun/21 19:41
Start Date: 03/Jun/21 19:41
Worklog Time Spent: 10m
Work Description: jbrennan333 commented on a change in pull request #2615:
URL: https://github.com/apache/hadoop/pull/2615#discussion_r645071212
##########
File path:
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/nativeio/NativeIO.java
##########
@@ -620,7 +621,7 @@ private static String getName(IdCache domain, int id)
throws IOException {
? USER_ID_NAME_CACHE : GROUP_ID_NAME_CACHE;
String name;
CachedName cachedName = idNameCache.get(id);
- long now = System.currentTimeMillis();
+ long now = Time.monotonicNow();
if (cachedName != null && (cachedName.timestamp + cacheTimeout) > now) {
Review comment:
When switching from System.currentTimeMillis, or Time.now() to
Time.monotonicNow(), keep in mind that the latter can return a negative number.
In this case, cachedName.timestamp could be negative due to overflow, while
now might still be positive, in which case this code will not take the right
path. The correct comparison would be `((now - cachedName.timestamp) <
cacheTimeout)`
But I would also avoid using monitonicNow for any field called `timestamp`.
##########
File path:
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestReconfiguration.java
##########
@@ -317,8 +317,8 @@ public void testThread() throws ReconfigurationException {
}
dummy.reconfigureProperty(PROP1, VAL2);
- long endWait = Time.now() + 2000;
- while (dummyThread.isAlive() && Time.now() < endWait) {
+ long endWait = Time.monotonicNow() + 2000;
+ while (dummyThread.isAlive() && Time.monotonicNow() < endWait) {
Review comment:
Another dangerous comparison.
##########
File path:
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RPC.java
##########
@@ -419,7 +419,7 @@ public RpcErrorCodeProto getRpcErrorCodeProto() {
ioe = nrthe;
}
// check if timed out
- if (Time.now()-timeout >= startTime) {
+ if (Time.monotonicNow() - timeout >= startTime) {
Review comment:
Similarly, I think `Time.monotonicNow() - startTime >= timeout` would be
better here.
##########
File path:
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/CacheableIPList.java
##########
@@ -48,7 +48,7 @@ private void updateCacheExpiryTime() {
if (cacheTimeout < 0) {
cacheExpiryTimeStamp = -1; // no automatic cache expiry.
}else {
- cacheExpiryTimeStamp = System.currentTimeMillis() + cacheTimeout;
+ cacheExpiryTimeStamp = Time.monotonicNow() + cacheTimeout;
Review comment:
Timestamps should use currentTimeMillis or similar.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 606159)
Time Spent: 1h 10m (was: 1h)
> Replace currentTimeMillis with monotonicNow in elapsed time
> -----------------------------------------------------------
>
> Key: HADOOP-17463
> URL: https://issues.apache.org/jira/browse/HADOOP-17463
> Project: Hadoop Common
> Issue Type: Bug
> Reporter: Ahmed Hussein
> Assignee: Ahmed Hussein
> Priority: Major
> Labels: pull-request-available
> Time Spent: 1h 10m
> Remaining Estimate: 0h
>
> I noticed that there is a widespread incorrect usage of
> {{System.currentTimeMillis()}} throughout the hadoop code.
> For example:
> {code:java}
> // Some comments here
> long start = System.currentTimeMillis();
> while (System.currentTimeMillis() - start < timeout) {
> // Do something
> }
> {code}
> Elapsed time should be measured using `monotonicNow()`.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]