[ https://issues.apache.org/jira/browse/RATIS-835?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17082511#comment-17082511 ]
Tsz-wo Sze edited comment on RATIS-835 at 4/13/20, 5:35 PM: ------------------------------------------------------------ Thanks [~ljain]. - In RaftClientImpl.PendingClientRequest, let's rename exceptionAttemptCount to exceptionCounts and the corresponding methods. Also it should use Class<?>, i.e. {code} private final Map<Class<?>, Integer> exceptionCounts = new ConcurrentHashMap<>(); {code} - In ClientRetryEvent, the exceptionAttemptCount is counting the number of occurrences of the cause. So, let's rename it to causeCount and the corresponding methods. -* Let's also change the order of the parameter in ClientRetryEvent(..) to {code} public ClientRetryEvent(int attemptCount, RaftClientRequest request, int causeCount, Throwable cause) { {code} so that it is more clear that the attemptCount is counting the request and the causeCount is counting the cause. - PendingClientRequest.incrementExceptionCount (after rename) should return the new value, i.e. {code} int incrementExceptionCount(Throwable t) { return exceptionCounts.compute(t.getClass(), (k, v) -> v != null ? v + 1 : 1); } {code} Then the code can be simplified as below: -# OrderedAsync {code} final int exceptionCount = pending.incrementExceptionCount(e); final ClientRetryEvent event = new ClientRetryEvent(attemptCount, request, exceptionCount, e); {code} -# RaftClientImpl {code} final int exceptionCount = ioe != null? pending.incrementExceptionCount(ioe): 0; final ClientRetryEvent event = new ClientRetryEvent(attemptCount, request, exceptionCount, ioe); {code} -# UnorderedAsync {code} final Throwable cause = replyException != null ? replyException : e; final int causeCount = pending.incrementExceptionCount(cause); final ClientRetryEvent event = new ClientRetryEvent(attemptCount, request, causeCount, cause) {code} getExceptionCount should check null. {code} int getExceptionCount(Throwable t) { return Optional.ofNullable(exceptionCounts.get(t.getClass())).orElse(0); } {code} was (Author: szetszwo): Thanks [~ljain]. - In RaftClientImpl.PendingClientRequest, let rename exceptionAttemptCount to exceptionCounts and the corresponding methods. Also it should use <Class<?>, i.e. {code} private final Map<Class<?>, Integer> exceptionCounts = new ConcurrentHashMap<>(); {code} - In ClientRetryEvent, the exceptionAttemptCount is counting the number of occurance of the cause. So, let's rename it to causeCount and the corresponding methods. -* Let's also change the order of the parameter in ClientRetryEvent(..) to {code} public ClientRetryEvent(int attemptCount, RaftClientRequest request, int causeCount, Throwable cause) { {code} so that it is more clear that the attemptCount is counting the request and the causeCount is counting the cause. - PendingClientRequest.incrementExceptionCount (after rename) should return the new value, i.e. {code} int incrementExceptionCount(Throwable t) { return exceptionCounts.compute(t.getClass(), (k, v) -> v != null ? v + 1 : 1); } {code} Then the code can be simplified as below: -# OrderedAsync {code} final int exceptionCount = pending.incrementExceptionCount(e); final ClientRetryEvent event = new ClientRetryEvent(attemptCount, request, exceptionCount, e); {code} -# RaftClientImpl {code} final int exceptionCount = ioe != null? pending.incrementExceptionCount(ioe): 0; final ClientRetryEvent event = new ClientRetryEvent(attemptCount, request, exceptionCount, ioe); {code} -# UnorderedAsync {code} final Throwable cause = replyException != null ? replyException : e; final int causeCount = pending.incrementExceptionCount(cause); final ClientRetryEvent event = new ClientRetryEvent(attemptCount, request, causeCount, cause) {code} getExceptionCount should check null. {code} int getExceptionCount(Throwable t) { return Optional.ofNullable(exceptionCounts.get(t.getClass())).orElse(0); } {code} > Include exception based attempt count in raft client request > ------------------------------------------------------------ > > Key: RATIS-835 > URL: https://issues.apache.org/jira/browse/RATIS-835 > Project: Ratis > Issue Type: Bug > Components: client > Reporter: Lokesh Jain > Assignee: Lokesh Jain > Priority: Major > Attachments: RATIS-835.001.patch, RATIS-835.002.patch, > RATIS-835.003.patch > > > Client needs to maintain exception based attempt count for using Exception > Dependent retry policy. Exception dependent policy helps in specifying > individual policies for different exception types. > Currently policy takes number of attempts as argument. Therefore the > individual policies require attempt counts for the particular exception while > handling retry event. This is particularly important for using > MulipleLinearRandomRetry policy which increases sleep interval based on > number of attempts made by the client. Raft Client can therefore use this > policy for ResourceUnavailableException and increase sleep interval for > subsequent retries of the request on the same exception. -- This message was sent by Atlassian Jira (v8.3.4#803005)