Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sunxiaojian committed Feb 26, 2024
1 parent b060e12 commit 080cfaa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private boolean cleanMainBranch(TableBranch fromBranch) throws IOException {
Snapshot fromSnapshot = snapshotManager.snapshot(fromBranch.getCreatedFromSnapshot());
while (snapshots.hasNext()) {
Snapshot snapshot = snapshots.next();
if (snapshot.timeMillis() >= fromSnapshot.timeMillis()) {
if (snapshot.id() >= fromSnapshot.id()) {
fileIO.delete(snapshotManager.snapshotPath(snapshot.id()), true);
}
}
Expand Down Expand Up @@ -291,7 +291,7 @@ private void calculateCopyMainBranchToTargetBranch(String branchName) throws IOE
// If it already exists, skip it directly
continue;
}
if (snapshot.timeMillis() < fromSnapshot.timeMillis()) {
if (snapshot.id() < fromSnapshot.id()) {
fileIO.copyFileUtf8(
snapshotManager.snapshotPath(snapshot.id()),
snapshotManager.branchSnapshotPath(branchName, snapshot.id()));
Expand All @@ -307,7 +307,7 @@ private void calculateCopyMainBranchToTargetBranch(String branchName) throws IOE
// If it already exists, skip it directly
continue;
}
if (tableSchema.timeMillis() < fromSnapshot.timeMillis()) {
if (tableSchema.id() < fromSnapshot.schemaId()) {
fileIO.copyFileUtf8(
schemaManager.toSchemaPath(schemaId),
schemaManager.branchSchemaPath(branchName, schemaId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public Iterator<Snapshot> snapshots() throws IOException {

public Iterator<Snapshot> snapshotsWithBranch(String branchName) throws IOException {
return listVersionedFiles(fileIO, snapshotDirByBranch(branchName), SNAPSHOT_PREFIX)
.map(this::snapshot)
.map(snapshotId -> snapshot(branchName, snapshotId))
.sorted(Comparator.comparingLong(Snapshot::id))
.iterator();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.paimon.types.DataTypes;
import org.apache.paimon.types.RowType;
import org.apache.paimon.utils.BranchManager;
import org.apache.paimon.utils.SnapshotManager;
import org.apache.paimon.utils.TagManager;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -128,7 +129,14 @@ void testMergeBranchToTargetBranch() throws Exception {
String.format(
"CALL sys.merge_branch('%s.%s', 'merge_branch_name')",
database, tableName));
assertThat(branchManager.branchExists("merge_branch_name")).isFalse();
assertThat(branchManager.branchExists("merge_branch_name")).isTrue();
assertThat(tagManager.tagExists("tag3")).isFalse();

// Check snapshot
SnapshotManager snapshotManager = table.snapshotManager();
assertThat(snapshotManager.snapshotExists(3)).isFalse();
assertThat(snapshotManager.snapshotExists(4)).isFalse();
assertThat(snapshotManager.snapshotExists(5)).isFalse();
}

@Test
Expand Down

0 comments on commit 080cfaa

Please sign in to comment.