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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]