|
17 | 17 | */ |
18 | 18 | package org.apache.hadoop.ozone.client; |
19 | 19 |
|
| 20 | +import java.util.ArrayList; |
| 21 | +import java.util.HashMap; |
| 22 | +import java.util.List; |
| 23 | +import java.util.Map; |
| 24 | +import java.util.concurrent.TimeUnit; |
| 25 | +import java.util.concurrent.TimeoutException; |
| 26 | + |
20 | 27 | import org.apache.hadoop.hdds.client.OzoneQuota; |
21 | 28 | import org.apache.hadoop.hdds.scm.client.HddsClientUtils; |
22 | 29 | import org.apache.hadoop.hdds.scm.container.common.helpers.ContainerNotOpenException; |
23 | 30 | import org.apache.hadoop.io.retry.RetryPolicies; |
24 | 31 | import org.apache.hadoop.io.retry.RetryPolicy; |
25 | 32 | import org.apache.hadoop.ozone.OzoneConsts; |
26 | | -import org.apache.hadoop.ozone.client.rest.response.*; |
| 33 | +import org.apache.hadoop.ozone.client.rest.response.BucketInfo; |
| 34 | +import org.apache.hadoop.ozone.client.rest.response.KeyInfo; |
| 35 | +import org.apache.hadoop.ozone.client.rest.response.KeyInfoDetails; |
| 36 | +import org.apache.hadoop.ozone.client.rest.response.KeyLocation; |
| 37 | +import org.apache.hadoop.ozone.client.rest.response.VolumeInfo; |
| 38 | +import org.apache.hadoop.ozone.client.rest.response.VolumeOwner; |
27 | 39 | import org.apache.ratis.protocol.AlreadyClosedException; |
28 | 40 | import org.apache.ratis.protocol.GroupMismatchException; |
29 | 41 | import org.apache.ratis.protocol.RaftRetryFailureException; |
30 | 42 |
|
31 | | -import java.util.ArrayList; |
32 | | -import java.util.List; |
33 | | -import java.util.concurrent.TimeUnit; |
34 | | -import java.util.concurrent.TimeoutException; |
35 | | - |
36 | 43 | /** A utility class for OzoneClient. */ |
37 | 44 | public final class OzoneClientUtils { |
38 | 45 |
|
@@ -129,14 +136,31 @@ public static KeyInfoDetails asKeyInfoDetails(OzoneKeyDetails key) { |
129 | 136 |
|
130 | 137 | public static RetryPolicy createRetryPolicy(int maxRetryCount, |
131 | 138 | long retryInterval) { |
132 | | - // just retry without sleep |
133 | | - RetryPolicy retryPolicy = RetryPolicies |
134 | | - .retryUpToMaximumCountWithFixedSleep(maxRetryCount, retryInterval, |
135 | | - TimeUnit.MILLISECONDS); |
136 | | - return retryPolicy; |
| 139 | + // retry with fixed sleep between retries |
| 140 | + return RetryPolicies.retryUpToMaximumCountWithFixedSleep( |
| 141 | + maxRetryCount, retryInterval, TimeUnit.MILLISECONDS); |
137 | 142 | } |
138 | 143 |
|
139 | 144 | public static List<Class<? extends Exception>> getExceptionList() { |
140 | 145 | return EXCEPTION_LIST; |
141 | 146 | } |
| 147 | + |
| 148 | + public static Map<Class<? extends Throwable>, RetryPolicy> |
| 149 | + getRetryPolicyByException(int maxRetryCount, long retryInterval) { |
| 150 | + Map<Class<? extends Throwable>, RetryPolicy> policyMap = new HashMap<>(); |
| 151 | + for (Class<? extends Exception> ex : EXCEPTION_LIST) { |
| 152 | + if (ex == TimeoutException.class || |
| 153 | + ex == RaftRetryFailureException.class) { |
| 154 | + // retry without sleep |
| 155 | + policyMap.put(ex, createRetryPolicy(maxRetryCount, 0)); |
| 156 | + } else { |
| 157 | + // retry with fixed sleep between retries |
| 158 | + policyMap.put(ex, createRetryPolicy(maxRetryCount, retryInterval)); |
| 159 | + } |
| 160 | + } |
| 161 | + // Default retry policy |
| 162 | + policyMap.put(Exception.class, createRetryPolicy( |
| 163 | + maxRetryCount, retryInterval)); |
| 164 | + return policyMap; |
| 165 | + } |
142 | 166 | } |
0 commit comments