dramaticlly commented on code in PR #15148:
URL: https://github.com/apache/iceberg/pull/15148#discussion_r2728951585


##########
core/src/test/java/org/apache/iceberg/TestSetStatisticsConcurrency.java:
##########
@@ -0,0 +1,196 @@
+/*
+ * 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.iceberg;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.apache.iceberg.exceptions.CommitFailedException;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Tests for SetStatistics concurrency handling.
+ *
+ * <p>Tests that SetStatistics properly handles concurrent modifications using 
retry mechanism.
+ */
+@ExtendWith(ParameterizedTestExtension.class)
+public class TestSetStatisticsConcurrency extends TestBase {

Review Comment:
   do we need a new unit test ? I think we might just bring those to 
TestSetStatistics.java. From what I can tell, the comment in unit test is 
uncommon, usually assertion with `assertThat().as($comments)` is 
self-explanatory. 



##########
core/src/main/java/org/apache/iceberg/SetStatistics.java:
##########
@@ -18,12 +18,26 @@
  */
 package org.apache.iceberg;
 
+import static org.apache.iceberg.TableProperties.COMMIT_MAX_RETRY_WAIT_MS;
+import static 
org.apache.iceberg.TableProperties.COMMIT_MAX_RETRY_WAIT_MS_DEFAULT;
+import static org.apache.iceberg.TableProperties.COMMIT_MIN_RETRY_WAIT_MS;
+import static 
org.apache.iceberg.TableProperties.COMMIT_MIN_RETRY_WAIT_MS_DEFAULT;
+import static org.apache.iceberg.TableProperties.COMMIT_NUM_RETRIES;
+import static org.apache.iceberg.TableProperties.COMMIT_NUM_RETRIES_DEFAULT;
+import static org.apache.iceberg.TableProperties.COMMIT_TOTAL_RETRY_TIME_MS;
+import static 
org.apache.iceberg.TableProperties.COMMIT_TOTAL_RETRY_TIME_MS_DEFAULT;
+
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import org.apache.iceberg.exceptions.CommitFailedException;
 import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.util.Tasks;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class SetStatistics implements UpdateStatistics {
+  private static final Logger LOG = 
LoggerFactory.getLogger(SetStatistics.class);

Review Comment:
   nit: new line after to separate with non-static



##########
core/src/main/java/org/apache/iceberg/SetStatistics.java:
##########
@@ -50,9 +64,36 @@ public List<StatisticsFile> apply() {
 
   @Override
   public void commit() {
-    TableMetadata base = ops.current();
-    TableMetadata newMetadata = internalApply(base);
-    ops.commit(base, newMetadata);
+    // Get current metadata for retry configuration
+    TableMetadata currentMetadata = ops.current();
+
+    // Retry loop with exponential backoff
+    Tasks.foreach(ops)
+        .retry(currentMetadata.propertyAsInt(COMMIT_NUM_RETRIES, 
COMMIT_NUM_RETRIES_DEFAULT))
+        .exponentialBackoff(
+            currentMetadata.propertyAsInt(
+                COMMIT_MIN_RETRY_WAIT_MS, COMMIT_MIN_RETRY_WAIT_MS_DEFAULT),
+            currentMetadata.propertyAsInt(
+                COMMIT_MAX_RETRY_WAIT_MS, COMMIT_MAX_RETRY_WAIT_MS_DEFAULT),
+            currentMetadata.propertyAsInt(
+                COMMIT_TOTAL_RETRY_TIME_MS, 
COMMIT_TOTAL_RETRY_TIME_MS_DEFAULT),
+            2.0)
+        .onlyRetryOn(CommitFailedException.class)
+        .run(
+            taskOps -> {
+              // Refresh metadata on each retry attempt
+              TableMetadata base = taskOps.refresh();
+              TableMetadata newMetadata = internalApply(base);
+
+              // Skip if no changes
+              if (base == newMetadata) {
+                LOG.info("No statistics changes to commit, skipping");

Review Comment:
   I think debug shall be sufficient here or we can remove it entirely.



-- 
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