This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git
The following commit(s) were added to refs/heads/master by this push:
new 2027c15 RATIS-1451. GroupManagementImpl should use
sendRequestWithRetry. (#545)
2027c15 is described below
commit 2027c15e0533edd8057899fa0da82345447e4b20
Author: Tsz-Wo Nicholas Sze <[email protected]>
AuthorDate: Wed Dec 1 04:23:31 2021 +0800
RATIS-1451. GroupManagementImpl should use sendRequestWithRetry. (#545)
---
.../org/apache/ratis/client/impl/BlockingImpl.java | 6 ++++--
.../ratis/client/impl/GroupManagementImpl.java | 20 ++++++++++----------
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git
a/ratis-client/src/main/java/org/apache/ratis/client/impl/BlockingImpl.java
b/ratis-client/src/main/java/org/apache/ratis/client/impl/BlockingImpl.java
index 8decf96..e234714 100644
--- a/ratis-client/src/main/java/org/apache/ratis/client/impl/BlockingImpl.java
+++ b/ratis-client/src/main/java/org/apache/ratis/client/impl/BlockingImpl.java
@@ -31,6 +31,8 @@ import org.apache.ratis.protocol.Message;
import org.apache.ratis.protocol.RaftClientReply;
import org.apache.ratis.protocol.RaftClientRequest;
import org.apache.ratis.protocol.RaftPeerId;
+import org.apache.ratis.protocol.exceptions.AlreadyClosedException;
+import org.apache.ratis.protocol.exceptions.AlreadyExistsException;
import org.apache.ratis.protocol.exceptions.GroupMismatchException;
import org.apache.ratis.protocol.exceptions.LeaderSteppingDownException;
import org.apache.ratis.protocol.exceptions.StateMachineException;
@@ -99,7 +101,7 @@ class BlockingImpl implements BlockingApi {
return client.handleReply(request, reply);
}
} catch (GroupMismatchException | StateMachineException |
TransferLeadershipException |
- LeaderSteppingDownException e) {
+ LeaderSteppingDownException | AlreadyClosedException |
AlreadyExistsException e) {
throw e;
} catch (IOException e) {
ioe = e;
@@ -123,7 +125,7 @@ class BlockingImpl implements BlockingApi {
}
}
- RaftClientReply sendRequest(RaftClientRequest request) throws IOException {
+ private RaftClientReply sendRequest(RaftClientRequest request) throws
IOException {
LOG.debug("{}: send {}", client.getId(), request);
RaftClientReply reply;
try {
diff --git
a/ratis-client/src/main/java/org/apache/ratis/client/impl/GroupManagementImpl.java
b/ratis-client/src/main/java/org/apache/ratis/client/impl/GroupManagementImpl.java
index 0171bcb..27e0bbf 100644
---
a/ratis-client/src/main/java/org/apache/ratis/client/impl/GroupManagementImpl.java
+++
b/ratis-client/src/main/java/org/apache/ratis/client/impl/GroupManagementImpl.java
@@ -48,7 +48,8 @@ class GroupManagementImpl implements GroupManagementApi {
final long callId = CallId.getAndIncrement();
client.getClientRpc().addRaftPeers(newGroup.getPeers());
- return
client.io().sendRequest(GroupManagementRequest.newAdd(client.getId(), server,
callId, newGroup));
+ return client.io().sendRequestWithRetry(
+ () -> GroupManagementRequest.newAdd(client.getId(), server, callId,
newGroup));
}
@Override
@@ -57,27 +58,26 @@ class GroupManagementImpl implements GroupManagementApi {
Objects.requireNonNull(groupId, "groupId == null");
final long callId = CallId.getAndIncrement();
- return
client.io().sendRequest(GroupManagementRequest.newRemove(client.getId(), server,
- callId, groupId, deleteDirectory, renameDirectory));
+ return client.io().sendRequestWithRetry(
+ () -> GroupManagementRequest.newRemove(client.getId(), server, callId,
groupId,
+ deleteDirectory, renameDirectory));
}
@Override
public GroupListReply list() throws IOException {
final long callId = CallId.getAndIncrement();
- final RaftClientReply reply = client.io().sendRequest(
- new GroupListRequest(client.getId(), server, client.getGroupId(),
callId));
+ final RaftClientReply reply = client.io().sendRequestWithRetry(
+ () -> new GroupListRequest(client.getId(), server,
client.getGroupId(), callId));
Preconditions.assertTrue(reply instanceof GroupListReply, () ->
"Unexpected reply: " + reply);
return (GroupListReply)reply;
}
@Override
public GroupInfoReply info(RaftGroupId groupId) throws IOException {
- if (groupId == null) {
- groupId = client.getGroupId();
- }
+ final RaftGroupId gid = groupId != null? groupId: client.getGroupId();
final long callId = CallId.getAndIncrement();
- final RaftClientReply reply = client.io().sendRequest(
- new GroupInfoRequest(client.getId(), server, groupId, callId));
+ final RaftClientReply reply = client.io().sendRequestWithRetry(
+ () -> new GroupInfoRequest(client.getId(), server, gid, callId));
Preconditions.assertTrue(reply instanceof GroupInfoReply, () ->
"Unexpected reply: " + reply);
return (GroupInfoReply)reply;
}