|
@@ -46,8 +46,7 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
|
|
|
-import org.apache.commons.lang3.ArrayUtils;
|
|
|
-import org.apache.hadoop.ipc.CallerContext;
|
|
|
+import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
|
|
import org.apache.hadoop.HadoopIllegalArgumentException;
|
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
@@ -271,7 +270,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
|
|
|
private final String defaultECPolicyName;
|
|
|
|
|
|
- // Users who can override the client ip
|
|
|
+ // Users who can override the client info
|
|
|
private final String[] ipProxyUsers;
|
|
|
|
|
|
public NameNodeRpcServer(Configuration conf, NameNode nn)
|
|
@@ -711,8 +710,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
if(!nn.isRole(NamenodeRole.NAMENODE))
|
|
|
throw new IOException("Only an ACTIVE node can invoke startCheckpoint.");
|
|
|
|
|
|
- CacheEntryWithPayload cacheEntry = RetryCache.waitForCompletion(retryCache,
|
|
|
- null);
|
|
|
+ CacheEntryWithPayload cacheEntry = getCacheEntryWithPayload(null);
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return (NamenodeCommand) cacheEntry.getPayload();
|
|
|
}
|
|
@@ -725,13 +723,33 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Return the current CacheEntry.
|
|
|
+ */
|
|
|
+ private CacheEntry getCacheEntry() {
|
|
|
+ Pair<byte[], Integer> clientInfo =
|
|
|
+ NameNode.getClientIdAndCallId(this.ipProxyUsers);
|
|
|
+ return RetryCache.waitForCompletion(
|
|
|
+ retryCache, clientInfo.getLeft(), clientInfo.getRight());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Return the current CacheEntryWithPayload.
|
|
|
+ */
|
|
|
+ private CacheEntryWithPayload getCacheEntryWithPayload(Object payload) {
|
|
|
+ Pair<byte[], Integer> clientInfo =
|
|
|
+ NameNode.getClientIdAndCallId(this.ipProxyUsers);
|
|
|
+ return RetryCache.waitForCompletion(retryCache, payload,
|
|
|
+ clientInfo.getLeft(), clientInfo.getRight());
|
|
|
+ }
|
|
|
+
|
|
|
@Override // NamenodeProtocol
|
|
|
public void endCheckpoint(NamenodeRegistration registration,
|
|
|
CheckpointSignature sig) throws IOException {
|
|
|
String operationName = "endCheckpoint";
|
|
|
checkNNStartup();
|
|
|
namesystem.checkSuperuserPrivilege(operationName);
|
|
|
- CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return; // Return previous response
|
|
|
}
|
|
@@ -801,7 +819,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
+ MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels.");
|
|
|
}
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- CacheEntryWithPayload cacheEntry = RetryCache.waitForCompletion(retryCache, null);
|
|
|
+ CacheEntryWithPayload cacheEntry = getCacheEntryWithPayload(null);
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return (HdfsFileStatus) cacheEntry.getPayload();
|
|
|
}
|
|
@@ -832,8 +850,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
+src+" for "+clientName+" at "+clientMachine);
|
|
|
}
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- CacheEntryWithPayload cacheEntry = RetryCache.waitForCompletion(retryCache,
|
|
|
- null);
|
|
|
+ CacheEntryWithPayload cacheEntry = getCacheEntryWithPayload(null);
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return (LastBlockWithStatus) cacheEntry.getPayload();
|
|
|
}
|
|
@@ -999,7 +1016,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
throws IOException {
|
|
|
checkNNStartup();
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return; // Return previous response
|
|
|
}
|
|
@@ -1044,7 +1061,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
+ MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels.");
|
|
|
}
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return true; // Return previous response
|
|
|
}
|
|
@@ -1067,7 +1084,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
stateChangeLog.debug("*DIR* NameNode.concat: src path {} to" +
|
|
|
" target path {}", Arrays.toString(src), trg);
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return; // Return previous response
|
|
|
}
|
|
@@ -1093,7 +1110,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
+ MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels.");
|
|
|
}
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return; // Return previous response
|
|
|
}
|
|
@@ -1130,7 +1147,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
+ ", recursive=" + recursive);
|
|
|
}
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return true; // Return previous response
|
|
|
}
|
|
@@ -1315,7 +1332,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
@Override // ClientProtocol
|
|
|
public boolean saveNamespace(long timeWindow, long txGap) throws IOException {
|
|
|
checkNNStartup();
|
|
|
- CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return true; // Return previous response
|
|
|
}
|
|
@@ -1503,7 +1520,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
public void satisfyStoragePolicy(String src) throws IOException {
|
|
|
checkNNStartup();
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return; // Return previous response
|
|
|
}
|
|
@@ -1550,7 +1567,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
boolean createParent) throws IOException {
|
|
|
checkNNStartup();
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return; // Return previous response
|
|
|
}
|
|
@@ -1920,34 +1937,11 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Get the actual client's machine.
|
|
|
+ */
|
|
|
private String getClientMachine() {
|
|
|
- if (ipProxyUsers != null) {
|
|
|
- // Get the real user (or effective if it isn't a proxy user)
|
|
|
- UserGroupInformation user =
|
|
|
- UserGroupInformation.getRealUserOrSelf(Server.getRemoteUser());
|
|
|
- if (user != null &&
|
|
|
- ArrayUtils.contains(ipProxyUsers, user.getShortUserName())) {
|
|
|
- CallerContext context = CallerContext.getCurrent();
|
|
|
- if (context != null && context.isContextValid()) {
|
|
|
- String cc = context.getContext();
|
|
|
- // if the rpc has a caller context of "clientIp:1.2.3.4,CLI",
|
|
|
- // return "1.2.3.4" as the client machine.
|
|
|
- String key = CallerContext.CLIENT_IP_STR +
|
|
|
- CallerContext.Builder.KEY_VALUE_SEPARATOR;
|
|
|
- int posn = cc.indexOf(key);
|
|
|
- if (posn != -1) {
|
|
|
- posn += key.length();
|
|
|
- int end = cc.indexOf(",", posn);
|
|
|
- return end == -1 ? cc.substring(posn) : cc.substring(posn, end);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- String clientMachine = Server.getRemoteAddress();
|
|
|
- if (clientMachine == null) { //not a RPC client
|
|
|
- clientMachine = "";
|
|
|
- }
|
|
|
- return clientMachine;
|
|
|
+ return NameNode.getClientMachine(this.ipProxyUsers);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -1967,8 +1961,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
+ MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels.");
|
|
|
}
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- CacheEntryWithPayload cacheEntry = RetryCache.waitForCompletion(retryCache,
|
|
|
- null);
|
|
|
+ CacheEntryWithPayload cacheEntry = getCacheEntryWithPayload(null);
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return (String) cacheEntry.getPayload();
|
|
|
}
|
|
@@ -1995,7 +1988,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
}
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
metrics.incrDeleteSnapshotOps();
|
|
|
- CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return; // Return previous response
|
|
|
}
|
|
@@ -2037,7 +2030,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
}
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
metrics.incrRenameSnapshotOps();
|
|
|
- CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return; // Return previous response
|
|
|
}
|
|
@@ -2098,8 +2091,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
CacheDirectiveInfo path, EnumSet<CacheFlag> flags) throws IOException {
|
|
|
checkNNStartup();
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- CacheEntryWithPayload cacheEntry = RetryCache.waitForCompletion
|
|
|
- (retryCache, null);
|
|
|
+ CacheEntryWithPayload cacheEntry = getCacheEntryWithPayload(null);
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return (Long) cacheEntry.getPayload();
|
|
|
}
|
|
@@ -2120,7 +2112,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
CacheDirectiveInfo directive, EnumSet<CacheFlag> flags) throws IOException {
|
|
|
checkNNStartup();
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return;
|
|
|
}
|
|
@@ -2138,7 +2130,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
public void removeCacheDirective(long id) throws IOException {
|
|
|
checkNNStartup();
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return;
|
|
|
}
|
|
@@ -2165,7 +2157,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
public void addCachePool(CachePoolInfo info) throws IOException {
|
|
|
checkNNStartup();
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return; // Return previous response
|
|
|
}
|
|
@@ -2182,7 +2174,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
public void modifyCachePool(CachePoolInfo info) throws IOException {
|
|
|
checkNNStartup();
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return; // Return previous response
|
|
|
}
|
|
@@ -2199,7 +2191,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
public void removeCachePool(String cachePoolName) throws IOException {
|
|
|
checkNNStartup();
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return;
|
|
|
}
|
|
@@ -2262,7 +2254,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
throws IOException {
|
|
|
checkNNStartup();
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- final CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ final CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return;
|
|
|
}
|
|
@@ -2294,7 +2286,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
final ReencryptAction action) throws IOException {
|
|
|
checkNNStartup();
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- final CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ final CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return;
|
|
|
}
|
|
@@ -2318,7 +2310,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
public void setErasureCodingPolicy(String src, String ecPolicyName)
|
|
|
throws IOException {
|
|
|
checkNNStartup();
|
|
|
- final CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ final CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return;
|
|
|
}
|
|
@@ -2342,7 +2334,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
throws IOException {
|
|
|
checkNNStartup();
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return; // Return previous response
|
|
|
}
|
|
@@ -2372,7 +2364,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
public void removeXAttr(String src, XAttr xAttr) throws IOException {
|
|
|
checkNNStartup();
|
|
|
namesystem.checkOperation(OperationCategory.WRITE);
|
|
|
- CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return; // Return previous response
|
|
|
}
|
|
@@ -2555,7 +2547,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
@Override // ClientProtocol
|
|
|
public void unsetErasureCodingPolicy(String src) throws IOException {
|
|
|
checkNNStartup();
|
|
|
- final CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ final CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return;
|
|
|
}
|
|
@@ -2581,8 +2573,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
String operationName = "addErasureCodingPolicies";
|
|
|
checkNNStartup();
|
|
|
namesystem.checkSuperuserPrivilege(operationName);
|
|
|
- final CacheEntryWithPayload cacheEntry =
|
|
|
- RetryCache.waitForCompletion(retryCache, null);
|
|
|
+ final CacheEntryWithPayload cacheEntry = getCacheEntryWithPayload(null);
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return (AddErasureCodingPolicyResponse[]) cacheEntry.getPayload();
|
|
|
}
|
|
@@ -2605,7 +2596,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
String operationName = "removeErasureCodingPolicy";
|
|
|
checkNNStartup();
|
|
|
namesystem.checkSuperuserPrivilege(operationName);
|
|
|
- final CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ final CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return;
|
|
|
}
|
|
@@ -2624,7 +2615,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
String operationName = "enableErasureCodingPolicy";
|
|
|
checkNNStartup();
|
|
|
namesystem.checkSuperuserPrivilege(operationName);
|
|
|
- final CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ final CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return;
|
|
|
}
|
|
@@ -2643,7 +2634,7 @@ public class NameNodeRpcServer implements NamenodeProtocols {
|
|
|
String operationName = "disableErasureCodingPolicy";
|
|
|
checkNNStartup();
|
|
|
namesystem.checkSuperuserPrivilege(operationName);
|
|
|
- final CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
|
|
|
+ final CacheEntry cacheEntry = getCacheEntry();
|
|
|
if (cacheEntry != null && cacheEntry.isSuccess()) {
|
|
|
return;
|
|
|
}
|