|
71 | 71 | import org.apache.paimon.utils.IOUtils; |
72 | 72 | import org.apache.paimon.utils.InternalRowPartitionComputer; |
73 | 73 | import org.apache.paimon.utils.Pair; |
| 74 | +import org.apache.paimon.utils.RetryWaiter; |
74 | 75 | import org.apache.paimon.utils.SnapshotManager; |
75 | 76 |
|
76 | 77 | import org.slf4j.Logger; |
|
88 | 89 | import java.util.Objects; |
89 | 90 | import java.util.Optional; |
90 | 91 | import java.util.Set; |
91 | | -import java.util.concurrent.ThreadLocalRandom; |
92 | | -import java.util.concurrent.TimeUnit; |
93 | 92 | import java.util.stream.Collectors; |
94 | 93 |
|
95 | 94 | import static java.util.Collections.emptyList; |
@@ -152,8 +151,7 @@ public class FileStoreCommitImpl implements FileStoreCommit { |
152 | 151 | private final StatsFileHandler statsFileHandler; |
153 | 152 | private final BucketMode bucketMode; |
154 | 153 | private final long commitTimeout; |
155 | | - private final long commitMinRetryWait; |
156 | | - private final long commitMaxRetryWait; |
| 154 | + private final RetryWaiter retryWaiter; |
157 | 155 | private final int commitMaxRetries; |
158 | 156 | private final InternalRowPartitionComputer partitionComputer; |
159 | 157 | private final boolean rowTrackingEnabled; |
@@ -223,8 +221,7 @@ public FileStoreCommitImpl( |
223 | 221 | this.commitCallbacks = commitCallbacks; |
224 | 222 | this.commitMaxRetries = commitMaxRetries; |
225 | 223 | this.commitTimeout = commitTimeout; |
226 | | - this.commitMinRetryWait = commitMinRetryWait; |
227 | | - this.commitMaxRetryWait = commitMaxRetryWait; |
| 224 | + this.retryWaiter = new RetryWaiter(commitMinRetryWait, commitMaxRetryWait); |
228 | 225 | this.partitionComputer = |
229 | 226 | new InternalRowPartitionComputer( |
230 | 227 | options.partitionDefaultName(), |
@@ -720,7 +717,7 @@ private int tryCommit( |
720 | 717 | throw new RuntimeException(message, retryResult.exception); |
721 | 718 | } |
722 | 719 |
|
723 | | - commitRetryWait(retryCount); |
| 720 | + retryWaiter.retryWait(retryCount); |
724 | 721 | retryCount++; |
725 | 722 | } |
726 | 723 | return retryCount + 1; |
@@ -1070,7 +1067,7 @@ public void compactManifest() { |
1070 | 1067 | commitTimeout, retryCount)); |
1071 | 1068 | } |
1072 | 1069 |
|
1073 | | - commitRetryWait(retryCount); |
| 1070 | + retryWaiter.retryWait(retryCount); |
1074 | 1071 | retryCount++; |
1075 | 1072 | } |
1076 | 1073 | } |
@@ -1155,19 +1152,6 @@ private boolean commitSnapshotImpl(Snapshot newSnapshot, List<PartitionEntry> de |
1155 | 1152 | } |
1156 | 1153 | } |
1157 | 1154 |
|
1158 | | - private void commitRetryWait(int retryCount) { |
1159 | | - int retryWait = |
1160 | | - (int) Math.min(commitMinRetryWait * Math.pow(2, retryCount), commitMaxRetryWait); |
1161 | | - ThreadLocalRandom random = ThreadLocalRandom.current(); |
1162 | | - retryWait += random.nextInt(Math.max(1, (int) (retryWait * 0.2))); |
1163 | | - try { |
1164 | | - TimeUnit.MILLISECONDS.sleep(retryWait); |
1165 | | - } catch (InterruptedException ie) { |
1166 | | - Thread.currentThread().interrupt(); |
1167 | | - throw new RuntimeException(ie); |
1168 | | - } |
1169 | | - } |
1170 | | - |
1171 | 1155 | @Override |
1172 | 1156 | public void close() { |
1173 | 1157 | IOUtils.closeAllQuietly(commitCallbacks); |
|
0 commit comments