Skip to content

Commit 6eacaff

Browse files
hchaverrishvachko
authored andcommitted
HDFS-15623. Respect configured values of rpc.engine (#2403) Contributed by Hector Chaverri.
1 parent 4b31281 commit 6eacaff

File tree

2 files changed

+18
-2
lines changed
  • hadoop-common-project/hadoop-common/src

2 files changed

+18
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,18 @@ private RPC() {} // no public ctor
195195
private static final String ENGINE_PROP = "rpc.engine";
196196

197197
/**
198-
* Set a protocol to use a non-default RpcEngine.
198+
* Set a protocol to use a non-default RpcEngine if one
199+
* is not specified in the configuration.
199200
* @param conf configuration to use
200201
* @param protocol the protocol interface
201202
* @param engine the RpcEngine impl
202203
*/
203204
public static void setProtocolEngine(Configuration conf,
204205
Class<?> protocol, Class<?> engine) {
205-
conf.setClass(ENGINE_PROP+"."+protocol.getName(), engine, RpcEngine.class);
206+
if (conf.get(ENGINE_PROP+"."+protocol.getName()) == null) {
207+
conf.setClass(ENGINE_PROP+"."+protocol.getName(), engine,
208+
RpcEngine.class);
209+
}
206210
}
207211

208212
// return the RpcEngine configured to handle a protocol

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,18 @@ public RpcStatusProto getRpcStatusProto() {
15541554
}
15551555
}
15561556

1557+
@Test
1558+
public void testSetProtocolEngine() {
1559+
Configuration conf = new Configuration();
1560+
RPC.setProtocolEngine(conf, StoppedProtocol.class, StoppedRpcEngine.class);
1561+
RpcEngine rpcEngine = RPC.getProtocolEngine(StoppedProtocol.class, conf);
1562+
assertTrue(rpcEngine instanceof StoppedRpcEngine);
1563+
1564+
RPC.setProtocolEngine(conf, StoppedProtocol.class, ProtobufRpcEngine.class);
1565+
rpcEngine = RPC.getProtocolEngine(StoppedProtocol.class, conf);
1566+
assertTrue(rpcEngine instanceof StoppedRpcEngine);
1567+
}
1568+
15571569
public static void main(String[] args) throws Exception {
15581570
new TestRPC().testCallsInternal(conf);
15591571
}

0 commit comments

Comments
 (0)