Skip to content
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 @@ -27,6 +27,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.iceberg.Table;
import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
Expand Down Expand Up @@ -60,7 +61,7 @@ abstract class BaseCommitService<T> implements Closeable {
private final int rewritesPerCommit;
private final AtomicBoolean running = new AtomicBoolean(false);
private final long timeoutInMS;
private int succeededCommits = 0;
private final AtomicInteger succeededCommits = new AtomicInteger(0);

/**
* Constructs a {@link BaseCommitService}
Expand Down Expand Up @@ -228,7 +229,7 @@ private void commitReadyCommitGroups() {
try {
commitOrClean(batch);
committedRewrites.addAll(batch);
succeededCommits++;
succeededCommits.incrementAndGet();
} catch (Exception e) {
LOG.error("Failure during rewrite commit process, partial progress enabled. Ignoring", e);
}
Expand All @@ -237,7 +238,7 @@ private void commitReadyCommitGroups() {
}

public int succeededCommits() {
return succeededCommits;
return succeededCommits.get();
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ private Builder doExecuteWithPartialProgress(
// stop commit service
commitService.close();

int totalCommits = Math.min(plan.totalGroupCount(), maxCommits);
int totalCommits =
IntMath.divide(plan.totalGroupCount(), groupsPerCommit, RoundingMode.CEILING);
int failedCommits = totalCommits - commitService.succeededCommits();
if (failedCommits > 0 && failedCommits <= maxFailedCommits) {
LOG.warn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,40 @@ public void testParallelPartialProgressWithMaxCommitsLargerThanTotalGroupCount()
shouldHaveACleanCache(table);
}

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

table.updateProperties().set(COMMIT_NUM_RETRIES, "10").commit();

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, "2")
.option(RewriteDataFiles.PARTIAL_PROGRESS_ENABLED, "true")
// Since we can have at most one commit per 2 file groups and there
// are only 10 file groups, actual number of commits is 5.
.option(RewriteDataFiles.PARTIAL_PROGRESS_MAX_COMMITS, "7")
.option(RewriteDataFiles.PARTIAL_PROGRESS_MAX_FAILED_COMMITS, "0");

RewriteDataFiles.Result result = rewrite.execute();
assertThat(result.rewriteResults()).hasSize(10);
assertThat(result.rewriteFailures()).hasSize(0);

List<Object[]> postRewriteData = currentData();
assertEquals("We shouldn't have changed the data", originalData, postRewriteData);

// With 10 original groups and max commits of 7, we have 2 groups per commit.
// That produces 5 rewrite commits plus the initial snapshot (6 snapshots total).
shouldHaveSnapshots(table, 6);
shouldHaveNoOrphans(table);
shouldHaveACleanCache(table);
}

@TestTemplate
public void testInvalidOptions() {
Table table = createTable(20);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ private Builder doExecuteWithPartialProgress(
// stop commit service
commitService.close();

int totalCommits = Math.min(plan.totalGroupCount(), maxCommits);
int totalCommits =
IntMath.divide(plan.totalGroupCount(), groupsPerCommit, RoundingMode.CEILING);
int failedCommits = totalCommits - commitService.succeededCommits();
if (failedCommits > 0 && failedCommits <= maxFailedCommits) {
LOG.warn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,40 @@ public void testParallelPartialProgressWithMaxCommitsLargerThanTotalGroupCount()
shouldHaveACleanCache(table);
}

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

table.updateProperties().set(COMMIT_NUM_RETRIES, "10").commit();

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, "2")
.option(RewriteDataFiles.PARTIAL_PROGRESS_ENABLED, "true")
// Since we can have at most one commit per 2 file groups and there
// are only 10 file groups, actual number of commits is 5.
.option(RewriteDataFiles.PARTIAL_PROGRESS_MAX_COMMITS, "7")
.option(RewriteDataFiles.PARTIAL_PROGRESS_MAX_FAILED_COMMITS, "0");

RewriteDataFiles.Result result = rewrite.execute();
assertThat(result.rewriteResults()).hasSize(10);
assertThat(result.rewriteFailures()).hasSize(0);

List<Object[]> postRewriteData = currentData();
assertEquals("We shouldn't have changed the data", originalData, postRewriteData);

// With 10 original groups and max commits of 7, we have 2 groups per commit.
// That produces 5 rewrite commits plus the initial snapshot (6 snapshots total).
shouldHaveSnapshots(table, 6);
shouldHaveNoOrphans(table);
shouldHaveACleanCache(table);
}

@TestTemplate
public void testInvalidOptions() {
Table table = createTable(20);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ private Builder doExecuteWithPartialProgress(
// stop commit service
commitService.close();

int totalCommits = Math.min(plan.totalGroupCount(), maxCommits);
int totalCommits =
IntMath.divide(plan.totalGroupCount(), groupsPerCommit, RoundingMode.CEILING);
int failedCommits = totalCommits - commitService.succeededCommits();
if (failedCommits > 0 && failedCommits <= maxFailedCommits) {
LOG.warn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,40 @@ public void testParallelPartialProgressWithMaxCommitsLargerThanTotalGroupCount()
shouldHaveACleanCache(table);
}

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

table.updateProperties().set(COMMIT_NUM_RETRIES, "10").commit();

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, "2")
.option(RewriteDataFiles.PARTIAL_PROGRESS_ENABLED, "true")
// Since we can have at most one commit per 2 file groups and there
// are only 10 file groups, actual number of commits is 5.
.option(RewriteDataFiles.PARTIAL_PROGRESS_MAX_COMMITS, "7")
.option(RewriteDataFiles.PARTIAL_PROGRESS_MAX_FAILED_COMMITS, "0");

RewriteDataFiles.Result result = rewrite.execute();
assertThat(result.rewriteResults()).hasSize(10);
assertThat(result.rewriteFailures()).hasSize(0);

List<Object[]> postRewriteData = currentData();
assertEquals("We shouldn't have changed the data", originalData, postRewriteData);

// With 10 original groups and max commits of 7, we have 2 groups per commit.
// That produces 5 rewrite commits plus the initial snapshot (6 snapshots total).
shouldHaveSnapshots(table, 6);
shouldHaveNoOrphans(table);
shouldHaveACleanCache(table);
}

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