Skip to content

Commit 770b571

Browse files
committed
HDFS-3641. Move server Util time methods to common and use now instead of System#currentTimeMillis. Contributed by Eli Collins
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1360858 13f79535-47bb-0310-9956-ffa450edef68
1 parent b3732e7 commit 770b571

File tree

136 files changed

+628
-479
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+628
-479
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegationTokenRenewer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.hadoop.classification.InterfaceAudience;
2828
import org.apache.hadoop.security.token.Token;
2929
import org.apache.hadoop.security.token.TokenIdentifier;
30+
import org.apache.hadoop.util.Time;
3031

3132
/**
3233
* A daemon thread that waits for the next file system to renew.
@@ -62,7 +63,7 @@ private RenewAction(final T fs) {
6263
/** Get the delay until this event should happen. */
6364
@Override
6465
public long getDelay(final TimeUnit unit) {
65-
final long millisLeft = renewalTime - System.currentTimeMillis();
66+
final long millisLeft = renewalTime - Time.now();
6667
return unit.convert(millisLeft, TimeUnit.MILLISECONDS);
6768
}
6869

@@ -92,7 +93,7 @@ public boolean equals(final Object that) {
9293
* @param newTime the new time
9394
*/
9495
private void updateRenewalTime() {
95-
renewalTime = RENEW_CYCLE + System.currentTimeMillis();
96+
renewalTime = RENEW_CYCLE + Time.now();
9697
}
9798

9899
/**

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.hadoop.fs.Options.Rename;
3939
import org.apache.hadoop.fs.permission.FsAction;
4040
import org.apache.hadoop.fs.permission.FsPermission;
41+
import org.apache.hadoop.util.Time;
4142

4243
/** Provides a <i>trash</i> feature. Files are moved to a user's trash
4344
* directory, a subdirectory of their home directory named ".Trash". Files are
@@ -136,7 +137,7 @@ public boolean moveToTrash(Path path) throws IOException {
136137
String orig = trashPath.toString();
137138

138139
while(fs.exists(trashPath)) {
139-
trashPath = new Path(orig + System.currentTimeMillis());
140+
trashPath = new Path(orig + Time.now());
140141
}
141142

142143
if (fs.rename(path, trashPath)) // move to current trash
@@ -187,7 +188,7 @@ public void deleteCheckpoint() throws IOException {
187188
return;
188189
}
189190

190-
long now = System.currentTimeMillis();
191+
long now = Time.now();
191192
for (int i = 0; i < dirs.length; i++) {
192193
Path path = dirs[i].getPath();
193194
String dir = path.toUri().getPath();
@@ -248,7 +249,7 @@ private class Emptier implements Runnable {
248249
public void run() {
249250
if (emptierInterval == 0)
250251
return; // trash disabled
251-
long now = System.currentTimeMillis();
252+
long now = Time.now();
252253
long end;
253254
while (true) {
254255
end = ceiling(now, emptierInterval);
@@ -259,7 +260,7 @@ public void run() {
259260
}
260261

261262
try {
262-
now = System.currentTimeMillis();
263+
now = Time.now();
263264
if (now >= end) {
264265

265266
FileStatus[] homes = null;

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.apache.hadoop.security.UserGroupInformation;
5656
import org.apache.hadoop.security.token.Token;
5757
import org.apache.hadoop.util.Progressable;
58+
import org.apache.hadoop.util.Time;
5859

5960
/**
6061
* ViewFileSystem (extends the FileSystem interface) implements a client-side
@@ -146,7 +147,7 @@ private Path makeAbsolute(final Path f) {
146147
*/
147148
public ViewFileSystem() throws IOException {
148149
ugi = UserGroupInformation.getCurrentUser();
149-
creationTime = System.currentTimeMillis();
150+
creationTime = Time.now();
150151
}
151152

152153
/**

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.apache.hadoop.security.UserGroupInformation;
5656
import org.apache.hadoop.security.token.Token;
5757
import org.apache.hadoop.util.Progressable;
58+
import org.apache.hadoop.util.Time;
5859

5960

6061
/**
@@ -192,7 +193,7 @@ public ViewFs(final Configuration conf) throws IOException,
192193
ViewFs(final URI theUri, final Configuration conf) throws IOException,
193194
URISyntaxException {
194195
super(theUri, FsConstants.VIEWFS_SCHEME, false, -1);
195-
creationTime = System.currentTimeMillis();
196+
creationTime = Time.now();
196197
ugi = UserGroupInformation.getCurrentUser();
197198
config = conf;
198199
// Now build client side view (i.e. client side mount table) from config.

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/SequenceFile.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.apache.hadoop.util.NativeCodeLoader;
4848
import org.apache.hadoop.util.MergeSort;
4949
import org.apache.hadoop.util.PriorityQueue;
50+
import org.apache.hadoop.util.Time;
5051

5152
/**
5253
* <code>SequenceFile</code>s are flat files consisting of binary key/value
@@ -835,7 +836,7 @@ public static class Writer implements java.io.Closeable, Syncable {
835836
{
836837
try {
837838
MessageDigest digester = MessageDigest.getInstance("MD5");
838-
long time = System.currentTimeMillis();
839+
long time = Time.now();
839840
digester.update((new UID()+"@"+time).getBytes());
840841
sync = digester.digest();
841842
} catch (Exception e) {

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import org.apache.hadoop.security.token.TokenSelector;
7676
import org.apache.hadoop.util.ProtoUtil;
7777
import org.apache.hadoop.util.ReflectionUtils;
78+
import org.apache.hadoop.util.Time;
7879

7980
/** A client for an IPC service. IPC calls take a single {@link Writable} as a
8081
* parameter, and return a {@link Writable} as their value. A service runs on
@@ -316,7 +317,7 @@ public Connection(ConnectionId remoteId) throws IOException {
316317

317318
/** Update lastActivity with the current time. */
318319
private void touch() {
319-
lastActivity.set(System.currentTimeMillis());
320+
lastActivity.set(Time.now());
320321
}
321322

322323
/**
@@ -762,7 +763,7 @@ private void writeConnectionContext() throws IOException {
762763
private synchronized boolean waitForWork() {
763764
if (calls.isEmpty() && !shouldCloseConnection.get() && running.get()) {
764765
long timeout = maxIdleTime-
765-
(System.currentTimeMillis()-lastActivity.get());
766+
(Time.now()-lastActivity.get());
766767
if (timeout>0) {
767768
try {
768769
wait(timeout);
@@ -792,7 +793,7 @@ public InetSocketAddress getRemoteAddress() {
792793
* since last I/O activity is equal to or greater than the ping interval
793794
*/
794795
private synchronized void sendPing() throws IOException {
795-
long curTime = System.currentTimeMillis();
796+
long curTime = Time.now();
796797
if ( curTime - lastActivity.get() >= pingInterval) {
797798
lastActivity.set(curTime);
798799
synchronized (out) {

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ProtobufRpcEngine.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.apache.hadoop.security.token.SecretManager;
4545
import org.apache.hadoop.security.token.TokenIdentifier;
4646
import org.apache.hadoop.util.ProtoUtil;
47+
import org.apache.hadoop.util.Time;
4748

4849
import com.google.common.annotations.VisibleForTesting;
4950
import com.google.protobuf.BlockingService;
@@ -185,7 +186,7 @@ public Object invoke(Object proxy, Method method, Object[] args)
185186
throws ServiceException {
186187
long startTime = 0;
187188
if (LOG.isDebugEnabled()) {
188-
startTime = System.currentTimeMillis();
189+
startTime = Time.now();
189190
}
190191

191192
HadoopRpcRequestProto rpcRequest = constructRpcRequest(method, args);
@@ -198,7 +199,7 @@ public Object invoke(Object proxy, Method method, Object[] args)
198199
}
199200

200201
if (LOG.isDebugEnabled()) {
201-
long callTime = System.currentTimeMillis() - startTime;
202+
long callTime = Time.now() - startTime;
202203
LOG.debug("Call: " + method.getName() + " " + callTime);
203204
}
204205

@@ -446,10 +447,10 @@ public Writable call(RPC.Server server, String connectionProtocolName,
446447
.mergeFrom(rpcRequest.getRequest()).build();
447448
Message result;
448449
try {
449-
long startTime = System.currentTimeMillis();
450+
long startTime = Time.now();
450451
server.rpcDetailedMetrics.init(protocolImpl.protocolClass);
451452
result = service.callBlockingMethod(methodDescriptor, null, param);
452-
int processingTime = (int) (System.currentTimeMillis() - startTime);
453+
int processingTime = (int) (Time.now() - startTime);
453454
int qTime = (int) (startTime - receiveTime);
454455
if (LOG.isDebugEnabled()) {
455456
LOG.info("Served: " + methodName + " queueTime= " + qTime +

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RPC.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.apache.hadoop.security.token.TokenIdentifier;
5151
import org.apache.hadoop.conf.*;
5252
import org.apache.hadoop.util.ReflectionUtils;
53+
import org.apache.hadoop.util.Time;
5354

5455
import com.google.protobuf.BlockingService;
5556

@@ -369,7 +370,7 @@ public static <T> ProtocolProxy<T> waitForProtocolProxy(Class<T> protocol,
369370
int rpcTimeout,
370371
RetryPolicy connectionRetryPolicy,
371372
long timeout) throws IOException {
372-
long startTime = System.currentTimeMillis();
373+
long startTime = Time.now();
373374
IOException ioe;
374375
while (true) {
375376
try {
@@ -387,7 +388,7 @@ public static <T> ProtocolProxy<T> waitForProtocolProxy(Class<T> protocol,
387388
ioe = nrthe;
388389
}
389390
// check if timed out
390-
if (System.currentTimeMillis()-timeout >= startTime) {
391+
if (Time.now()-timeout >= startTime) {
391392
throw ioe;
392393
}
393394

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
import org.apache.hadoop.util.ProtoUtil;
9696
import org.apache.hadoop.util.ReflectionUtils;
9797
import org.apache.hadoop.util.StringUtils;
98+
import org.apache.hadoop.util.Time;
9899

99100
import com.google.common.annotations.VisibleForTesting;
100101

@@ -411,7 +412,7 @@ public Call(int id, Writable param, Connection connection, RPC.RpcKind kind) {
411412
this.callId = id;
412413
this.rpcRequest = param;
413414
this.connection = connection;
414-
this.timestamp = System.currentTimeMillis();
415+
this.timestamp = Time.now();
415416
this.rpcResponse = null;
416417
this.rpcKind = kind;
417418
}
@@ -561,7 +562,7 @@ void shutdown() {
561562
*/
562563
private void cleanupConnections(boolean force) {
563564
if (force || numConnections > thresholdIdleConnections) {
564-
long currentTime = System.currentTimeMillis();
565+
long currentTime = Time.now();
565566
if (!force && (currentTime - lastCleanupRunTime) < cleanupInterval) {
566567
return;
567568
}
@@ -597,7 +598,7 @@ private void cleanupConnections(boolean force) {
597598
}
598599
else i++;
599600
}
600-
lastCleanupRunTime = System.currentTimeMillis();
601+
lastCleanupRunTime = Time.now();
601602
}
602603
}
603604

@@ -682,7 +683,7 @@ void doAccept(SelectionKey key) throws IOException, OutOfMemoryError {
682683
try {
683684
reader.startAdd();
684685
SelectionKey readKey = reader.registerChannel(channel);
685-
c = new Connection(readKey, channel, System.currentTimeMillis());
686+
c = new Connection(readKey, channel, Time.now());
686687
readKey.attach(c);
687688
synchronized (connectionList) {
688689
connectionList.add(numConnections, c);
@@ -704,7 +705,7 @@ void doRead(SelectionKey key) throws InterruptedException {
704705
if (c == null) {
705706
return;
706707
}
707-
c.setLastContact(System.currentTimeMillis());
708+
c.setLastContact(Time.now());
708709

709710
try {
710711
count = c.readAndProcess();
@@ -726,7 +727,7 @@ void doRead(SelectionKey key) throws InterruptedException {
726727
c = null;
727728
}
728729
else {
729-
c.setLastContact(System.currentTimeMillis());
730+
c.setLastContact(Time.now());
730731
}
731732
}
732733

@@ -805,7 +806,7 @@ private void doRunLoop() {
805806
LOG.info(getName() + ": doAsyncWrite threw exception " + e);
806807
}
807808
}
808-
long now = System.currentTimeMillis();
809+
long now = Time.now();
809810
if (now < lastPurgeTime + PURGE_INTERVAL) {
810811
continue;
811812
}
@@ -951,7 +952,7 @@ private boolean processResponse(LinkedList<Call> responseQueue,
951952

952953
if (inHandler) {
953954
// set the serve time when the response has to be sent later
954-
call.timestamp = System.currentTimeMillis();
955+
call.timestamp = Time.now();
955956

956957
incPending();
957958
try {

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/WritableRpcEngine.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.hadoop.security.UserGroupInformation;
3838
import org.apache.hadoop.security.token.SecretManager;
3939
import org.apache.hadoop.security.token.TokenIdentifier;
40+
import org.apache.hadoop.util.Time;
4041
import org.apache.hadoop.classification.InterfaceAudience;
4142
import org.apache.hadoop.classification.InterfaceStability;
4243
import org.apache.hadoop.conf.*;
@@ -218,13 +219,13 @@ public Object invoke(Object proxy, Method method, Object[] args)
218219
throws Throwable {
219220
long startTime = 0;
220221
if (LOG.isDebugEnabled()) {
221-
startTime = System.currentTimeMillis();
222+
startTime = Time.now();
222223
}
223224

224225
ObjectWritable value = (ObjectWritable)
225226
client.call(RPC.RpcKind.RPC_WRITABLE, new Invocation(method, args), remoteId);
226227
if (LOG.isDebugEnabled()) {
227-
long callTime = System.currentTimeMillis() - startTime;
228+
long callTime = Time.now() - startTime;
228229
LOG.debug("Call: " + method.getName() + " " + callTime);
229230
}
230231
return value.get();
@@ -464,15 +465,15 @@ public Writable call(org.apache.hadoop.ipc.RPC.Server server,
464465

465466
// Invoke the protocol method
466467

467-
long startTime = System.currentTimeMillis();
468+
long startTime = Time.now();
468469
Method method =
469470
protocolImpl.protocolClass.getMethod(call.getMethodName(),
470471
call.getParameterClasses());
471472
method.setAccessible(true);
472473
server.rpcDetailedMetrics.init(protocolImpl.protocolClass);
473474
Object value =
474475
method.invoke(protocolImpl.protocolImpl, call.getParameters());
475-
int processingTime = (int) (System.currentTimeMillis() - startTime);
476+
int processingTime = (int) (Time.now() - startTime);
476477
int qTime = (int) (startTime-receivedTime);
477478
if (LOG.isDebugEnabled()) {
478479
LOG.debug("Served: " + call.getMethodName() +

0 commit comments

Comments
 (0)