[ 
https://issues.apache.org/jira/browse/HBASE-14771?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14998683#comment-14998683
 ] 

Abhishek Kumar commented on HBASE-14771:
----------------------------------------

thanks Appy for review, i m planning to write something like below which 
returns remoteAddress from 'echo' method back to client, pls let me know if it 
seems okay for test:
{noformat}
// in static nested class TestRpcServer1
TestRpcServer1(RpcScheduler scheduler) throws IOException {
      super(null, "testRemoteAddressInCallObject", Lists
          .newArrayList(new 
BlockingServiceAndInterface(TestRpcServiceProtos.TestProtobufRpcProto
              .newReflectiveBlockingService(SERVICE1), null)),
          new InetSocketAddress("localhost", 0), CONF, scheduler);
    }

// echo message return remoteAddress 
@Override
   public EchoResponseProto echo(RpcController unused, EchoRequestProto request)
        throws ServiceException {
      final InetAddress remoteAddr = TestRpcServer1.getRemoteAddress();
      final String message = remoteAddr == null ? "NULL" : 
remoteAddr.getHostAddress();
      return EchoResponseProto.newBuilder().setMessage(message).build();
     }

// in test method
 @Test
  public void testRpcServerForNotNullRemoteAddressInCallObject() throws 
IOException,
      ServiceException {
    final RpcScheduler scheduler = new FifoRpcScheduler(CONF, 1);
    final TestRpcServer1 rpcServer = new TestRpcServer1(scheduler);
    final InetSocketAddress localAddr = new InetSocketAddress("localhost", 0);
    final AbstractRpcClient client =
        new RpcClientImpl(CONF, HConstants.CLUSTER_ID_DEFAULT, localAddr, null);
    try {
      rpcServer.start();
      final InetSocketAddress isa = rpcServer.getListenerAddress();
      if (isa == null) {
        throw new IOException("Listener channel is closed");
      }
      final BlockingRpcChannel channel =
          client.createBlockingRpcChannel(
            ServerName.valueOf(isa.getHostName(), isa.getPort(), 
System.currentTimeMillis()),
            User.getCurrent(), 0);
      TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface stub =
          TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(channel);
      final EchoRequestProto echoRequest =
          EchoRequestProto.newBuilder().setMessage("GetRemoteAddress").build();
      final EchoResponseProto echoResponse = stub.echo(null, echoRequest);
      Assert.assertEquals(localAddr.getAddress().getHostAddress(), 
echoResponse.getMessage());
    } finally {
      client.close();
      rpcServer.stop();
    }
  }

{noformat}

> RpcServer.getRemoteAddress always returns null.
> -----------------------------------------------
>
>                 Key: HBASE-14771
>                 URL: https://issues.apache.org/jira/browse/HBASE-14771
>             Project: HBase
>          Issue Type: Bug
>          Components: IPC/RPC
>    Affects Versions: 1.2.0
>            Reporter: Abhishek Kumar
>            Assignee: Abhishek Kumar
>            Priority: Minor
>         Attachments: HBASE-14771-V1.patch, HBASE-14771.patch
>
>
> RpcServer.getRemoteAddress always returns null, because Call object is 
> getting initialized with null.This seems to be happening because of using 
> RpcServer.getRemoteIp() in  Call object constructor before RpcServer thread 
> local 'CurCall' being set in CallRunner.run method:
> {noformat}
> // --- RpcServer.java ---
> protected void processRequest(byte[] buf) throws IOException, 
> InterruptedException {
>  .................................
> // Call object getting initialized here with address 
> // obtained from RpcServer.getRemoteIp()
> Call call = new Call(id, this.service, md, header, param, cellScanner, this, 
> responder,
>               totalRequestSize, traceInfo, RpcServer.getRemoteIp());
>   scheduler.dispatch(new CallRunner(RpcServer.this, call));
>  }
> // getRemoteIp method gets address from threadlocal 'CurCall' which 
> // gets set in CallRunner.run and calling it before this as in above case, 
> will return null
> // --- CallRunner.java ---
> public void run() {
>   .........................   
>   Pair<Message, CellScanner> resultPair = null;
>   RpcServer.CurCall.set(call);
>   ..............................
> }
> // Using 'this.addr' in place of getRemoteIp method in RpcServer.java seems 
> to be fixing this issue
> Call call = new Call(id, this.service, md, header, param, cellScanner, this, 
> responder,
>               totalRequestSize, traceInfo, this.addr);
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to