linguoxuan commented on code in PR #576:
URL: https://github.com/apache/iceberg-cpp/pull/576#discussion_r2971197987


##########
src/iceberg/util/retry_util.h:
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <chrono>
+#include <functional>
+#include <optional>
+#include <random>
+#include <thread>
+#include <vector>
+
+#include "iceberg/result.h"
+
+namespace iceberg {
+
+/// \brief Configuration for retry behavior
+struct RetryConfig {
+  /// Maximum number of retry attempts (not including the first attempt)
+  int32_t num_retries = 4;
+  /// Minimum wait time between retries in milliseconds
+  int32_t min_wait_ms = 100;
+  /// Maximum wait time between retries in milliseconds
+  int32_t max_wait_ms = 60 * 1000;  // 1 minute
+  /// Total maximum time for all retries in milliseconds
+  int32_t total_timeout_ms = 30 * 60 * 1000;  // 30 minutes
+  /// Exponential backoff scale factor
+  double scale_factor = 2.0;
+};
+
+/// \brief Utility class for running tasks with retry logic
+class RetryRunner {
+ public:
+  RetryRunner() = default;
+
+  RetryRunner& WithRetries(int32_t num_retries) {
+    config_.num_retries = num_retries;
+    return *this;
+  }
+
+  RetryRunner& WithExponentialBackoff(int32_t min_wait_ms, int32_t max_wait_ms,
+                                      int32_t total_timeout_ms, double 
scale_factor) {
+    config_.min_wait_ms = min_wait_ms;
+    config_.max_wait_ms = max_wait_ms;
+    config_.total_timeout_ms = total_timeout_ms;
+    config_.scale_factor = scale_factor;
+    return *this;
+  }
+
+  /// \brief Specify error types that should trigger a retry
+  RetryRunner& OnlyRetryOn(std::initializer_list<ErrorKind> error_kinds) {

Review Comment:
   The current implementation handles this by giving OnlyRetryOn precedence 
over StopRetryOn, which aligns with the Java upstream behavior in Tasks.java 
(no runtime check either). I think it's enough since the API is unlikely to be 
called with both set simultaneously. WDYT?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to