This is an automated email from the ASF dual-hosted git repository.

RongtongJin pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git


The following commit(s) were added to refs/heads/develop by this push:
     new f3386107cb [ISSUE #11452] fix(common): name the file in the checkpoint 
crc mismatch message
f3386107cb is described below

commit f3386107cba84dc56eca6cc6a0c2e5975fd2aff7
Author: bai mengxuan <[email protected]>
AuthorDate: Mon Oct 19 17:43:43 2026 +0800

    [ISSUE #11452] fix(common): name the file in the checkpoint crc mismatch 
message
    
    CheckpointFile.read builds the IOException for a crc32 mismatch with a 
"file=%s"
    label but passes expectedCrc32 into it, so an operator who opens a corrupted
    checkpoint reads e.g. "file=823222925" - a checksum where the path that 
failed to
    load is expected - and the expected value itself is never named.
    
    Pass the path that was read and label the expected checksum, and pin it 
with the
    case that corrupts both the checkpoint and the .bak fallback read() falls 
back to.
---
 .../rocketmq/common/utils/CheckpointFile.java      |  2 +-
 .../remoting/protocol/CheckpointFileTest.java      | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git 
a/common/src/main/java/org/apache/rocketmq/common/utils/CheckpointFile.java 
b/common/src/main/java/org/apache/rocketmq/common/utils/CheckpointFile.java
index 1cb85d05ee..8f51d27465 100644
--- a/common/src/main/java/org/apache/rocketmq/common/utils/CheckpointFile.java
+++ b/common/src/main/java/org/apache/rocketmq/common/utils/CheckpointFile.java
@@ -130,7 +130,7 @@ public class CheckpointFile<T> {
 
                 if (NOT_CHECK_CRC_MAGIC_CODE != expectedCrc32 && truthCrc32 != 
expectedCrc32) {
                     final String err = String.format(
-                        "Entries crc32 not match, file=%s, truth=%s", 
expectedCrc32, truthCrc32);
+                        "Entries crc32 not match, file=%s, expected=%s, 
truth=%s", filePath, expectedCrc32, truthCrc32);
                     throw new IOException(err);
                 }
                 return result;
diff --git 
a/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/CheckpointFileTest.java
 
b/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/CheckpointFileTest.java
index 658f59e480..1f54011c1c 100644
--- 
a/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/CheckpointFileTest.java
+++ 
b/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/CheckpointFileTest.java
@@ -19,6 +19,8 @@ package org.apache.rocketmq.remoting.protocol;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
@@ -75,6 +77,26 @@ public class CheckpointFileTest {
         UtilAll.deleteFile(new File(FILE_PATH + ".bak"));
     }
 
+    @Test
+    public void testCrcMismatchReportsTheFileAndTheExpectedCrc() throws 
IOException {
+        String content = new String(Files.readAllBytes(Paths.get(FILE_PATH)), 
StandardCharsets.UTF_8);
+        String separator = System.lineSeparator();
+        String[] parts = content.split(separator, 3);
+        long wrongCrc = Long.parseLong(parts[1]) + 1;
+        String corrupted = parts[0] + separator + wrongCrc + separator + 
parts[2];
+        Files.write(Paths.get(FILE_PATH), 
corrupted.getBytes(StandardCharsets.UTF_8));
+        Files.write(Paths.get(FILE_PATH + ".bak"), 
corrupted.getBytes(StandardCharsets.UTF_8));
+        try {
+            checkpoint.read();
+            Assert.fail("a mismatched crc32 must fail the read");
+        } catch (IOException e) {
+            String message = e.getMessage();
+            Assert.assertTrue(message, message.contains(FILE_PATH));
+            Assert.assertTrue(message, message.contains("expected=" + 
wrongCrc));
+            Assert.assertTrue(message, message.contains("truth="));
+        }
+    }
+
     @Test
     public void testNormalWriteAndRead() throws IOException {
         List<EpochEntry> listFromFile = checkpoint.read();

Reply via email to