-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Refactor AppendDeletionFileMaintainer to separate bucketed and…
… unaware (#3950)
- Loading branch information
1 parent
037dc54
commit c4762cc
Showing
10 changed files
with
216 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
.../src/main/java/org/apache/paimon/deletionvectors/append/AppendDeletionFileMaintainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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.paimon.deletionvectors.append; | ||
|
||
import org.apache.paimon.data.BinaryRow; | ||
import org.apache.paimon.deletionvectors.DeletionVector; | ||
import org.apache.paimon.deletionvectors.DeletionVectorsMaintainer; | ||
import org.apache.paimon.index.IndexFileHandler; | ||
import org.apache.paimon.manifest.IndexManifestEntry; | ||
import org.apache.paimon.table.source.DeletionFile; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.apache.paimon.table.BucketMode.UNAWARE_BUCKET; | ||
|
||
/** | ||
* A maintainer to maintain deletion files for append table, the core methods: | ||
* | ||
* <ul> | ||
* <li>{@link #notifyDeletionFiles}: Mark the deletion of data files, create new deletion vectors. | ||
* <li>{@link #persist}: persist deletion files to commit. | ||
* </ul> | ||
*/ | ||
public interface AppendDeletionFileMaintainer { | ||
|
||
BinaryRow getPartition(); | ||
|
||
int getBucket(); | ||
|
||
void notifyDeletionFiles(String dataFile, DeletionVector deletionVector); | ||
|
||
List<IndexManifestEntry> persist(); | ||
|
||
static AppendDeletionFileMaintainer forBucketedAppend( | ||
IndexFileHandler indexFileHandler, | ||
@Nullable Long snapshotId, | ||
BinaryRow partition, | ||
int bucket) { | ||
// bucket should have only one deletion file, so here we should read old deletion vectors, | ||
// overwrite the entire deletion file of the bucket when writing deletes. | ||
DeletionVectorsMaintainer maintainer = | ||
new DeletionVectorsMaintainer.Factory(indexFileHandler) | ||
.createOrRestore(snapshotId, partition, bucket); | ||
return new BucketedAppendDeletionFileMaintainer(partition, bucket, maintainer); | ||
} | ||
|
||
static AppendDeletionFileMaintainer forUnawareAppend( | ||
IndexFileHandler indexFileHandler, @Nullable Long snapshotId, BinaryRow partition) { | ||
Map<String, DeletionFile> deletionFiles = | ||
indexFileHandler.scanDVIndex(snapshotId, partition, UNAWARE_BUCKET); | ||
return new UnawareAppendDeletionFileMaintainer(indexFileHandler, partition, deletionFiles); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...n/java/org/apache/paimon/deletionvectors/append/BucketedAppendDeletionFileMaintainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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.paimon.deletionvectors.append; | ||
|
||
import org.apache.paimon.data.BinaryRow; | ||
import org.apache.paimon.deletionvectors.DeletionVector; | ||
import org.apache.paimon.deletionvectors.DeletionVectorsMaintainer; | ||
import org.apache.paimon.manifest.FileKind; | ||
import org.apache.paimon.manifest.IndexManifestEntry; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** A {@link AppendDeletionFileMaintainer} of bucketed append table. */ | ||
public class BucketedAppendDeletionFileMaintainer implements AppendDeletionFileMaintainer { | ||
|
||
private final BinaryRow partition; | ||
private final int bucket; | ||
private final DeletionVectorsMaintainer maintainer; | ||
|
||
BucketedAppendDeletionFileMaintainer( | ||
BinaryRow partition, int bucket, DeletionVectorsMaintainer maintainer) { | ||
this.partition = partition; | ||
this.bucket = bucket; | ||
this.maintainer = maintainer; | ||
} | ||
|
||
@Override | ||
public BinaryRow getPartition() { | ||
return this.partition; | ||
} | ||
|
||
@Override | ||
public int getBucket() { | ||
return this.bucket; | ||
} | ||
|
||
@Override | ||
public void notifyDeletionFiles(String dataFile, DeletionVector deletionVector) { | ||
maintainer.mergeNewDeletion(dataFile, deletionVector); | ||
} | ||
|
||
@Override | ||
public List<IndexManifestEntry> persist() { | ||
return maintainer.writeDeletionVectorsIndex().stream() | ||
.map(fileMeta -> new IndexManifestEntry(FileKind.ADD, partition, bucket, fileMeta)) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.