LiyunZhang10 opened a new pull request, #10258:
URL: https://github.com/apache/rocketmq/pull/10258

   ## Which Issue(s) This PR Fixes
   
   - Fixes #9328
   
   ## Brief Description
   
   When `ConfigManager.persist()` writes config data using `RandomAccessFile`, 
it does not truncate the file after writing. If the new content is shorter than 
the previous content (e.g., fewer consumer offsets after some groups are 
removed), stale trailing bytes from the old write remain in the file, producing 
invalid JSON like `{"new":"data"}old_garbage}`.
   
   After an unexpected power cut during a write, the file may contain a mix of 
partial new data and old trailing data, causing `decode()` to fail on restart. 
If the `.bak` file was also overwritten by the atomic move in the same persist 
cycle, the Broker starts with empty data structures, leading to 
`NullPointerException` as reported in #9328.
   
   ## Changes
   
   - Add `randomAccessFile.setLength(data.length)` after writing to truncate 
stale trailing data
   - Added unit test `testPersistTruncatesStaleData` to verify old trailing 
bytes are properly removed
   - Added tests for corrupted file fallback and first-time startup scenarios


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to