You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ji...@apache.org on 2024/10/31 09:53:18 UTC
(hadoop) 17/30: Integration of TOS: Add RetryableUtils.
This is an automated email from the ASF dual-hosted git repository.
jinglun pushed a commit to branch HADOOP-19236
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit fbf16e25b58015cfb1db3268139669fa36d85375
Author: lijinglun <li...@bytedance.com>
AuthorDate: Wed Aug 21 17:50:18 2024 +0800
Integration of TOS: Add RetryableUtils.
---
.../hadoop/fs/tosfs/util/RetryableUtils.java | 55 ++++++++++++++++++++++
1 file changed, 55 insertions(+)
diff --git a/hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/util/RetryableUtils.java b/hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/util/RetryableUtils.java
new file mode 100644
index 00000000000..7117a6becc2
--- /dev/null
+++ b/hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/util/RetryableUtils.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.fs.tosfs.util;
+
+import java.util.concurrent.ThreadLocalRandom;
+
+public class RetryableUtils {
+ private static final ThreadLocalRandom RANDOM = ThreadLocalRandom.current();
+
+ private RetryableUtils() {
+ }
+
+ /**
+ * Copy from {@link com.volcengine.tos.internal.util.TosUtils#backoff(int)}
+ *
+ * @param attempt the attempt count
+ * @return backoff milliseconds
+ */
+ public static long backoff(int attempt) {
+ if (attempt == 0) {
+ return 1000L;
+ } else {
+ double backoff = 1.0;
+
+ double max;
+ for (max = 10.0; backoff < max && attempt > 0; --attempt) {
+ backoff *= 1.6;
+ }
+
+ if (backoff > max) {
+ backoff = max;
+ }
+
+ backoff *= 1.0 + 0.2 * (RANDOM.nextDouble(1.0) * 2.0 - 1.0);
+ return backoff < 0.0 ? 0L : (long) (backoff * 1000.0);
+ }
+ }
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org