Skip to content

Commit f89dd6b

Browse files
committed
HADOOP-10070. RPC client doesn't use per-connection conf to determine server's expected Kerberos principal name. Contributed by Aaron T. Myers.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1570776 13f79535-47bb-0310-9956-ffa450edef68
1 parent 453fb0b commit f89dd6b

File tree

4 files changed

+43
-21
lines changed

4 files changed

+43
-21
lines changed

hadoop-common-project/hadoop-common/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,9 @@ Release 2.4.0 - UNRELEASED
406406

407407
HADOOP-10355. Fix TestLoadGenerator#testLoadGenerator. (Haohui Mai via jing9)
408408

409+
HADOOP-10070. RPC client doesn't use per-connection conf to determine
410+
server's expected Kerberos principal name. (atm)
411+
409412
Release 2.3.1 - UNRELEASED
410413

411414
INCOMPATIBLE CHANGES

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,11 @@ private synchronized boolean shouldAuthenticateOverKrb() throws IOException {
542542

543543
private synchronized AuthMethod setupSaslConnection(final InputStream in2,
544544
final OutputStream out2) throws IOException, InterruptedException {
545+
// Do not use Client.conf here! We must use ConnectionId.conf, since the
546+
// Client object is cached and shared between all RPC clients, even those
547+
// for separate services.
545548
saslRpcClient = new SaslRpcClient(remoteId.getTicket(),
546-
remoteId.getProtocol(), remoteId.getAddress(), conf);
549+
remoteId.getProtocol(), remoteId.getAddress(), remoteId.conf);
547550
return saslRpcClient.saslConnect(in2, out2);
548551
}
549552

@@ -1480,21 +1483,31 @@ public static class ConnectionId {
14801483
private final boolean doPing; //do we need to send ping message
14811484
private final int pingInterval; // how often sends ping to the server in msecs
14821485
private String saslQop; // here for testing
1486+
private final Configuration conf; // used to get the expected kerberos principal name
14831487

14841488
ConnectionId(InetSocketAddress address, Class<?> protocol,
1485-
UserGroupInformation ticket, int rpcTimeout, int maxIdleTime,
1486-
RetryPolicy connectionRetryPolicy, int maxRetriesOnSocketTimeouts,
1487-
boolean tcpNoDelay, boolean doPing, int pingInterval) {
1489+
UserGroupInformation ticket, int rpcTimeout,
1490+
RetryPolicy connectionRetryPolicy, Configuration conf) {
14881491
this.protocol = protocol;
14891492
this.address = address;
14901493
this.ticket = ticket;
14911494
this.rpcTimeout = rpcTimeout;
1492-
this.maxIdleTime = maxIdleTime;
14931495
this.connectionRetryPolicy = connectionRetryPolicy;
1494-
this.maxRetriesOnSocketTimeouts = maxRetriesOnSocketTimeouts;
1495-
this.tcpNoDelay = tcpNoDelay;
1496-
this.doPing = doPing;
1497-
this.pingInterval = pingInterval;
1496+
1497+
this.maxIdleTime = conf.getInt(
1498+
CommonConfigurationKeysPublic.IPC_CLIENT_CONNECTION_MAXIDLETIME_KEY,
1499+
CommonConfigurationKeysPublic.IPC_CLIENT_CONNECTION_MAXIDLETIME_DEFAULT);
1500+
this.maxRetriesOnSocketTimeouts = conf.getInt(
1501+
CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_ON_SOCKET_TIMEOUTS_KEY,
1502+
CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_ON_SOCKET_TIMEOUTS_DEFAULT);
1503+
this.tcpNoDelay = conf.getBoolean(
1504+
CommonConfigurationKeysPublic.IPC_CLIENT_TCPNODELAY_KEY,
1505+
CommonConfigurationKeysPublic.IPC_CLIENT_TCPNODELAY_DEFAULT);
1506+
this.doPing = conf.getBoolean(
1507+
CommonConfigurationKeys.IPC_CLIENT_PING_KEY,
1508+
CommonConfigurationKeys.IPC_CLIENT_PING_DEFAULT);
1509+
this.pingInterval = (doPing ? Client.getPingInterval(conf) : 0);
1510+
this.conf = conf;
14981511
}
14991512

15001513
InetSocketAddress getAddress() {
@@ -1572,19 +1585,8 @@ static ConnectionId getConnectionId(InetSocketAddress addr,
15721585
max, retryInterval, TimeUnit.MILLISECONDS);
15731586
}
15741587

1575-
boolean doPing =
1576-
conf.getBoolean(CommonConfigurationKeys.IPC_CLIENT_PING_KEY, true);
15771588
return new ConnectionId(addr, protocol, ticket, rpcTimeout,
1578-
conf.getInt(CommonConfigurationKeysPublic.IPC_CLIENT_CONNECTION_MAXIDLETIME_KEY,
1579-
CommonConfigurationKeysPublic.IPC_CLIENT_CONNECTION_MAXIDLETIME_DEFAULT),
1580-
connectionRetryPolicy,
1581-
conf.getInt(
1582-
CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_ON_SOCKET_TIMEOUTS_KEY,
1583-
CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_ON_SOCKET_TIMEOUTS_DEFAULT),
1584-
conf.getBoolean(CommonConfigurationKeysPublic.IPC_CLIENT_TCPNODELAY_KEY,
1585-
CommonConfigurationKeysPublic.IPC_CLIENT_TCPNODELAY_DEFAULT),
1586-
doPing,
1587-
(doPing ? Client.getPingInterval(conf) : 0));
1589+
connectionRetryPolicy, conf);
15881590
}
15891591

15901592
static boolean isEqual(Object a, Object b) {

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ClientCache.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public synchronized Client getClient(Configuration conf,
5959
} else {
6060
client.incCount();
6161
}
62+
if (Client.LOG.isDebugEnabled()) {
63+
Client.LOG.debug("getting client out of cache: " + client);
64+
}
6265
return client;
6366
}
6467

@@ -90,13 +93,23 @@ public synchronized Client getClient(Configuration conf, SocketFactory factory)
9093
* A RPC client is closed only when its reference count becomes zero.
9194
*/
9295
public void stopClient(Client client) {
96+
if (Client.LOG.isDebugEnabled()) {
97+
Client.LOG.debug("stopping client from cache: " + client);
98+
}
9399
synchronized (this) {
94100
client.decCount();
95101
if (client.isZeroReference()) {
102+
if (Client.LOG.isDebugEnabled()) {
103+
Client.LOG.debug("removing client from cache: " + client);
104+
}
96105
clients.remove(client.getSocketFactory());
97106
}
98107
}
99108
if (client.isZeroReference()) {
109+
if (Client.LOG.isDebugEnabled()) {
110+
Client.LOG.debug("stopping actual client because no more references remain: "
111+
+ client);
112+
}
100113
client.stop();
101114
}
102115
}

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/SaslRpcClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ String getServerPrincipal(SaslAuth authType) throws IOException {
309309
// check that the server advertised principal matches our conf
310310
String confPrincipal = SecurityUtil.getServerPrincipal(
311311
conf.get(serverKey), serverAddr.getAddress());
312+
if (LOG.isDebugEnabled()) {
313+
LOG.debug("getting serverKey: " + serverKey + " conf value: " + conf.get(serverKey)
314+
+ " principal: " + confPrincipal);
315+
}
312316
if (confPrincipal == null || confPrincipal.isEmpty()) {
313317
throw new IllegalArgumentException(
314318
"Failed to specify server's Kerberos principal name");

0 commit comments

Comments
 (0)