Skip to content

Commit fd30f4c

Browse files
committed
HDFS-15096. RBF: GetServerDefaults Should be Cached At Router. Contributed by Ayush Saxena.
1 parent b1e07d2 commit fd30f4c

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterClientProtocol.java

+24-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.apache.hadoop.hdfs.server.federation.router;
1919

20+
import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.DFS_CLIENT_SERVER_DEFAULTS_VALIDITY_PERIOD_MS_DEFAULT;
21+
import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.DFS_CLIENT_SERVER_DEFAULTS_VALIDITY_PERIOD_MS_KEY;
2022
import static org.apache.hadoop.hdfs.server.federation.router.FederationUtil.updateMountPointStatus;
2123
import org.apache.hadoop.conf.Configuration;
2224
import org.apache.hadoop.crypto.CryptoProtocolVersion;
@@ -88,6 +90,7 @@
8890
import org.apache.hadoop.net.ConnectTimeoutException;
8991
import org.apache.hadoop.security.UserGroupInformation;
9092
import org.apache.hadoop.security.token.Token;
93+
import org.apache.hadoop.util.Time;
9194
import org.slf4j.Logger;
9295
import org.slf4j.LoggerFactory;
9396

@@ -122,6 +125,15 @@ public class RouterClientProtocol implements ClientProtocol {
122125
private final FileSubclusterResolver subclusterResolver;
123126
private final ActiveNamenodeResolver namenodeResolver;
124127

128+
/**
129+
* Caching server defaults so as to prevent redundant calls to namenode,
130+
* similar to DFSClient, caching saves efforts when router connects
131+
* to multiple clients.
132+
*/
133+
private volatile FsServerDefaults serverDefaults;
134+
private volatile long serverDefaultsLastUpdate;
135+
private final long serverDefaultsValidityPeriod;
136+
125137
/** If it requires response from all subclusters. */
126138
private final boolean allowPartialList;
127139
/** Time out when getting the mount statistics. */
@@ -155,7 +167,9 @@ public class RouterClientProtocol implements ClientProtocol {
155167
RBFConfigKeys.DFS_ROUTER_CLIENT_MOUNT_TIME_OUT,
156168
RBFConfigKeys.DFS_ROUTER_CLIENT_MOUNT_TIME_OUT_DEFAULT,
157169
TimeUnit.MILLISECONDS);
158-
170+
this.serverDefaultsValidityPeriod = conf.getLong(
171+
DFS_CLIENT_SERVER_DEFAULTS_VALIDITY_PERIOD_MS_KEY,
172+
DFS_CLIENT_SERVER_DEFAULTS_VALIDITY_PERIOD_MS_DEFAULT);
159173
// User and group for reporting
160174
try {
161175
this.superUser = UserGroupInformation.getCurrentUser().getShortUserName();
@@ -226,9 +240,15 @@ public LocatedBlocks getBlockLocations(String src, final long offset,
226240
@Override
227241
public FsServerDefaults getServerDefaults() throws IOException {
228242
rpcServer.checkOperation(NameNode.OperationCategory.READ);
229-
230-
RemoteMethod method = new RemoteMethod("getServerDefaults");
231-
return rpcServer.invokeAtAvailableNs(method, FsServerDefaults.class);
243+
long now = Time.monotonicNow();
244+
if ((serverDefaults == null) || (now - serverDefaultsLastUpdate
245+
> serverDefaultsValidityPeriod)) {
246+
RemoteMethod method = new RemoteMethod("getServerDefaults");
247+
serverDefaults =
248+
rpcServer.invokeAtAvailableNs(method, FsServerDefaults.class);
249+
serverDefaultsLastUpdate = now;
250+
}
251+
return serverDefaults;
232252
}
233253

234254
@Override

0 commit comments

Comments
 (0)