kakoc commented on issue #11460:
URL: https://github.com/apache/rocketmq/issues/11460#issuecomment-7244847586

   A broker in controller mode hits this parse after a power cut, and there is 
no `.bak` to fall back to, so both slaves of a replica group never start again.
   
   - **What happens:** after a power cut of the whole machine, broker0 and 
broker1, the two slaves of a three-broker group, exit at every start with the 
stack below. The group runs on its master alone.
   - **The empty file:** `epochFileCheckpoint` of both slaves is 0 bytes, and 
neither has a `.bak`. Each was written 17 s before the cut, when the controller 
made the node a slave.
   - **Why the file is empty:** `CheckpointFile.write` 
(`common/src/main/java/org/apache/rocketmq/common/utils/CheckpointFile.java:94`)
 calls `MixAll.string2File`, which copies the old content to `.bak` and then 
writes the file in place with a `FileOutputStream` 
(`IOTinyUtils.writeStringToFile`). Neither file nor their folder is synced, so 
the new size of 0 reached the disk before the data. #5905 and #7729 saw config 
files broken the same way after a forced restart.
   - **Also one broker:** a power loss of one broker alone leaves the same 
empty file and the same exit at its restart.
   - **Versions:** seen on 5.5.0 (`apache/rocketmq:5.5.0`), and `develop` 
(`19352a246`) has the same code.
   
   ```text
   java.lang.NumberFormatException: null
        at java.lang.Integer.parseInt(Integer.java:542)
        at java.lang.Integer.parseInt(Integer.java:615)
        at 
org.apache.rocketmq.common.utils.CheckpointFile.read(CheckpointFile.java:107)
        at 
org.apache.rocketmq.common.utils.CheckpointFile.read(CheckpointFile.java:146)
        at 
org.apache.rocketmq.store.ha.autoswitch.EpochFileCache.initCacheFromFile(EpochFileCache.java:59)
        at 
org.apache.rocketmq.store.ha.autoswitch.AutoSwitchHAService.init(AutoSwitchHAService.java:84)
        at 
org.apache.rocketmq.store.DefaultMessageStore.start(DefaultMessageStore.java:426)
   ```
   
   **How it was found**
   Found autonomously by [hydo](https://github.com/kakoc/hydo), an open-source 
tool that runs the whole system in a VM where every run repeats exactly. It 
looks for bugs on its own and can replay anything it finds.
   - a NameServer with the controller embedded and one replica group of three 
brokers (`allAckInSyncStateSet`, `SYNC_FLUSH`) in one VM, each node's store on 
a file system of its own
   - two blind explorations of 66 schedules reached it at 8 power cuts of the 
whole VM and at 11 power losses of one broker
   - to reproduce it (a Linux machine with an Intel CPU, where the installer 
builds and loads hydo's kernel module with sudo; `docs/INSTALL.md` in the hydo 
repository has the other ways to install; and Go 1.27.3 for the client):
     ```sh
     curl -LO 
https://github.com/kakoc/hydo/releases/download/v0.8.0/hydo-linux-0.8.0.tar.gz
     curl -LO https://github.com/kakoc/hydo/releases/download/v0.8.0/SHA256SUMS
     sha256sum -c --ignore-missing SHA256SUMS
     tar xzf hydo-linux-0.8.0.tar.gz && ./hydo-linux-0.8.0/install.sh
     export PATH="$HOME/.hydo/bin:$PATH"
     git clone https://github.com/kakoc/hydo && cd hydo && git checkout v0.8.0
     cd hydo/onboard/examples/rocketmq && sh build.sh
     cd hydo && sh fetch-images.sh && hydo build hydo.yaml
     hydo run "disk=cut | run C=20"
     # -> VIOLATION service cannot recover (committed data unrecoverable) 
(broker0), fp=b5252e4bc9b73a2c
     #    <run dir>/logs/broker0.log ends with the stack above
     hydo run "disk=none | run"
     # -> OK, fp=b40afc5cabb53082
     ```
     the same fingerprints on every run
   


-- 
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