Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spark 3.5: Fix RewriteDataFiles with partial progress enabled and max-failed-commits larger than total-file-group #12120

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ private Builder doExecuteWithPartialProgress(
// stop commit service
commitService.close();

int failedCommits = maxCommits - commitService.succeededCommits();
int totalCommits = groupsPerCommit == 1 ? ctx.totalGroupCount() : maxCommits;
int failedCommits = totalCommits - commitService.succeededCommits();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this calculation is weird and doesn't look at actually failed commits. Why not collect the failed commits within the commit service and use it here? Something like

--- a/core/src/main/java/org/apache/iceberg/actions/BaseCommitService.java
+++ b/core/src/main/java/org/apache/iceberg/actions/BaseCommitService.java
@@ -61,6 +61,7 @@ abstract class BaseCommitService<T> implements Closeable {
   private final AtomicBoolean running = new AtomicBoolean(false);
   private final long timeoutInMS;
   private int succeededCommits = 0;
+  private int failedCommits = 0;

   /**
    * Constructs a {@link BaseCommitService}
@@ -231,6 +232,7 @@ abstract class BaseCommitService<T> implements Closeable {
         succeededCommits++;
       } catch (Exception e) {
         LOG.error("Failure during rewrite commit process, partial progress enabled. Ignoring", e);
+        failedCommits++;
       }
       inProgressCommits.remove(inProgressCommitToken);
     }
@@ -240,6 +242,10 @@ abstract class BaseCommitService<T> implements Closeable {
     return succeededCommits;
   }

+  public int failedCommits() {
+    return failedCommits;
+  }
+
   @VisibleForTesting
   boolean canCreateCommitGroup() {
     // Either we have a full commit group, or we have completed writing and need to commit
diff --git a/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/actions/RewriteDataFilesSparkAction.java b/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/actions/RewriteDataFilesSparkAction.java
index e04a0c88b4..7c851c3dc9 100644
--- a/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/actions/RewriteDataFilesSparkAction.java
+++ b/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/actions/RewriteDataFilesSparkAction.java
@@ -377,7 +377,7 @@ public class RewriteDataFilesSparkAction
     // stop commit service
     commitService.close();

-    int failedCommits = maxCommits - commitService.succeededCommits();
+    int failedCommits = commitService.failedCommits();
     if (failedCommits > 0 && failedCommits <= maxFailedCommits) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because when a rewrite group fails, it's not submitted to commit service. failedCommits only count failures in the commit service.

if (failedCommits > 0 && failedCommits <= maxFailedCommits) {
LOG.warn(
"{} is true but {} rewrite commits failed. Check the logs to determine why the individual "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,33 @@ public void testParallelPartialProgressWithMaxFailedCommits() {
shouldHaveACleanCache(table);
}

@TestTemplate
public void testParallelPartialProgressWithMaxFailedCommitsLargerThanTotalFileGroup() {
Table table = createTable(20);
int fileSize = averageFileSize(table);

List<Object[]> originalData = currentData();

RewriteDataFilesSparkAction rewrite =
basicRewrite(table)
.option(
RewriteDataFiles.MAX_FILE_GROUP_SIZE_BYTES, Integer.toString(fileSize * 2 + 1000))
.option(RewriteDataFiles.MAX_CONCURRENT_FILE_GROUP_REWRITES, "3")
.option(RewriteDataFiles.PARTIAL_PROGRESS_ENABLED, "true")
.option(RewriteDataFiles.PARTIAL_PROGRESS_MAX_COMMITS, "20")
.option(RewriteDataFiles.PARTIAL_PROGRESS_MAX_FAILED_COMMITS, "0");
rewrite.execute();

table.refresh();

List<Object[]> postRewriteData = currentData();
assertEquals("We shouldn't have changed the data", originalData, postRewriteData);
// With 10 original groups and max commits of 20, we have 1 group per commit.
shouldHaveSnapshots(table, 11);
shouldHaveNoOrphans(table);
shouldHaveACleanCache(table);
}

@TestTemplate
public void testInvalidOptions() {
Table table = createTable(20);
Expand Down