You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "aokolnychyi (via GitHub)" <gi...@apache.org> on 2024/09/05 21:28:24 UTC
[PR] Core: Optimize writing metadata for many new files [iceberg]
aokolnychyi opened a new pull request, #11086:
URL: https://github.com/apache/iceberg/pull/11086
This PR optimizes writing metadata for many new files, which is helpful during initial table creation and row-level operations that modify many files.
Benchmark results prior to the changes:
```
Benchmark (fast) (numFiles) Mode Cnt Score Error Units
AppendBenchmark.appendFiles true 50000 ss 5 1.111 ± 0.035 s/op
AppendBenchmark.appendFiles true 100000 ss 5 2.114 ± 0.049 s/op
AppendBenchmark.appendFiles true 500000 ss 5 10.144 ± 0.182 s/op
AppendBenchmark.appendFiles true 1000000 ss 5 20.205 ± 0.388 s/op
AppendBenchmark.appendFiles true 2500000 ss 5 51.280 ± 3.610 s/op
AppendBenchmark.appendFiles false 50000 ss 5 1.125 ± 0.084 s/op
AppendBenchmark.appendFiles false 100000 ss 5 2.107 ± 0.095 s/op
AppendBenchmark.appendFiles false 500000 ss 5 10.117 ± 0.398 s/op
AppendBenchmark.appendFiles false 1000000 ss 5 20.350 ± 1.046 s/op
AppendBenchmark.appendFiles false 2500000 ss 5 48.823 ± 3.604 s/op
```
Benchmark results after the changes:
```
Benchmark (fast) (numFiles) Mode Cnt Score Error Units
AppendBenchmark.appendFiles true 50000 ss 5 0.383 ± 0.072 s/op
AppendBenchmark.appendFiles true 100000 ss 5 0.435 ± 0.031 s/op
AppendBenchmark.appendFiles true 500000 ss 5 1.283 ± 0.152 s/op
AppendBenchmark.appendFiles true 1000000 ss 5 2.325 ± 0.411 s/op
AppendBenchmark.appendFiles true 2500000 ss 5 5.615 ± 1.203 s/op
AppendBenchmark.appendFiles false 50000 ss 5 0.403 ± 0.023 s/op
AppendBenchmark.appendFiles false 100000 ss 5 0.484 ± 0.058 s/op
AppendBenchmark.appendFiles false 500000 ss 5 1.357 ± 0.190 s/op
AppendBenchmark.appendFiles false 1000000 ss 5 2.596 ± 0.829 s/op
AppendBenchmark.appendFiles false 2500000 ss 5 5.993 ± 1.447 s/op
```
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Parallelize manifest writing for many new files [iceberg]
Posted by "aokolnychyi (via GitHub)" <gi...@apache.org>.
aokolnychyi merged PR #11086:
URL: https://github.com/apache/iceberg/pull/11086
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Optimize writing metadata for many new files [iceberg]
Posted by "aokolnychyi (via GitHub)" <gi...@apache.org>.
aokolnychyi commented on code in PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#discussion_r1747921992
##########
core/src/test/java/org/apache/iceberg/TestFastAppend.java:
##########
@@ -42,6 +42,25 @@ protected static List<Object> parameters() {
return Arrays.asList(1, 2, 3);
}
+ @TestTemplate
+ public void testAddManyFiles() {
+ assertThat(listManifestFiles()).as("Table should start empty").isEmpty();
+
+ List<DataFile> dataFiles = Lists.newArrayList();
+
+ for (int ordinal = 0; ordinal < 20_000; ordinal++) {
Review Comment:
This would require making `MIN_FILE_GROUP_SIZE` package-private. I was debating that.
What's your opinion, @stevenzwu?
##########
core/src/test/java/org/apache/iceberg/TestSnapshotProducer.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+public class TestSnapshotProducer {
+ @Test
+ public void testManifestFileGroupSize() {
+ assertEquals(
+ 1_000,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 1_000 /* file count */),
+ "Must return file count when it is small");
+
+ assertEquals(
+ 10_000,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 10_000 /* file count */),
+ "Must return file count when it matches the min group size");
+
+ assertEquals(
+ 10_001,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 10_001 /* file count */),
+ "Must return file count when it is slightly above min group size");
+
+ assertEquals(
+ 12_500,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 12_500 /* file count */),
+ "Must return file count when remainder is < 50% of min group size");
Review Comment:
Will update.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Parallelize manifest writing for many new files [iceberg]
Posted by "karuppayya (via GitHub)" <gi...@apache.org>.
karuppayya commented on code in PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#discussion_r1751070837
##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -554,6 +562,84 @@ protected boolean cleanupAfterCommit() {
return true;
}
+ protected List<ManifestFile> writeDataManifests(List<DataFile> files, PartitionSpec spec) {
+ return writeDataManifests(files, null /* inherit data seq */, spec);
+ }
+
+ protected List<ManifestFile> writeDataManifests(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDataFileGroup(group, dataSeq, spec));
+ }
+
+ private List<ManifestFile> writeDataFileGroup(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ RollingManifestWriter<DataFile> writer = newRollingManifestWriter(spec);
+
+ try (RollingManifestWriter<DataFile> closableWriter = writer) {
+ if (dataSeq != null) {
+ files.forEach(file -> closableWriter.add(file, dataSeq));
+ } else {
+ files.forEach(closableWriter::add);
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write data manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ protected List<ManifestFile> writeDeleteManifests(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDeleteFileGroup(group, spec));
+ }
+
+ private List<ManifestFile> writeDeleteFileGroup(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ RollingManifestWriter<DeleteFile> writer = newRollingDeleteManifestWriter(spec);
+
+ try (RollingManifestWriter<DeleteFile> closableWriter = writer) {
+ for (DeleteFileHolder file : files) {
+ if (file.dataSequenceNumber() != null) {
+ closableWriter.add(file.deleteFile(), file.dataSequenceNumber());
+ } else {
+ closableWriter.add(file.deleteFile());
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write delete manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ private static <F> List<ManifestFile> writeManifests(
+ List<F> files, Function<List<F>, List<ManifestFile>> writeFunc) {
+ int groupSize = manifestFileGroupSize(ThreadPools.WORKER_THREAD_POOL_SIZE, files.size());
+ List<List<F>> groups = Lists.partition(files, groupSize);
+ Queue<ManifestFile> manifests = Queues.newConcurrentLinkedQueue();
+ Tasks.foreach(groups)
+ .stopOnFailure()
+ .throwFailureWhenFinished()
+ .executeWith(ThreadPools.getWorkerPool())
+ .run(group -> manifests.addAll(writeFunc.apply(group)));
+ return ImmutableList.copyOf(manifests);
+ }
+
+ /**
+ * Calculates how many files can be processed concurrently depending on the provided parallelism
Review Comment:
Slight change in behavior from old code
1. I think it is the prior code we would have only one(the last) that is not sized rightly.
In this case, we would have more(equal to the parallelism) of not rightly sized manifest.
2. The max number of datafile in any manifest is 10_000
```private static final int MIN_FILE_GROUP_SIZE = 10_000;```
I guess 1 is ok
Should 2 be configurable?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Parallelize manifest writing for many new files [iceberg]
Posted by "dramaticlly (via GitHub)" <gi...@apache.org>.
dramaticlly commented on code in PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#discussion_r1751080154
##########
core/src/test/java/org/apache/iceberg/TestSnapshotProducer.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+public class TestSnapshotProducer {
+ @Test
+ public void testManifestFileGroupSize() {
+ assertEquals(
+ 1_000,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 1_000 /* file count */),
+ "Must return file count when it is small");
+
+ assertEquals(
+ 10_000,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 10_000 /* file count */),
+ "Must return file count when it matches the min group size");
+
+ assertEquals(
+ 10_001,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 10_001 /* file count */),
+ "Must return file count when it is slightly above min group size");
+
+ assertEquals(
+ 12_500,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 12_500 /* file count */),
+ "Must return file count when remainder is < 50% of min group size");
+
+ assertEquals(
+ 7_500,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 15_000 /* file count */),
+ "Must split into 2 groups when remainder is >= 50% of min group size");
+
+ assertEquals(
+ 16_667,
+ SnapshotProducer.manifestFileGroupSize(3 /* parallelism */, 50_000 /* file count */),
+ "Must split into 3 groups when file count is large");
+
+ assertEquals(
+ 166_667,
+ SnapshotProducer.manifestFileGroupSize(3 /* parallelism */, 500_000 /* file count */),
+ "Provided parallelism must be respected when file count is large");
+
+ assertEquals(
+ 10_000,
+ SnapshotProducer.manifestFileGroupSize(32 /* parallelism */, 50_000 /* file count */),
+ "Max parallelism based on file count must be respected");
Review Comment:
this read a bit weird, I am thinking maybe `Provided parallelism will be adjusted if not enough files in each group`
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Parallelize manifest writing for many new files [iceberg]
Posted by "aokolnychyi (via GitHub)" <gi...@apache.org>.
aokolnychyi commented on code in PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#discussion_r1757647083
##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -554,6 +562,84 @@ protected boolean cleanupAfterCommit() {
return true;
}
+ protected List<ManifestFile> writeDataManifests(List<DataFile> files, PartitionSpec spec) {
+ return writeDataManifests(files, null /* inherit data seq */, spec);
+ }
+
+ protected List<ManifestFile> writeDataManifests(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDataFileGroup(group, dataSeq, spec));
+ }
+
+ private List<ManifestFile> writeDataFileGroup(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ RollingManifestWriter<DataFile> writer = newRollingManifestWriter(spec);
+
+ try (RollingManifestWriter<DataFile> closableWriter = writer) {
+ if (dataSeq != null) {
+ files.forEach(file -> closableWriter.add(file, dataSeq));
+ } else {
+ files.forEach(closableWriter::add);
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write data manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ protected List<ManifestFile> writeDeleteManifests(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDeleteFileGroup(group, spec));
+ }
+
+ private List<ManifestFile> writeDeleteFileGroup(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ RollingManifestWriter<DeleteFile> writer = newRollingDeleteManifestWriter(spec);
+
+ try (RollingManifestWriter<DeleteFile> closableWriter = writer) {
+ for (DeleteFileHolder file : files) {
+ if (file.dataSequenceNumber() != null) {
+ closableWriter.add(file.deleteFile(), file.dataSequenceNumber());
+ } else {
+ closableWriter.add(file.deleteFile());
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write delete manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ private static <F> List<ManifestFile> writeManifests(
+ List<F> files, Function<List<F>, List<ManifestFile>> writeFunc) {
+ int groupSize = manifestFileGroupSize(ThreadPools.WORKER_THREAD_POOL_SIZE, files.size());
+ List<List<F>> groups = Lists.partition(files, groupSize);
+ Queue<ManifestFile> manifests = Queues.newConcurrentLinkedQueue();
+ Tasks.foreach(groups)
+ .stopOnFailure()
+ .throwFailureWhenFinished()
Review Comment:
It is essentially as it was before as we never cleaned up potentially produced files by the rolling writer. We can try to cover that in the future but I am not sure it would be worth the extra complexity. Such files will be cleaned up by table maintenance anyway.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Parallelize manifest writing for many new files [iceberg]
Posted by "aokolnychyi (via GitHub)" <gi...@apache.org>.
aokolnychyi commented on code in PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#discussion_r1757641413
##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -554,6 +562,84 @@ protected boolean cleanupAfterCommit() {
return true;
}
+ protected List<ManifestFile> writeDataManifests(List<DataFile> files, PartitionSpec spec) {
+ return writeDataManifests(files, null /* inherit data seq */, spec);
+ }
+
+ protected List<ManifestFile> writeDataManifests(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDataFileGroup(group, dataSeq, spec));
+ }
+
+ private List<ManifestFile> writeDataFileGroup(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ RollingManifestWriter<DataFile> writer = newRollingManifestWriter(spec);
+
+ try (RollingManifestWriter<DataFile> closableWriter = writer) {
+ if (dataSeq != null) {
+ files.forEach(file -> closableWriter.add(file, dataSeq));
+ } else {
+ files.forEach(closableWriter::add);
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write data manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ protected List<ManifestFile> writeDeleteManifests(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDeleteFileGroup(group, spec));
+ }
+
+ private List<ManifestFile> writeDeleteFileGroup(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ RollingManifestWriter<DeleteFile> writer = newRollingDeleteManifestWriter(spec);
+
+ try (RollingManifestWriter<DeleteFile> closableWriter = writer) {
+ for (DeleteFileHolder file : files) {
+ if (file.dataSequenceNumber() != null) {
+ closableWriter.add(file.deleteFile(), file.dataSequenceNumber());
+ } else {
+ closableWriter.add(file.deleteFile());
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write delete manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ private static <F> List<ManifestFile> writeManifests(
+ List<F> files, Function<List<F>, List<ManifestFile>> writeFunc) {
+ int groupSize = manifestFileGroupSize(ThreadPools.WORKER_THREAD_POOL_SIZE, files.size());
+ List<List<F>> groups = Lists.partition(files, groupSize);
+ Queue<ManifestFile> manifests = Queues.newConcurrentLinkedQueue();
+ Tasks.foreach(groups)
+ .stopOnFailure()
+ .throwFailureWhenFinished()
+ .executeWith(ThreadPools.getWorkerPool())
+ .run(group -> manifests.addAll(writeFunc.apply(group)));
+ return ImmutableList.copyOf(manifests);
+ }
+
+ /**
+ * Calculates how many files can be processed concurrently depending on the provided parallelism
+ * without creating too small manifests.
+ *
+ * @param parallelism the max number of concurrent writers
+ * @param fileCount the total number of files to be written
+ * @return the size of each file group, adjusted to balance workload across available writers
+ */
+ @VisibleForTesting
+ static int manifestFileGroupSize(int parallelism, int fileCount) {
+ int maxParallelism = IntMath.divide(fileCount, MIN_FILE_GROUP_SIZE, RoundingMode.HALF_UP);
+ int actualParallelism = Math.max(1, Math.min(parallelism, maxParallelism));
Review Comment:
I restructured this bit to make it cleaner. The new method reasons about the number of manifest writers.
##########
core/src/test/java/org/apache/iceberg/TestFastAppend.java:
##########
@@ -42,6 +42,25 @@ protected static List<Object> parameters() {
return Arrays.asList(1, 2, 3);
}
+ @TestTemplate
+ public void testAddManyFiles() {
+ assertThat(listManifestFiles()).as("Table should start empty").isEmpty();
+
+ List<DataFile> dataFiles = Lists.newArrayList();
+
+ for (int ordinal = 0; ordinal < 20_000; ordinal++) {
Review Comment:
Done.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Optimize writing metadata for many new files [iceberg]
Posted by "aokolnychyi (via GitHub)" <gi...@apache.org>.
aokolnychyi commented on code in PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#discussion_r1747920842
##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -554,6 +562,84 @@ protected boolean cleanupAfterCommit() {
return true;
}
+ protected List<ManifestFile> writeDataManifests(List<DataFile> files, PartitionSpec spec) {
+ return writeDataManifests(files, null /* inherit data seq */, spec);
+ }
+
+ protected List<ManifestFile> writeDataManifests(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDataFileGroup(group, dataSeq, spec));
+ }
+
+ private List<ManifestFile> writeDataFileGroup(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ RollingManifestWriter<DataFile> writer = newRollingManifestWriter(spec);
+
+ try (RollingManifestWriter<DataFile> closableWriter = writer) {
+ if (dataSeq != null) {
+ files.forEach(file -> closableWriter.add(file, dataSeq));
+ } else {
+ files.forEach(closableWriter::add);
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write data manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ protected List<ManifestFile> writeDeleteManifests(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDeleteFileGroup(group, spec));
+ }
+
+ private List<ManifestFile> writeDeleteFileGroup(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ RollingManifestWriter<DeleteFile> writer = newRollingDeleteManifestWriter(spec);
+
+ try (RollingManifestWriter<DeleteFile> closableWriter = writer) {
+ for (DeleteFileHolder file : files) {
+ if (file.dataSequenceNumber() != null) {
+ closableWriter.add(file.deleteFile(), file.dataSequenceNumber());
+ } else {
+ closableWriter.add(file.deleteFile());
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write delete manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ private static <F> List<ManifestFile> writeManifests(
+ List<F> files, Function<List<F>, List<ManifestFile>> writeFunc) {
+ int groupSize = manifestFileGroupSize(ThreadPools.WORKER_THREAD_POOL_SIZE, files.size());
+ List<List<F>> groups = Lists.partition(files, groupSize);
+ Queue<ManifestFile> manifests = Queues.newConcurrentLinkedQueue();
+ Tasks.foreach(groups)
+ .stopOnFailure()
+ .throwFailureWhenFinished()
+ .executeWith(ThreadPools.getWorkerPool())
+ .run(group -> manifests.addAll(writeFunc.apply(group)));
+ return ImmutableList.copyOf(manifests);
+ }
+
+ /**
+ * Calculates how many files can be processed concurrently depending on the provided parallelism
+ * without creating too small manifests.
+ *
+ * @param parallelism the max number of concurrent writers
+ * @param fileCount the total number of files to be written
+ * @return the size of each file group, adjusted to balance workload across available writers
+ */
+ @VisibleForTesting
+ static int manifestFileGroupSize(int parallelism, int fileCount) {
+ int maxParallelism = IntMath.divide(fileCount, MIN_FILE_GROUP_SIZE, RoundingMode.HALF_UP);
+ int actualParallelism = Math.max(1, Math.min(parallelism, maxParallelism));
Review Comment:
It is not only to handle `parallelism` as 0 but to also to handle cases with a small number of files, when we don't have a full group. Let me think if I can make it a bit more obvious.
##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -554,6 +562,84 @@ protected boolean cleanupAfterCommit() {
return true;
}
+ protected List<ManifestFile> writeDataManifests(List<DataFile> files, PartitionSpec spec) {
+ return writeDataManifests(files, null /* inherit data seq */, spec);
+ }
+
+ protected List<ManifestFile> writeDataManifests(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDataFileGroup(group, dataSeq, spec));
+ }
+
+ private List<ManifestFile> writeDataFileGroup(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ RollingManifestWriter<DataFile> writer = newRollingManifestWriter(spec);
+
+ try (RollingManifestWriter<DataFile> closableWriter = writer) {
+ if (dataSeq != null) {
+ files.forEach(file -> closableWriter.add(file, dataSeq));
+ } else {
+ files.forEach(closableWriter::add);
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write data manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ protected List<ManifestFile> writeDeleteManifests(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDeleteFileGroup(group, spec));
+ }
+
+ private List<ManifestFile> writeDeleteFileGroup(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ RollingManifestWriter<DeleteFile> writer = newRollingDeleteManifestWriter(spec);
+
+ try (RollingManifestWriter<DeleteFile> closableWriter = writer) {
+ for (DeleteFileHolder file : files) {
+ if (file.dataSequenceNumber() != null) {
+ closableWriter.add(file.deleteFile(), file.dataSequenceNumber());
+ } else {
+ closableWriter.add(file.deleteFile());
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write delete manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ private static <F> List<ManifestFile> writeManifests(
+ List<F> files, Function<List<F>, List<ManifestFile>> writeFunc) {
+ int groupSize = manifestFileGroupSize(ThreadPools.WORKER_THREAD_POOL_SIZE, files.size());
+ List<List<F>> groups = Lists.partition(files, groupSize);
+ Queue<ManifestFile> manifests = Queues.newConcurrentLinkedQueue();
+ Tasks.foreach(groups)
+ .stopOnFailure()
+ .throwFailureWhenFinished()
+ .executeWith(ThreadPools.getWorkerPool())
+ .run(group -> manifests.addAll(writeFunc.apply(group)));
+ return ImmutableList.copyOf(manifests);
+ }
+
+ /**
+ * Calculates how many files can be processed concurrently depending on the provided parallelism
+ * without creating too small manifests.
+ *
+ * @param parallelism the max number of concurrent writers
+ * @param fileCount the total number of files to be written
+ * @return the size of each file group, adjusted to balance workload across available writers
+ */
+ @VisibleForTesting
+ static int manifestFileGroupSize(int parallelism, int fileCount) {
+ int maxParallelism = IntMath.divide(fileCount, MIN_FILE_GROUP_SIZE, RoundingMode.HALF_UP);
+ int actualParallelism = Math.max(1, Math.min(parallelism, maxParallelism));
Review Comment:
It is not only to handle `parallelism` as 0 but to also to handle cases with a small number of files, when we don't have a full group. Let me think if I can make it a bit more obvious with better variable names.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Parallelize manifest writing for many new files [iceberg]
Posted by "karuppayya (via GitHub)" <gi...@apache.org>.
karuppayya commented on code in PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#discussion_r1751070837
##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -554,6 +562,84 @@ protected boolean cleanupAfterCommit() {
return true;
}
+ protected List<ManifestFile> writeDataManifests(List<DataFile> files, PartitionSpec spec) {
+ return writeDataManifests(files, null /* inherit data seq */, spec);
+ }
+
+ protected List<ManifestFile> writeDataManifests(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDataFileGroup(group, dataSeq, spec));
+ }
+
+ private List<ManifestFile> writeDataFileGroup(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ RollingManifestWriter<DataFile> writer = newRollingManifestWriter(spec);
+
+ try (RollingManifestWriter<DataFile> closableWriter = writer) {
+ if (dataSeq != null) {
+ files.forEach(file -> closableWriter.add(file, dataSeq));
+ } else {
+ files.forEach(closableWriter::add);
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write data manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ protected List<ManifestFile> writeDeleteManifests(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDeleteFileGroup(group, spec));
+ }
+
+ private List<ManifestFile> writeDeleteFileGroup(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ RollingManifestWriter<DeleteFile> writer = newRollingDeleteManifestWriter(spec);
+
+ try (RollingManifestWriter<DeleteFile> closableWriter = writer) {
+ for (DeleteFileHolder file : files) {
+ if (file.dataSequenceNumber() != null) {
+ closableWriter.add(file.deleteFile(), file.dataSequenceNumber());
+ } else {
+ closableWriter.add(file.deleteFile());
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write delete manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ private static <F> List<ManifestFile> writeManifests(
+ List<F> files, Function<List<F>, List<ManifestFile>> writeFunc) {
+ int groupSize = manifestFileGroupSize(ThreadPools.WORKER_THREAD_POOL_SIZE, files.size());
+ List<List<F>> groups = Lists.partition(files, groupSize);
+ Queue<ManifestFile> manifests = Queues.newConcurrentLinkedQueue();
+ Tasks.foreach(groups)
+ .stopOnFailure()
+ .throwFailureWhenFinished()
+ .executeWith(ThreadPools.getWorkerPool())
+ .run(group -> manifests.addAll(writeFunc.apply(group)));
+ return ImmutableList.copyOf(manifests);
+ }
+
+ /**
+ * Calculates how many files can be processed concurrently depending on the provided parallelism
Review Comment:
Slight change in behavior from old code
I think it is the prior code we would have only one(the last) that is not sized rightly.
In this case, we would have more(equal to the parallelism) of not rightly sized manifest. I guess that is ok?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Parallelize manifest writing for many new files [iceberg]
Posted by "karuppayya (via GitHub)" <gi...@apache.org>.
karuppayya commented on code in PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#discussion_r1751128701
##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -554,6 +562,84 @@ protected boolean cleanupAfterCommit() {
return true;
}
+ protected List<ManifestFile> writeDataManifests(List<DataFile> files, PartitionSpec spec) {
+ return writeDataManifests(files, null /* inherit data seq */, spec);
+ }
+
+ protected List<ManifestFile> writeDataManifests(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDataFileGroup(group, dataSeq, spec));
+ }
+
+ private List<ManifestFile> writeDataFileGroup(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ RollingManifestWriter<DataFile> writer = newRollingManifestWriter(spec);
+
+ try (RollingManifestWriter<DataFile> closableWriter = writer) {
+ if (dataSeq != null) {
+ files.forEach(file -> closableWriter.add(file, dataSeq));
+ } else {
+ files.forEach(closableWriter::add);
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write data manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ protected List<ManifestFile> writeDeleteManifests(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDeleteFileGroup(group, spec));
+ }
+
+ private List<ManifestFile> writeDeleteFileGroup(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ RollingManifestWriter<DeleteFile> writer = newRollingDeleteManifestWriter(spec);
+
+ try (RollingManifestWriter<DeleteFile> closableWriter = writer) {
+ for (DeleteFileHolder file : files) {
+ if (file.dataSequenceNumber() != null) {
+ closableWriter.add(file.deleteFile(), file.dataSequenceNumber());
+ } else {
+ closableWriter.add(file.deleteFile());
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write delete manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ private static <F> List<ManifestFile> writeManifests(
+ List<F> files, Function<List<F>, List<ManifestFile>> writeFunc) {
+ int groupSize = manifestFileGroupSize(ThreadPools.WORKER_THREAD_POOL_SIZE, files.size());
+ List<List<F>> groups = Lists.partition(files, groupSize);
+ Queue<ManifestFile> manifests = Queues.newConcurrentLinkedQueue();
+ Tasks.foreach(groups)
+ .stopOnFailure()
+ .throwFailureWhenFinished()
Review Comment:
Do we want to do any clean up on failures?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Parallelize manifest writing for many new files [iceberg]
Posted by "aokolnychyi (via GitHub)" <gi...@apache.org>.
aokolnychyi commented on PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#issuecomment-2347417367
I've addressed the feedback. Thanks for reviewing, @stevenzwu @amogh-jahagirdar @karuppayya @dramaticlly @nastra!
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Parallelize manifest writing for many new files [iceberg]
Posted by "aokolnychyi (via GitHub)" <gi...@apache.org>.
aokolnychyi commented on code in PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#discussion_r1757656534
##########
core/src/test/java/org/apache/iceberg/TestSnapshotProducer.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+public class TestSnapshotProducer {
+ @Test
+ public void testManifestFileGroupSize() {
+ assertEquals(
+ 1_000,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 1_000 /* file count */),
+ "Must return file count when it is small");
+
+ assertEquals(
+ 10_000,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 10_000 /* file count */),
+ "Must return file count when it matches the min group size");
+
+ assertEquals(
+ 10_001,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 10_001 /* file count */),
+ "Must return file count when it is slightly above min group size");
+
+ assertEquals(
+ 12_500,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 12_500 /* file count */),
+ "Must return file count when remainder is < 50% of min group size");
+
+ assertEquals(
+ 7_500,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 15_000 /* file count */),
+ "Must split into 2 groups when remainder is >= 50% of min group size");
+
+ assertEquals(
+ 16_667,
+ SnapshotProducer.manifestFileGroupSize(3 /* parallelism */, 50_000 /* file count */),
+ "Must split into 3 groups when file count is large");
+
+ assertEquals(
+ 166_667,
+ SnapshotProducer.manifestFileGroupSize(3 /* parallelism */, 500_000 /* file count */),
+ "Provided parallelism must be respected when file count is large");
+
+ assertEquals(
+ 10_000,
+ SnapshotProducer.manifestFileGroupSize(32 /* parallelism */, 50_000 /* file count */),
+ "Max parallelism based on file count must be respected");
Review Comment:
Fixed.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Optimize writing metadata for many new files [iceberg]
Posted by "stevenzwu (via GitHub)" <gi...@apache.org>.
stevenzwu commented on code in PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#discussion_r1747731139
##########
core/src/test/java/org/apache/iceberg/TestSnapshotProducer.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+public class TestSnapshotProducer {
+ @Test
+ public void testManifestFileGroupSize() {
+ assertEquals(
+ 1_000,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 1_000 /* file count */),
+ "Must return file count when it is small");
+
+ assertEquals(
+ 10_000,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 10_000 /* file count */),
+ "Must return file count when it matches the min group size");
+
+ assertEquals(
+ 10_001,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 10_001 /* file count */),
+ "Must return file count when it is slightly above min group size");
+
+ assertEquals(
+ 12_500,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 12_500 /* file count */),
+ "Must return file count when remainder is < 50% of min group size");
Review Comment:
nit: `when remainder is < 50% of min group size` is less clear to me. maybe `when it is less than 1.5x of min group size`?
##########
core/src/test/java/org/apache/iceberg/TestSnapshotProducer.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+public class TestSnapshotProducer {
+ @Test
+ public void testManifestFileGroupSize() {
+ assertEquals(
+ 1_000,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 1_000 /* file count */),
+ "Must return file count when it is small");
+
+ assertEquals(
+ 10_000,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 10_000 /* file count */),
+ "Must return file count when it matches the min group size");
+
+ assertEquals(
+ 10_001,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 10_001 /* file count */),
+ "Must return file count when it is slightly above min group size");
+
+ assertEquals(
+ 12_500,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 12_500 /* file count */),
+ "Must return file count when remainder is < 50% of min group size");
+
+ assertEquals(
+ 7_500,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 15_000 /* file count */),
+ "Must split into 2 groups when remainder is >= 50% of min group size");
Review Comment:
same as above
##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -554,6 +562,84 @@ protected boolean cleanupAfterCommit() {
return true;
}
+ protected List<ManifestFile> writeDataManifests(List<DataFile> files, PartitionSpec spec) {
+ return writeDataManifests(files, null /* inherit data seq */, spec);
+ }
+
+ protected List<ManifestFile> writeDataManifests(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDataFileGroup(group, dataSeq, spec));
+ }
+
+ private List<ManifestFile> writeDataFileGroup(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ RollingManifestWriter<DataFile> writer = newRollingManifestWriter(spec);
+
+ try (RollingManifestWriter<DataFile> closableWriter = writer) {
+ if (dataSeq != null) {
+ files.forEach(file -> closableWriter.add(file, dataSeq));
+ } else {
+ files.forEach(closableWriter::add);
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write data manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ protected List<ManifestFile> writeDeleteManifests(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDeleteFileGroup(group, spec));
+ }
+
+ private List<ManifestFile> writeDeleteFileGroup(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ RollingManifestWriter<DeleteFile> writer = newRollingDeleteManifestWriter(spec);
+
+ try (RollingManifestWriter<DeleteFile> closableWriter = writer) {
+ for (DeleteFileHolder file : files) {
+ if (file.dataSequenceNumber() != null) {
+ closableWriter.add(file.deleteFile(), file.dataSequenceNumber());
+ } else {
+ closableWriter.add(file.deleteFile());
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write delete manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ private static <F> List<ManifestFile> writeManifests(
+ List<F> files, Function<List<F>, List<ManifestFile>> writeFunc) {
+ int groupSize = manifestFileGroupSize(ThreadPools.WORKER_THREAD_POOL_SIZE, files.size());
+ List<List<F>> groups = Lists.partition(files, groupSize);
+ Queue<ManifestFile> manifests = Queues.newConcurrentLinkedQueue();
+ Tasks.foreach(groups)
Review Comment:
nit: maybe the subject of this PR could be more specific like `Core: Parallelize manifest writing for many new files`
##########
core/src/test/java/org/apache/iceberg/TestSnapshotProducer.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+public class TestSnapshotProducer {
+ @Test
+ public void testManifestFileGroupSize() {
+ assertEquals(
+ 1_000,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 1_000 /* file count */),
+ "Must return file count when it is small");
+
+ assertEquals(
+ 10_000,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 10_000 /* file count */),
+ "Must return file count when it matches the min group size");
+
+ assertEquals(
+ 10_001,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 10_001 /* file count */),
+ "Must return file count when it is slightly above min group size");
+
+ assertEquals(
+ 12_500,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 12_500 /* file count */),
+ "Must return file count when remainder is < 50% of min group size");
+
+ assertEquals(
+ 7_500,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 15_000 /* file count */),
+ "Must split into 2 groups when remainder is >= 50% of min group size");
+
+ assertEquals(
+ 16_667,
+ SnapshotProducer.manifestFileGroupSize(3 /* parallelism */, 50_000 /* file count */),
+ "Must split into 3 groups when file count is large");
Review Comment:
this test is essentially the same as the one below. note that min group size is 10_000.
##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -554,6 +562,84 @@ protected boolean cleanupAfterCommit() {
return true;
}
+ protected List<ManifestFile> writeDataManifests(List<DataFile> files, PartitionSpec spec) {
+ return writeDataManifests(files, null /* inherit data seq */, spec);
+ }
+
+ protected List<ManifestFile> writeDataManifests(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDataFileGroup(group, dataSeq, spec));
+ }
+
+ private List<ManifestFile> writeDataFileGroup(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ RollingManifestWriter<DataFile> writer = newRollingManifestWriter(spec);
+
+ try (RollingManifestWriter<DataFile> closableWriter = writer) {
+ if (dataSeq != null) {
+ files.forEach(file -> closableWriter.add(file, dataSeq));
+ } else {
+ files.forEach(closableWriter::add);
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write data manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ protected List<ManifestFile> writeDeleteManifests(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDeleteFileGroup(group, spec));
+ }
+
+ private List<ManifestFile> writeDeleteFileGroup(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ RollingManifestWriter<DeleteFile> writer = newRollingDeleteManifestWriter(spec);
+
+ try (RollingManifestWriter<DeleteFile> closableWriter = writer) {
+ for (DeleteFileHolder file : files) {
+ if (file.dataSequenceNumber() != null) {
+ closableWriter.add(file.deleteFile(), file.dataSequenceNumber());
+ } else {
+ closableWriter.add(file.deleteFile());
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write delete manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ private static <F> List<ManifestFile> writeManifests(
+ List<F> files, Function<List<F>, List<ManifestFile>> writeFunc) {
+ int groupSize = manifestFileGroupSize(ThreadPools.WORKER_THREAD_POOL_SIZE, files.size());
+ List<List<F>> groups = Lists.partition(files, groupSize);
+ Queue<ManifestFile> manifests = Queues.newConcurrentLinkedQueue();
+ Tasks.foreach(groups)
+ .stopOnFailure()
+ .throwFailureWhenFinished()
+ .executeWith(ThreadPools.getWorkerPool())
+ .run(group -> manifests.addAll(writeFunc.apply(group)));
+ return ImmutableList.copyOf(manifests);
+ }
+
+ /**
+ * Calculates how many files can be processed concurrently depending on the provided parallelism
+ * without creating too small manifests.
+ *
+ * @param parallelism the max number of concurrent writers
+ * @param fileCount the total number of files to be written
+ * @return the size of each file group, adjusted to balance workload across available writers
+ */
+ @VisibleForTesting
+ static int manifestFileGroupSize(int parallelism, int fileCount) {
+ int maxParallelism = IntMath.divide(fileCount, MIN_FILE_GROUP_SIZE, RoundingMode.HALF_UP);
+ int actualParallelism = Math.max(1, Math.min(parallelism, maxParallelism));
Review Comment:
nit: is `Math.max(1, ...)` redundant? should we have assertion that `parallelism` and `fileCount` are `> 0`
##########
core/src/test/java/org/apache/iceberg/TestFastAppend.java:
##########
@@ -42,6 +42,25 @@ protected static List<Object> parameters() {
return Arrays.asList(1, 2, 3);
}
+ @TestTemplate
+ public void testAddManyFiles() {
+ assertThat(listManifestFiles()).as("Table should start empty").isEmpty();
+
+ List<DataFile> dataFiles = Lists.newArrayList();
+
+ for (int ordinal = 0; ordinal < 20_000; ordinal++) {
Review Comment:
nit: change `20_000` to `MIN_FILE_GROUP_SIZE * 2`.
applicable to other tests.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Parallelize manifest writing for many new files [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#discussion_r1751586752
##########
core/src/test/java/org/apache/iceberg/TestSnapshotProducer.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.junit.jupiter.api.Assertions.assertEquals;
Review Comment:
just FYI that the project moved to using AssertJ assertions
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Parallelize manifest writing for many new files [iceberg]
Posted by "stevenzwu (via GitHub)" <gi...@apache.org>.
stevenzwu commented on code in PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#discussion_r1749541033
##########
core/src/test/java/org/apache/iceberg/TestFastAppend.java:
##########
@@ -42,6 +42,25 @@ protected static List<Object> parameters() {
return Arrays.asList(1, 2, 3);
}
+ @TestTemplate
+ public void testAddManyFiles() {
+ assertThat(listManifestFiles()).as("Table should start empty").isEmpty();
+
+ List<DataFile> dataFiles = Lists.newArrayList();
+
+ for (int ordinal = 0; ordinal < 20_000; ordinal++) {
Review Comment:
I am usually good with package private. we have quite a bit `@VisibleForTesting` for case like that.
It can be tricky to update the tests if we ever change the `MIN_FILE_GROUP_SIZE` default value to some larger value like 20_000. then this test is not covering the intended case.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Parallelize manifest writing for many new files [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#discussion_r1750840473
##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -554,6 +562,84 @@ protected boolean cleanupAfterCommit() {
return true;
}
+ protected List<ManifestFile> writeDataManifests(List<DataFile> files, PartitionSpec spec) {
+ return writeDataManifests(files, null /* inherit data seq */, spec);
+ }
+
+ protected List<ManifestFile> writeDataManifests(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDataFileGroup(group, dataSeq, spec));
+ }
+
+ private List<ManifestFile> writeDataFileGroup(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ RollingManifestWriter<DataFile> writer = newRollingManifestWriter(spec);
+
+ try (RollingManifestWriter<DataFile> closableWriter = writer) {
+ if (dataSeq != null) {
+ files.forEach(file -> closableWriter.add(file, dataSeq));
+ } else {
+ files.forEach(closableWriter::add);
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write data manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ protected List<ManifestFile> writeDeleteManifests(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDeleteFileGroup(group, spec));
+ }
+
+ private List<ManifestFile> writeDeleteFileGroup(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ RollingManifestWriter<DeleteFile> writer = newRollingDeleteManifestWriter(spec);
+
+ try (RollingManifestWriter<DeleteFile> closableWriter = writer) {
+ for (DeleteFileHolder file : files) {
+ if (file.dataSequenceNumber() != null) {
+ closableWriter.add(file.deleteFile(), file.dataSequenceNumber());
+ } else {
+ closableWriter.add(file.deleteFile());
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write delete manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ private static <F> List<ManifestFile> writeManifests(
+ List<F> files, Function<List<F>, List<ManifestFile>> writeFunc) {
+ int groupSize = manifestFileGroupSize(ThreadPools.WORKER_THREAD_POOL_SIZE, files.size());
+ List<List<F>> groups = Lists.partition(files, groupSize);
+ Queue<ManifestFile> manifests = Queues.newConcurrentLinkedQueue();
+ Tasks.foreach(groups)
+ .stopOnFailure()
+ .throwFailureWhenFinished()
+ .executeWith(ThreadPools.getWorkerPool())
+ .run(group -> manifests.addAll(writeFunc.apply(group)));
+ return ImmutableList.copyOf(manifests);
+ }
+
+ /**
+ * Calculates how many files can be processed concurrently depending on the provided parallelism
+ * without creating too small manifests.
+ *
+ * @param parallelism the max number of concurrent writers
+ * @param fileCount the total number of files to be written
+ * @return the size of each file group, adjusted to balance workload across available writers
+ */
+ @VisibleForTesting
+ static int manifestFileGroupSize(int parallelism, int fileCount) {
+ int maxParallelism = IntMath.divide(fileCount, MIN_FILE_GROUP_SIZE, RoundingMode.HALF_UP);
+ int actualParallelism = Math.max(1, Math.min(parallelism, maxParallelism));
Review Comment:
I'm actually OK with the current naming of maxParallelism and actualParallelism. Do we want to just inline comment the handling of the cases where there's not a full manifest file group?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Parallelize manifest writing for many new files [iceberg]
Posted by "aokolnychyi (via GitHub)" <gi...@apache.org>.
aokolnychyi commented on code in PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#discussion_r1757644822
##########
core/src/test/java/org/apache/iceberg/TestSnapshotProducer.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+public class TestSnapshotProducer {
+ @Test
+ public void testManifestFileGroupSize() {
+ assertEquals(
+ 1_000,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 1_000 /* file count */),
+ "Must return file count when it is small");
+
+ assertEquals(
+ 10_000,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 10_000 /* file count */),
+ "Must return file count when it matches the min group size");
+
+ assertEquals(
+ 10_001,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 10_001 /* file count */),
+ "Must return file count when it is slightly above min group size");
+
+ assertEquals(
+ 12_500,
+ SnapshotProducer.manifestFileGroupSize(4 /* parallelism */, 12_500 /* file count */),
+ "Must return file count when remainder is < 50% of min group size");
Review Comment:
Updated.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Optimize writing metadata for many new files [iceberg]
Posted by "aokolnychyi (via GitHub)" <gi...@apache.org>.
aokolnychyi commented on code in PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#discussion_r1746178142
##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -654,4 +740,38 @@ private static void updateTotal(
}
}
}
+
+ protected static class DeleteFileHolder {
Review Comment:
Simply moved from `MergingSnapshotProducer`.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Optimize writing metadata for many new files [iceberg]
Posted by "aokolnychyi (via GitHub)" <gi...@apache.org>.
aokolnychyi commented on code in PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#discussion_r1747917302
##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -554,6 +562,84 @@ protected boolean cleanupAfterCommit() {
return true;
}
+ protected List<ManifestFile> writeDataManifests(List<DataFile> files, PartitionSpec spec) {
+ return writeDataManifests(files, null /* inherit data seq */, spec);
+ }
+
+ protected List<ManifestFile> writeDataManifests(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDataFileGroup(group, dataSeq, spec));
+ }
+
+ private List<ManifestFile> writeDataFileGroup(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ RollingManifestWriter<DataFile> writer = newRollingManifestWriter(spec);
+
+ try (RollingManifestWriter<DataFile> closableWriter = writer) {
+ if (dataSeq != null) {
+ files.forEach(file -> closableWriter.add(file, dataSeq));
+ } else {
+ files.forEach(closableWriter::add);
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write data manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ protected List<ManifestFile> writeDeleteManifests(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDeleteFileGroup(group, spec));
+ }
+
+ private List<ManifestFile> writeDeleteFileGroup(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ RollingManifestWriter<DeleteFile> writer = newRollingDeleteManifestWriter(spec);
+
+ try (RollingManifestWriter<DeleteFile> closableWriter = writer) {
+ for (DeleteFileHolder file : files) {
+ if (file.dataSequenceNumber() != null) {
+ closableWriter.add(file.deleteFile(), file.dataSequenceNumber());
+ } else {
+ closableWriter.add(file.deleteFile());
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write delete manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ private static <F> List<ManifestFile> writeManifests(
+ List<F> files, Function<List<F>, List<ManifestFile>> writeFunc) {
+ int groupSize = manifestFileGroupSize(ThreadPools.WORKER_THREAD_POOL_SIZE, files.size());
+ List<List<F>> groups = Lists.partition(files, groupSize);
+ Queue<ManifestFile> manifests = Queues.newConcurrentLinkedQueue();
+ Tasks.foreach(groups)
Review Comment:
I like that, I'll update.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Parallelize manifest writing for many new files [iceberg]
Posted by "aokolnychyi (via GitHub)" <gi...@apache.org>.
aokolnychyi commented on code in PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#discussion_r1757656126
##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -554,6 +562,84 @@ protected boolean cleanupAfterCommit() {
return true;
}
+ protected List<ManifestFile> writeDataManifests(List<DataFile> files, PartitionSpec spec) {
+ return writeDataManifests(files, null /* inherit data seq */, spec);
+ }
+
+ protected List<ManifestFile> writeDataManifests(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDataFileGroup(group, dataSeq, spec));
+ }
+
+ private List<ManifestFile> writeDataFileGroup(
+ List<DataFile> files, Long dataSeq, PartitionSpec spec) {
+ RollingManifestWriter<DataFile> writer = newRollingManifestWriter(spec);
+
+ try (RollingManifestWriter<DataFile> closableWriter = writer) {
+ if (dataSeq != null) {
+ files.forEach(file -> closableWriter.add(file, dataSeq));
+ } else {
+ files.forEach(closableWriter::add);
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write data manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ protected List<ManifestFile> writeDeleteManifests(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ return writeManifests(files, group -> writeDeleteFileGroup(group, spec));
+ }
+
+ private List<ManifestFile> writeDeleteFileGroup(
+ List<DeleteFileHolder> files, PartitionSpec spec) {
+ RollingManifestWriter<DeleteFile> writer = newRollingDeleteManifestWriter(spec);
+
+ try (RollingManifestWriter<DeleteFile> closableWriter = writer) {
+ for (DeleteFileHolder file : files) {
+ if (file.dataSequenceNumber() != null) {
+ closableWriter.add(file.deleteFile(), file.dataSequenceNumber());
+ } else {
+ closableWriter.add(file.deleteFile());
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeIOException(e, "Failed to write delete manifests");
+ }
+
+ return writer.toManifestFiles();
+ }
+
+ private static <F> List<ManifestFile> writeManifests(
+ List<F> files, Function<List<F>, List<ManifestFile>> writeFunc) {
+ int groupSize = manifestFileGroupSize(ThreadPools.WORKER_THREAD_POOL_SIZE, files.size());
+ List<List<F>> groups = Lists.partition(files, groupSize);
+ Queue<ManifestFile> manifests = Queues.newConcurrentLinkedQueue();
+ Tasks.foreach(groups)
+ .stopOnFailure()
+ .throwFailureWhenFinished()
+ .executeWith(ThreadPools.getWorkerPool())
+ .run(group -> manifests.addAll(writeFunc.apply(group)));
+ return ImmutableList.copyOf(manifests);
+ }
+
+ /**
+ * Calculates how many files can be processed concurrently depending on the provided parallelism
Review Comment:
We will have a follow-up PR to make `ManifestWriter` smarter and avoid creating a new file for a few entires. This should cover 1. That said, it shouldn't be a big deal even today as the parallelism is always limited.
10K is actually the min target number of files that can be handled by a single rolling manifest writer, not the max.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Parallelize manifest writing for many new files [iceberg]
Posted by "aokolnychyi (via GitHub)" <gi...@apache.org>.
aokolnychyi commented on code in PR #11086:
URL: https://github.com/apache/iceberg/pull/11086#discussion_r1757656744
##########
core/src/test/java/org/apache/iceberg/TestSnapshotProducer.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.junit.jupiter.api.Assertions.assertEquals;
Review Comment:
Oops, I keep forgetting. Fixed.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org