From 6cb5febe9636f47684ca02bb0a226b623af490ca Mon Sep 17 00:00:00 2001 From: block Date: Tue, 3 Sep 2019 19:48:12 +0800 Subject: [PATCH] (feat) add log (#261) --- .../rpc/impl/core/NodeRequestProcessor.java | 17 ++++++++++------- .../rpc/impl/core/NodeRequestProcessorTest.java | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/jraft-core/src/main/java/com/alipay/sofa/jraft/rpc/impl/core/NodeRequestProcessor.java b/jraft-core/src/main/java/com/alipay/sofa/jraft/rpc/impl/core/NodeRequestProcessor.java index 8dd3a32bf..13432fe73 100644 --- a/jraft-core/src/main/java/com/alipay/sofa/jraft/rpc/impl/core/NodeRequestProcessor.java +++ b/jraft-core/src/main/java/com/alipay/sofa/jraft/rpc/impl/core/NodeRequestProcessor.java @@ -42,22 +42,25 @@ public NodeRequestProcessor(Executor executor) { super(executor); } - protected abstract Message processRequest0(RaftServerService serviceService, T request, RpcRequestClosure done); + protected abstract Message processRequest0(final RaftServerService serviceService, final T request, + final RpcRequestClosure done); - protected abstract String getPeerId(T request); + protected abstract String getPeerId(final T request); - protected abstract String getGroupId(T request); + protected abstract String getGroupId(final T request); @Override public Message processRequest(T request, RpcRequestClosure done) { - PeerId peer = new PeerId(); - String peerIdStr = getPeerId(request); + final PeerId peer = new PeerId(); + final String peerIdStr = getPeerId(request); if (peer.parse(peerIdStr)) { - Node node = NodeManager.getInstance().get(getGroupId(request), peer); + final String groupId = getGroupId(request); + final Node node = NodeManager.getInstance().get(groupId, peer); if (node != null) { return processRequest0((RaftServerService) node, request, done); } else { - return RpcResponseFactory.newResponse(RaftError.ENOENT, "Peer id not found: %s", peerIdStr); + return RpcResponseFactory.newResponse(RaftError.ENOENT, "Peer id not found: %s, group: %s", peerIdStr, + groupId); } } else { return RpcResponseFactory.newResponse(RaftError.EINVAL, "Fail to parse peerId: %s", peerIdStr); diff --git a/jraft-core/src/test/java/com/alipay/sofa/jraft/rpc/impl/core/NodeRequestProcessorTest.java b/jraft-core/src/test/java/com/alipay/sofa/jraft/rpc/impl/core/NodeRequestProcessorTest.java index 4f7055926..b1565cb12 100644 --- a/jraft-core/src/test/java/com/alipay/sofa/jraft/rpc/impl/core/NodeRequestProcessorTest.java +++ b/jraft-core/src/test/java/com/alipay/sofa/jraft/rpc/impl/core/NodeRequestProcessorTest.java @@ -120,6 +120,6 @@ public void testPeerIdNotFound() { ErrorResponse resp = (ErrorResponse) asyncContext.getResponseObject(); assertNotNull(resp); assertEquals(RaftError.ENOENT.getNumber(), resp.getErrorCode()); - assertEquals("Peer id not found: localhost:8081", resp.getErrorMsg()); + assertEquals("Peer id not found: localhost:8081, group: test", resp.getErrorMsg()); } }