Skip to content

Commit 91432fe

Browse files
committed
HDFS-4307. SocketCache should use monotonic time. Contributed by Colin Patrick McCabe.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1421572 13f79535-47bb-0310-9956-ffa450edef68
1 parent aa94456 commit 91432fe

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,9 @@ Release 2.0.3-alpha - Unreleased
610610
HDFS-2264. NamenodeProtocol has the wrong value for clientPrincipal in
611611
KerberosInfo annotation. (atm)
612612

613+
HDFS-4307. SocketCache should use monotonic time. (Colin Patrick McCabe
614+
via atm)
615+
613616
BREAKDOWN OF HDFS-3077 SUBTASKS
614617

615618
HDFS-3077. Quorum-based protocol for reading and writing edit logs.

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/SocketCache.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.hadoop.io.IOUtils;
3838
import org.apache.hadoop.util.Daemon;
3939
import org.apache.hadoop.util.StringUtils;
40+
import org.apache.hadoop.util.Time;
4041

4142
/**
4243
* A cache of input stream sockets to Data Node.
@@ -53,7 +54,7 @@ static class SocketAndStreams implements Closeable {
5354
public SocketAndStreams(Socket s, IOStreamPair ioStreams) {
5455
this.sock = s;
5556
this.ioStreams = ioStreams;
56-
this.createTime = System.currentTimeMillis();
57+
this.createTime = Time.monotonicNow();
5758
}
5859

5960
@Override
@@ -205,7 +206,7 @@ private synchronized void evictExpired(long expiryPeriod) {
205206
Entry<SocketAddress, SocketAndStreams> entry = iter.next();
206207
// if oldest socket expired, remove it
207208
if (entry == null ||
208-
System.currentTimeMillis() - entry.getValue().getCreateTime() <
209+
Time.monotonicNow() - entry.getValue().getCreateTime() <
209210
expiryPeriod) {
210211
break;
211212
}
@@ -236,13 +237,13 @@ private synchronized void evictOldest() {
236237
* older than expiryPeriod minutes
237238
*/
238239
private void run() throws InterruptedException {
239-
for(long lastExpiryTime = System.currentTimeMillis();
240+
for(long lastExpiryTime = Time.monotonicNow();
240241
!Thread.interrupted();
241242
Thread.sleep(expiryPeriod)) {
242-
final long elapsed = System.currentTimeMillis() - lastExpiryTime;
243+
final long elapsed = Time.monotonicNow() - lastExpiryTime;
243244
if (elapsed >= expiryPeriod) {
244245
evictExpired(expiryPeriod);
245-
lastExpiryTime = System.currentTimeMillis();
246+
lastExpiryTime = Time.monotonicNow();
246247
}
247248
}
248249
clear();

0 commit comments

Comments
 (0)