From a795ca32b64efef55ee1f572773313a5500872c2 Mon Sep 17 00:00:00 2001 From: yantian Date: Mon, 6 Jan 2025 11:03:16 +0800 Subject: [PATCH 1/2] overwrite is true when commit change log --- .../src/main/java/org/apache/paimon/utils/SnapshotManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paimon-core/src/main/java/org/apache/paimon/utils/SnapshotManager.java b/paimon-core/src/main/java/org/apache/paimon/utils/SnapshotManager.java index 49da83bfe48a..ae70d7aec5d1 100644 --- a/paimon-core/src/main/java/org/apache/paimon/utils/SnapshotManager.java +++ b/paimon-core/src/main/java/org/apache/paimon/utils/SnapshotManager.java @@ -745,7 +745,7 @@ public List findSnapshotsForIdentifiers( } public void commitChangelog(Changelog changelog, long id) throws IOException { - fileIO.writeFile(longLivedChangelogPath(id), changelog.toJson(), false); + fileIO.writeFile(longLivedChangelogPath(id), changelog.toJson(), true); } /** From 8f914697037a0fc5544addb8773e74f1c132803c Mon Sep 17 00:00:00 2001 From: yantian Date: Mon, 6 Jan 2025 14:52:11 +0800 Subject: [PATCH 2/2] add ut --- .../org/apache/paimon/utils/SnapshotManagerTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/paimon-core/src/test/java/org/apache/paimon/utils/SnapshotManagerTest.java b/paimon-core/src/test/java/org/apache/paimon/utils/SnapshotManagerTest.java index 26480cf411bb..e828a0c90a9d 100644 --- a/paimon-core/src/test/java/org/apache/paimon/utils/SnapshotManagerTest.java +++ b/paimon-core/src/test/java/org/apache/paimon/utils/SnapshotManagerTest.java @@ -39,6 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; /** Tests for {@link SnapshotManager}. */ public class SnapshotManagerTest { @@ -398,4 +399,15 @@ public void testLongLivedChangelog() throws Exception { Assertions.assertThat(snapshotManager.latestSnapshotId()).isEqualTo(10); Assertions.assertThat(snapshotManager.changelog(1)).isNotNull(); } + + @Test + public void testCommitChangelogWhenSameChangelogCommitTwice() throws IOException { + FileIO localFileIO = LocalFileIO.create(); + SnapshotManager snapshotManager = + new SnapshotManager(localFileIO, new Path(tempDir.toString())); + long id = 1L; + Changelog changelog = createChangelogWithMillis(id, 1L); + snapshotManager.commitChangelog(changelog, id); + assertDoesNotThrow(() -> snapshotManager.commitChangelog(changelog, id)); + } }