From 8769e6feda34713e130a88cabd145a1c74e71591 Mon Sep 17 00:00:00 2001 From: Chen Liang Date: Mon, 3 Dec 2018 17:05:07 -0800 Subject: [PATCH] HDFS-14120. [SBN read] ORFPP should also clone DT for the virtual IP. Contributed by Chen Liang. --- ...serverReadProxyProviderWithIPFailover.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/ObserverReadProxyProviderWithIPFailover.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/ObserverReadProxyProviderWithIPFailover.java index 751bc3b5c3a..22f6dd36381 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/ObserverReadProxyProviderWithIPFailover.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/ObserverReadProxyProviderWithIPFailover.java @@ -17,9 +17,12 @@ */ package org.apache.hadoop.hdfs.server.namenode.ha; +import java.net.InetSocketAddress; import java.net.URI; +import java.util.Collections; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hdfs.HAUtilClient; import org.apache.hadoop.hdfs.protocol.ClientProtocol; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,7 +61,8 @@ import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.DFS_CLIENT_FAIL * dfs.ha.namenodes.mycluster = ha1,ha2 * dfs.namenode.rpc-address.mycluster.ha1 = nn01-ha1.com:8020 * dfs.namenode.rpc-address.mycluster.ha2 = nn01-ha2.com:8020 - * dfs.client.failover.ipfailover.virtual-address.mycluster = nn01.com:8020 + * dfs.client.failover.ipfailover.virtual-address.mycluster = + * hdfs://nn01.com:8020 * dfs.client.failover.proxy.provider.mycluster = * org.apache...ObserverReadProxyProviderWithIPFailover * } @@ -97,6 +101,24 @@ public class ObserverReadProxyProviderWithIPFailover Configuration conf, URI uri, Class xface, HAProxyFactory factory, AbstractNNFailoverProxyProvider failoverProxy) { super(conf, uri, xface, factory, failoverProxy); + cloneDelegationTokenForVirtualIP(conf, uri); + } + + /** + * Clone delegation token for the virtual IP. Specifically + * clone the dt that corresponds to the name service uri, + * to the configured corresponding virtual IP. + * + * @param conf configuration + * @param haURI the ha uri, a name service id in this case. + */ + private void cloneDelegationTokenForVirtualIP( + Configuration conf, URI haURI) { + URI virtualIPURI = getFailoverVirtualIP(conf, haURI.getHost()); + InetSocketAddress vipAddress = new InetSocketAddress( + virtualIPURI.getHost(), virtualIPURI.getPort()); + HAUtilClient.cloneDelegationTokenForLogicalUri( + ugi, haURI, Collections.singleton(vipAddress)); } private static URI getFailoverVirtualIP(