Skip to content

Commit

Permalink
[core] Rename findOverlappedSnapshots to findSkippingTags
Browse files Browse the repository at this point in the history
  • Loading branch information
JingsongLi committed Oct 15, 2024
1 parent 6f033f0 commit a0eeee0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import java.util.Set;
import java.util.function.Predicate;

import static org.apache.paimon.table.ExpireSnapshotsImpl.findSkippingTags;

/** Cleanup the changelog in changelog directory. */
public class ExpireChangelogImpl implements ExpireSnapshots {

Expand Down Expand Up @@ -137,8 +139,7 @@ public int expireUntil(long earliestId, long endExclusiveId) {
List<Snapshot> taggedSnapshots = tagManager.taggedSnapshots();

List<Snapshot> skippingSnapshots =
SnapshotManager.findOverlappedSnapshots(
taggedSnapshots, earliestId, endExclusiveId);
findSkippingTags(taggedSnapshots, earliestId, endExclusiveId);
skippingSnapshots.add(snapshotManager.changelog(endExclusiveId));
Set<String> manifestSkippSet = changelogDeletion.manifestSkippingSet(skippingSnapshots);
for (long id = earliestId; id < endExclusiveId; id++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;

import static org.apache.paimon.utils.SnapshotManager.findPreviousOrEqualSnapshot;
import static org.apache.paimon.utils.SnapshotManager.findPreviousSnapshot;

/** An implementation for {@link ExpireSnapshots}. */
public class ExpireSnapshotsImpl implements ExpireSnapshots {

Expand Down Expand Up @@ -212,8 +216,7 @@ public int expireUntil(long earliestId, long endExclusiveId) {

// delete manifests and indexFiles
List<Snapshot> skippingSnapshots =
SnapshotManager.findOverlappedSnapshots(
taggedSnapshots, beginInclusiveId, endExclusiveId);
findSkippingTags(taggedSnapshots, beginInclusiveId, endExclusiveId);

try {
skippingSnapshots.add(snapshotManager.tryGetSnapshot(endExclusiveId));
Expand Down Expand Up @@ -277,4 +280,18 @@ private void writeEarliestHint(long earliest) {
public SnapshotDeletion snapshotDeletion() {
return snapshotDeletion;
}

/** Find the skipping tags in sortedTags for range of [beginInclusive, endExclusive). */
public static List<Snapshot> findSkippingTags(
List<Snapshot> sortedTags, long beginInclusive, long endExclusive) {
List<Snapshot> overlappedSnapshots = new ArrayList<>();
int right = findPreviousSnapshot(sortedTags, endExclusive);
if (right >= 0) {
int left = Math.max(findPreviousOrEqualSnapshot(sortedTags, beginInclusive), 0);
for (int i = left; i <= right; i++) {
overlappedSnapshots.add(sortedTags.get(i));
}
}
return overlappedSnapshots;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -723,23 +723,6 @@ private Long findByListFiles(BinaryOperator<Long> reducer, Path dir, String pref
return listVersionedFiles(fileIO, dir, prefix).reduce(reducer).orElse(null);
}

/**
* Find the overlapping snapshots between sortedSnapshots and range of [beginInclusive,
* endExclusive).
*/
public static List<Snapshot> findOverlappedSnapshots(
List<Snapshot> sortedSnapshots, long beginInclusive, long endExclusive) {
List<Snapshot> overlappedSnapshots = new ArrayList<>();
int right = findPreviousSnapshot(sortedSnapshots, endExclusive);
if (right >= 0) {
int left = Math.max(findPreviousOrEqualSnapshot(sortedSnapshots, beginInclusive), 0);
for (int i = left; i <= right; i++) {
overlappedSnapshots.add(sortedSnapshots.get(i));
}
}
return overlappedSnapshots;
}

public static int findPreviousSnapshot(List<Snapshot> sortedSnapshots, long targetSnapshotId) {
for (int i = sortedSnapshots.size() - 1; i >= 0; i--) {
if (sortedSnapshots.get(i).id() < targetSnapshotId) {
Expand All @@ -749,7 +732,7 @@ public static int findPreviousSnapshot(List<Snapshot> sortedSnapshots, long targ
return -1;
}

private static int findPreviousOrEqualSnapshot(
public static int findPreviousOrEqualSnapshot(
List<Snapshot> sortedSnapshots, long targetSnapshotId) {
for (int i = sortedSnapshots.size() - 1; i >= 0; i--) {
if (sortedSnapshots.get(i).id() <= targetSnapshotId) {
Expand Down

0 comments on commit a0eeee0

Please sign in to comment.