manishmalhotrawork commented on a change in pull request #666:
BaseRewriteManifests should keep different manifest for different partitionSpec
URL: https://github.com/apache/incubator-iceberg/pull/666#discussion_r357524009
##########
File path: core/src/main/java/org/apache/iceberg/BaseRewriteManifests.java
##########
@@ -312,33 +311,58 @@ long getManifestTargetSizeBytes() {
}
class WriterWrapper {
- private ManifestWriter writer;
-
- synchronized void addEntry(ManifestEntry entry) {
- if (writer == null) {
- writer = newWriter();
- } else if (writer.length() >= getManifestTargetSizeBytes()) {
- close();
- writer = newWriter();
+ private final Map<Integer, ManifestWriter> manifestWritersBySpecId =
Collections.synchronizedMap(new HashMap<>());
+
+ synchronized void addEntry(ManifestEntry entry, int partitionSpecId) {
+ ManifestWriter manifestWriter =
manifestWritersBySpecId.get(partitionSpecId);
+ if (manifestWriter == null) {
+ manifestWriter = addAndReturnNewWriter(partitionSpecId);
+ } else if (manifestWriter.length() >= getManifestTargetSizeBytes()) {
+ close(partitionSpecId);
+ manifestWriter = addAndReturnNewWriter(partitionSpecId);
}
- writer.existing(entry);
+ manifestWriter.existing(entry);
}
- private ManifestWriter newWriter() {
- return new ManifestWriter(spec,
manifestPath(manifestSuffix.getAndIncrement()), snapshotId());
+ private ManifestWriter addAndReturnNewWriter(int partitionSpecId) {
+ // create ManifestWriter with the correct partitionSpec
+ ManifestWriter manifestWriter = new
ManifestWriter(specsById.get(partitionSpecId),
+ manifestPath(manifestSuffix.getAndIncrement()),
+ snapshotId());
+ manifestWritersBySpecId.put(partitionSpecId, manifestWriter);
+ return manifestWriter;
}
- synchronized void close() {
- if (writer != null) {
+ synchronized void close(int partitionSpecId) {
+ if (manifestWritersBySpecId != null) {
try {
- writer.close();
- newManifests.add(writer.toManifestFile());
+ ManifestWriter manifestWriter =
manifestWritersBySpecId.get(partitionSpecId);
+ manifestWriter.close();
+ newManifests.add(manifestWriter.toManifestFile());
+ // remove so that we will not get the closed one again.
+ manifestWritersBySpecId.remove(partitionSpecId);
} catch (IOException x) {
throw new RuntimeIOException(x);
}
}
}
+ synchronized void close() {
+ if (manifestWritersBySpecId != null && manifestWritersBySpecId.size() >
0) {
+ // close all the manifestWriters belongs to writterWrapper
+ for (ManifestWriter manifestWriter : manifestWritersBySpecId.values())
{
+ try {
+ if (manifestWriter != null) {
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]