HDFS-4307. SocketCache should use monotonic time. Contributed by Colin Patrick McCabe.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1421573 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Aaron Myers 2012-12-13 22:13:07 +00:00
parent 7f341b7b39
commit eed48f54f5
2 changed files with 9 additions and 5 deletions

View File

@ -321,6 +321,9 @@ Release 2.0.3-alpha - Unreleased
HDFS-4295. Using port 1023 should be valid when starting Secure DataNode HDFS-4295. Using port 1023 should be valid when starting Secure DataNode
(Stephen Chu via todd) (Stephen Chu via todd)
HDFS-4307. SocketCache should use monotonic time. (Colin Patrick McCabe
via atm)
BREAKDOWN OF HDFS-3077 SUBTASKS BREAKDOWN OF HDFS-3077 SUBTASKS
HDFS-3077. Quorum-based protocol for reading and writing edit logs. HDFS-3077. Quorum-based protocol for reading and writing edit logs.

View File

@ -37,6 +37,7 @@
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.util.Daemon; import org.apache.hadoop.util.Daemon;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.apache.hadoop.util.Time;
/** /**
* A cache of input stream sockets to Data Node. * A cache of input stream sockets to Data Node.
@ -53,7 +54,7 @@ static class SocketAndStreams implements Closeable {
public SocketAndStreams(Socket s, IOStreamPair ioStreams) { public SocketAndStreams(Socket s, IOStreamPair ioStreams) {
this.sock = s; this.sock = s;
this.ioStreams = ioStreams; this.ioStreams = ioStreams;
this.createTime = System.currentTimeMillis(); this.createTime = Time.monotonicNow();
} }
@Override @Override
@ -205,7 +206,7 @@ private synchronized void evictExpired(long expiryPeriod) {
Entry<SocketAddress, SocketAndStreams> entry = iter.next(); Entry<SocketAddress, SocketAndStreams> entry = iter.next();
// if oldest socket expired, remove it // if oldest socket expired, remove it
if (entry == null || if (entry == null ||
System.currentTimeMillis() - entry.getValue().getCreateTime() < Time.monotonicNow() - entry.getValue().getCreateTime() <
expiryPeriod) { expiryPeriod) {
break; break;
} }
@ -236,13 +237,13 @@ private synchronized void evictOldest() {
* older than expiryPeriod minutes * older than expiryPeriod minutes
*/ */
private void run() throws InterruptedException { private void run() throws InterruptedException {
for(long lastExpiryTime = System.currentTimeMillis(); for(long lastExpiryTime = Time.monotonicNow();
!Thread.interrupted(); !Thread.interrupted();
Thread.sleep(expiryPeriod)) { Thread.sleep(expiryPeriod)) {
final long elapsed = System.currentTimeMillis() - lastExpiryTime; final long elapsed = Time.monotonicNow() - lastExpiryTime;
if (elapsed >= expiryPeriod) { if (elapsed >= expiryPeriod) {
evictExpired(expiryPeriod); evictExpired(expiryPeriod);
lastExpiryTime = System.currentTimeMillis(); lastExpiryTime = Time.monotonicNow();
} }
} }
clear(); clear();