|
17 | 17 | */
|
18 | 18 | package org.apache.hadoop.hdfs.server.federation.router;
|
19 | 19 |
|
| 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; |
20 | 22 | import static org.apache.hadoop.hdfs.server.federation.router.FederationUtil.updateMountPointStatus;
|
21 | 23 | import org.apache.hadoop.conf.Configuration;
|
22 | 24 | import org.apache.hadoop.crypto.CryptoProtocolVersion;
|
|
88 | 90 | import org.apache.hadoop.net.ConnectTimeoutException;
|
89 | 91 | import org.apache.hadoop.security.UserGroupInformation;
|
90 | 92 | import org.apache.hadoop.security.token.Token;
|
| 93 | +import org.apache.hadoop.util.Time; |
91 | 94 | import org.slf4j.Logger;
|
92 | 95 | import org.slf4j.LoggerFactory;
|
93 | 96 |
|
@@ -122,6 +125,15 @@ public class RouterClientProtocol implements ClientProtocol {
|
122 | 125 | private final FileSubclusterResolver subclusterResolver;
|
123 | 126 | private final ActiveNamenodeResolver namenodeResolver;
|
124 | 127 |
|
| 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 | + |
125 | 137 | /** If it requires response from all subclusters. */
|
126 | 138 | private final boolean allowPartialList;
|
127 | 139 | /** Time out when getting the mount statistics. */
|
@@ -155,7 +167,9 @@ public class RouterClientProtocol implements ClientProtocol {
|
155 | 167 | RBFConfigKeys.DFS_ROUTER_CLIENT_MOUNT_TIME_OUT,
|
156 | 168 | RBFConfigKeys.DFS_ROUTER_CLIENT_MOUNT_TIME_OUT_DEFAULT,
|
157 | 169 | 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); |
159 | 173 | // User and group for reporting
|
160 | 174 | try {
|
161 | 175 | this.superUser = UserGroupInformation.getCurrentUser().getShortUserName();
|
@@ -226,9 +240,15 @@ public LocatedBlocks getBlockLocations(String src, final long offset,
|
226 | 240 | @Override
|
227 | 241 | public FsServerDefaults getServerDefaults() throws IOException {
|
228 | 242 | 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; |
232 | 252 | }
|
233 | 253 |
|
234 | 254 | @Override
|
|
0 commit comments