HDFS-15633. Avoid redundant RPC calls for getDiskStatus. (#2386). Contributed by Ayush Saxena.

This commit is contained in:
Ayush Saxena 2020-10-16 10:36:24 +05:30 committed by GitHub
parent 8b8c672780
commit cc57eebe45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 2 deletions

View File

@ -2000,8 +2000,17 @@ public class DFSClient implements java.io.Closeable, RemotePeerFactory,
* @see ClientProtocol#getStats()
*/
public FsStatus getDiskStatus() throws IOException {
return new FsStatus(getStateByIndex(0),
getStateByIndex(1), getStateByIndex(2));
try (TraceScope ignored = tracer.newScope("getStats")) {
long[] states = namenode.getStats();
return new FsStatus(getStateAtIndex(states, 0),
getStateAtIndex(states, 1), getStateAtIndex(states, 2));
} catch (RemoteException re) {
throw re.unwrapRemoteException();
}
}
private long getStateAtIndex(long[] states, int index) {
return states.length > index ? states[index] : -1;
}
/**