Skip to content

Commit d31adc8

Browse files
authored
[core] Validate fast-forward from the current branch (#5413)
1 parent 72ab0e6 commit d31adc8

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

paimon-core/src/main/java/org/apache/paimon/utils/BranchManager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static void validateBranch(String branchName) {
7777
branchName);
7878
}
7979

80-
static void fastForwardValidate(String branchName) {
80+
static void fastForwardValidate(String branchName, String currentBranch) {
8181
checkArgument(
8282
!branchName.equals(DEFAULT_MAIN_BRANCH),
8383
"Branch name '%s' do not use in fast-forward.",
@@ -86,5 +86,9 @@ static void fastForwardValidate(String branchName) {
8686
!StringUtils.isNullOrWhitespaceOnly(branchName),
8787
"Branch name '%s' is blank.",
8888
branchName);
89+
checkArgument(
90+
!branchName.equals(currentBranch),
91+
"Fast-forward from the current branch '%s' is not allowed.",
92+
branchName);
8993
}
9094
}

paimon-core/src/main/java/org/apache/paimon/utils/CatalogBranchManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ public void dropBranch(String branchName) {
8989
public void fastForward(String branchName) {
9090
executePost(
9191
catalog -> {
92-
BranchManager.fastForwardValidate(branchName);
92+
BranchManager.fastForwardValidate(
93+
branchName, identifier.getBranchNameOrDefault());
9394
catalog.fastForward(identifier, branchName);
9495
});
9596
}

paimon-core/src/main/java/org/apache/paimon/utils/FileSystemBranchManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private boolean fileExists(Path path) {
138138

139139
@Override
140140
public void fastForward(String branchName) {
141-
BranchManager.fastForwardValidate(branchName);
141+
BranchManager.fastForwardValidate(branchName, snapshotManager.branch());
142142
checkArgument(branchExists(branchName), "Branch name '%s' doesn't exist.", branchName);
143143

144144
Long earliestSnapshotId = snapshotManager.copyWithBranch(branchName).earliestSnapshotId();

paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/BranchSqlITCase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ public void testBranchFastForward() throws Exception {
280280
.containsExactlyInAnyOrder("+I[1, 10, hunter]", "+I[2, 10, hunterX]");
281281

282282
checkSnapshots(snapshotManager, 1, 2);
283+
284+
sql("alter table T set ('branch'='test')");
285+
286+
assertThatThrownBy(() -> sql("CALL sys.fast_forward('default.T', 'test')"))
287+
.hasMessageContaining(
288+
"Fast-forward from the current branch 'test' is not allowed.");
283289
}
284290

285291
@Test

0 commit comments

Comments
 (0)