[core] Write changelog files atomically and skip empty changelog files - #10254
Open
LuciferYang wants to merge 2 commits into
Open
LuciferYang wants to merge 2 commits into
LuciferYang wants to merge 2 commits into
Conversation
The empty-file branch logged a warning but still fell through to Changelog.fromJson, which throws UncheckedIOException on the empty string and escaped the IOException-only catch, killing the whole enumeration — and with it the orphan files clean — over one torn or truncated changelog file. Skip the file after the warning, as the branch intended. Assisted-by: GLM-5.3
commitChangelog wrote the JSON directly to the target file with overwrite, so a crash midway left readers with an empty or partial changelog file, which safelyGetAllChangelogs then had to tolerate. Write through a temp file and rename like snapshot and schema commits, and treat an already-existing file as an idempotent retry only when its content matches. Assisted-by: GLM-5.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
ChangelogManagerhad two related weaknesses around changelog metadata files.commitChangelogwrote the changelog JSON withfileIO.writeFile(path, json, true), a direct overwrite of the target path. A crash during that write leaves an empty or partial file at the canonical changelog path, while snapshots and hint files are already committed atomically. This changescommitChangelogtofileIO.tryToWriteAtomic, which writes a temp file and renames it into place. When the atomic write returns false because the target already exists, the same id must carry the same content, so the commit is treated as idempotent and only a genuinely different content raises an error.safelyGetAllChangelogslogged "Changelog file is empty" but then still calledChangelog.fromJsonon the empty string. That parse throwsUncheckedIOException, which the consumer'scatch (IOException)does not catch, so it propagates and aborts the whole enumeration. The only caller,OrphanFilesClean, then fails entirely because of one empty or torn file. This skips empty changelog files so the listing stays resilient, matching the intent already expressed by the method name and its existingFileNotFoundExceptionhandling.This closes #10252.
Tests
Added
ChangelogManagerTestwith two cases.testCommitChangelogWritesAtomicallyverifies the target path is never opened for a direct overwrite and that repeating a commit of the same id is idempotent while a different content for the same id fails.testSafelyGetAllChangelogsSkipsEmptyFilewrites one valid and one empty changelog file and asserts the empty one is skipped.API and Format
No.
Documentation
No.