Skip to content
Merged
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 @@ -82,7 +82,6 @@ public abstract class FileDeletionBase<T extends Snapshot> {
protected final Map<BinaryRow, Set<Integer>> deletionBuckets;

private final Executor fileExecutor;
private final int fileOperationParallelism;
@Nullable private final Integer manifestReadParallelism;

protected boolean changelogDecoupled;
Expand Down Expand Up @@ -112,10 +111,6 @@ public FileDeletionBase(
this.cleanEmptyDirectories = cleanEmptyDirectories;
this.deletionBuckets = new ConcurrentHashMap<>();
this.fileExecutor = FileOperationThreadPool.getExecutorService(fileOperationThreadNum);
this.fileOperationParallelism =
fileOperationThreadNum > 0
? fileOperationThreadNum
: Runtime.getRuntime().availableProcessors();
this.manifestReadParallelism = manifestReadParallelism;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ public ExpireSnapshots newExpireSnapshots() {
snapshotManager(),
changelogManager(),
store().newSnapshotDeletion(),
store().newTagManager());
store().newTagManager(),
store().options().scanManifestParallelism());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UncheckedIOException;
Expand Down Expand Up @@ -68,6 +70,7 @@ public class ExpireSnapshotsImpl implements ExpireSnapshots {
private final SnapshotDeletion snapshotDeletion;
private final Executor fileExecutor;
private final TagManager tagManager;
private final int snapshotExpireBatchSize;

private ExpireConfig expireConfig;
private Supplier<Long> currentTimeMillis = System::currentTimeMillis;
Expand All @@ -76,7 +79,8 @@ public ExpireSnapshotsImpl(
SnapshotManager snapshotManager,
ChangelogManager changelogManager,
SnapshotDeletion snapshotDeletion,
TagManager tagManager) {
TagManager tagManager,
@Nullable Integer scanManifestParallelism) {
this.snapshotManager = snapshotManager;
this.changelogManager = changelogManager;
this.consumerManager =
Expand All @@ -88,6 +92,10 @@ public ExpireSnapshotsImpl(
this.tagManager = tagManager;
this.expireConfig = ExpireConfig.builder().build();
this.fileExecutor = snapshotDeletion.fileExecutor();
this.snapshotExpireBatchSize =
scanManifestParallelism == null || scanManifestParallelism <= 0
? Runtime.getRuntime().availableProcessors()
: scanManifestParallelism;
}

@VisibleForTesting
Expand Down Expand Up @@ -207,12 +215,11 @@ private int innerExpireUntil(long earliestId, long endExclusiveId)
// delete merge tree files
// deleted merge tree files in a snapshot are not used by the next snapshot, so the range of
// id should be (beginInclusiveId, endExclusiveId]
snapshotDeletion.cleanDataFiles(
collectDataFilesToDelete(snapshotsIncludingEnd, taggedSnapshots, beginInclusiveId));
cleanDataFiles(snapshotsIncludingEnd, taggedSnapshots, beginInclusiveId);

// delete changelog files
if (!expireConfig.isChangelogDecoupled()) {
snapshotDeletion.cleanDataFiles(collectChangelogFilesToDelete(snapshotsExcludingEnd));
cleanChangelogFiles(snapshotsExcludingEnd);
}

// data files and changelog files in bucket directories has been deleted
Expand Down Expand Up @@ -262,7 +269,7 @@ private int innerExpireUntil(long earliestId, long endExclusiveId)
return snapshotsExcludingEnd.size();
}

private Collection<Path> collectDataFilesToDelete(
private void cleanDataFiles(
List<Snapshot> snapshotsIncludingEnd,
List<Snapshot> taggedSnapshots,
long beginInclusiveId)
Expand All @@ -288,6 +295,7 @@ private Collection<Path> collectDataFilesToDelete(
collectTagSkippers(tags.values());
Predicate<ExpireFileEntry> deleteAll = entry -> false;
List<CompletableFuture<List<Path>>> futures = new ArrayList<>();
int plannedSnapshots = 0;
for (Snapshot snapshot : snapshotsIncludingEnd) {
long id = snapshot.id();
if (id == beginInclusiveId) {
Expand All @@ -308,15 +316,18 @@ private Collection<Path> collectDataFilesToDelete(
id);
continue;
}

futures.add(
CompletableFuture.supplyAsync(
() ->
snapshotDeletion.planDeletedInDeltaManifest(
snapshot, skipper.get()),
fileExecutor));
if (++plannedSnapshots >= snapshotExpireBatchSize) {
cleanBatch(futures);
plannedSnapshots = 0;
}
}
return flatten(getAll(futures));
cleanBatch(futures);
}

private Map<Long, Optional<Predicate<ExpireFileEntry>>> collectTagSkippers(
Expand Down Expand Up @@ -350,9 +361,10 @@ private Map<Long, Optional<Predicate<ExpireFileEntry>>> collectTagSkippers(
return skippers;
}

private Collection<Path> collectChangelogFilesToDelete(List<Snapshot> snapshots)
private void cleanChangelogFiles(List<Snapshot> snapshots)
throws ExecutionException, InterruptedException {
List<CompletableFuture<List<Path>>> futures = new ArrayList<>();
int plannedSnapshots = 0;
for (Snapshot snapshot : snapshots) {
if (LOG.isDebugEnabled()) {
LOG.debug("Ready to delete changelog files from snapshot #{}", snapshot.id());
Expand All @@ -362,9 +374,20 @@ private Collection<Path> collectChangelogFilesToDelete(List<Snapshot> snapshots)
CompletableFuture.supplyAsync(
() -> snapshotDeletion.planAddedInChangelogManifest(snapshot),
fileExecutor));
if (++plannedSnapshots >= snapshotExpireBatchSize) {
cleanBatch(futures);
plannedSnapshots = 0;
}
}
}
return flatten(getAll(futures));
cleanBatch(futures);
}

private void cleanBatch(List<CompletableFuture<List<Path>>> futures)
throws ExecutionException, InterruptedException {
Collection<Path> paths = flatten(getAll(futures));
futures.clear();
snapshotDeletion.cleanDataFiles(paths);
}

private Collection<Runnable> collectManifestDeletionTasks(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ public ExpireSnapshots newExpire(int numRetainedMin, int numRetainedMax, long mi
snapshotManager(),
changelogManager(),
newSnapshotDeletion(),
new TagManager(fileIO, options.path()))
new TagManager(fileIO, options.path()),
null)
.config(
ExpireConfig.builder()
.snapshotRetainMax(numRetainedMax)
Expand All @@ -189,7 +190,8 @@ public ExpireSnapshots newExpire(ExpireConfig expireConfig) {
snapshotManager(),
changelogManager(),
newSnapshotDeletion(),
new TagManager(fileIO, options.path()))
new TagManager(fileIO, options.path()),
null)
.config(expireConfig);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,8 @@ public void testExpireCollectsSnapshotsConcurrently() throws Exception {
blockingSnapshotManager,
changelogManager,
store.newSnapshotDeletion(),
store.newTagManager());
store.newTagManager(),
store.options().scanManifestParallelism());

expire.expireUntil(1, latestSnapshotId);

Expand Down Expand Up @@ -961,7 +962,8 @@ public void testExpireWithTimeDoesNotReadProtectedRange() throws Exception {
failingSnapshotManager,
changelogManager,
store.newSnapshotDeletion(),
store.newTagManager());
store.newTagManager(),
store.options().scanManifestParallelism());
expire.config(config);
expire.setCurrentTimeMillis(() -> 6000L);

Expand Down Expand Up @@ -1217,7 +1219,11 @@ private ExpireSnapshotsImpl newExpireWithSnapshotDeletion(
SnapshotManager snapshotManager,
SnapshotDeletion snapshotDeletion) {
return new ExpireSnapshotsImpl(
snapshotManager, store.changelogManager(), snapshotDeletion, store.newTagManager());
snapshotManager,
store.changelogManager(),
snapshotDeletion,
store.newTagManager(),
store.options().scanManifestParallelism());
}

private void rewriteSnapshotTime(long snapshotId, long newTimeMillis) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,11 @@ public void testExpireWithDeletingTags() throws Exception {
// result: exist A & B (because of tag2)
ExpireSnapshots expireSnapshots =
new ExpireSnapshotsImpl(
snapshotManager, changelogManager, store.newSnapshotDeletion(), tagManager);
snapshotManager,
changelogManager,
store.newSnapshotDeletion(),
tagManager,
store.options().scanManifestParallelism());
expireSnapshots
.config(
ExpireConfig.builder()
Expand Down Expand Up @@ -755,7 +759,11 @@ public void testDataFileSkippingSetException() throws Exception {

ExpireSnapshots expireSnapshots =
new ExpireSnapshotsImpl(
snapshotManager, changelogManager, snapshotDeletion, tagManager);
snapshotManager,
changelogManager,
snapshotDeletion,
tagManager,
store.options().scanManifestParallelism());
snapshotDeletion.readMergedDataFilesThrowException = true;
expireSnapshots
.config(
Expand Down Expand Up @@ -820,7 +828,11 @@ public void testManifestFileSkippingSetException() throws Exception {
store.options().scanManifestParallelism());
ExpireSnapshots expireSnapshots =
new ExpireSnapshotsImpl(
snapshotManager, changelogManager, snapshotDeletion, tagManager);
snapshotManager,
changelogManager,
snapshotDeletion,
tagManager,
store.options().scanManifestParallelism());
snapshotDeletion.manifestSkippingSetThrowException = true;
expireSnapshots
.config(
Expand Down
Loading