tuantran0910 opened a new issue, #71076:
URL: https://github.com/apache/doris/issues/71076

   ### Search before asking
   
   - [x] I had searched in the 
[issues](https://github.com/apache/doris/issues?q=is%3Aissue) and found no 
similar issues.
   
   ### Version
   
   4.1.5 (`doris-4.1.5-release`). The same code is on `master` (e46677d800), 
`branch-4.2`, `branch-4.1`, `branch-4.0` and `branch-3.1`.
   
   ### What's Wrong?
   
   A follower FE was unable to start after its host was powered off. Every 
restart failed while loading the newest image:
   
   ```
   WARN [MetaFooter.read():66] Image file .../doris-meta/image/image.137503402 
format mismatch. Expected magic number is [67, 79, 82, 49], actual is [...]
   ERROR java.lang.IllegalStateException: 3199351665075383397 vs. 1795745247426
        at 
com.google.common.base.Preconditions.checkState(Preconditions.java:515)
        at org.apache.doris.persist.meta.MetaReader.read(MetaReader.java:133)
        at org.apache.doris.catalog.Env.loadImage(Env.java:2316)
        at org.apache.doris.catalog.Env.initialize(Env.java:1199)
        at org.apache.doris.cloud.catalog.CloudEnv.initialize(CloudEnv.java:164)
        at org.apache.doris.DorisFE.start(DorisFE.java:248)
        at org.apache.doris.DorisFE.main(DorisFE.java:117)
   ```
   
   Comparing the image with the master's copy of the same version:
   
   | | master | follower |
   |---|---|---|
   | `image.137503402` size | 227,346,286 bytes, ends with the `COR1` footer | 
223,129,600 bytes (54,475 × 4 KiB) |
   | MD5 of the first 223,129,600 bytes | `e6dd085f9913814f1b93a668af239df0` | 
`e6dd085f9913814f1b93a668af239df0` |
   | previous `image.137500571` | `e1b2f4af9931a2783706686b4749b6db` | 
`e1b2f4af9931a2783706686b4749b6db` (intact) |
   
   The follower's file is an exact prefix of the master's, cut at a page 
boundary: the last ~4 MiB never reached the disk.
   
   Timeline (UTC):
   
   - 15:10:24 the master finishes the checkpoint `image.137503402` and pushes 
it (`/put`) to the follower.
   - 15:11:06 the follower finishes downloading the image and renames 
`image.137503402.part` to `image.137503402`.
   - 15:11:09 the master logs the push as successful and deletes old journals.
   - 15:11:41 the follower's VM is powered off (preemptible VM reclaimed by the 
cloud provider, about 30 s notice).
   
   Cause: `MetaHelper.getRemoteFile` never syncs the downloaded file. 
`IOUtils.copyBytes(bin, out, ..., true)` closes the output stream right after 
the copy, the MD5 check reads the file back from the page cache, and 
`MetaHelper.complete` renames it to its final name. The master's own checkpoint 
path does not have this problem: `MetaWriter.write` and `MetaFooter.write` call 
`force(true)`. A power loss within the kernel's writeback window after the 
rename leaves a truncated `image.N` that the FE picks as its newest image.
   
   Impact: `Env.loadImage` loads only the newest image, so the FE fails on 
every restart even though the previous image is intact. With two FEs, the 
master also lost its BDB JE majority (`Insufficient acks for 
policy:SIMPLE_MAJORITY`) and no FE could be elected until the follower's image 
was fixed by hand.
   
   ### What You Expected?
   
   A downloaded image should be on disk before it is renamed to `image.N`, so 
that a power loss leaves either the previous image or a complete new one.
   
   ### How to Reproduce?
   
   Timing-dependent; it needs a host power loss (not a process kill) within a 
few seconds of a follower storing a new image:
   
   1. Run a cluster with at least two FEs and enough metadata that an image 
takes some time to download.
   2. Let the master take a checkpoint and push it to the follower (`push 
image.N to other nodes` in the master's `fe.log`).
   3. Power off the follower's host (for example, reset the VM) a few seconds 
after it logs `put image`.
   4. Start the follower: it fails in `MetaReader.read` as above, and its 
`image.N` is shorter than the master's.
   
   A tool that drops unsynced writes, such as dm-flakey or LazyFS, can 
reproduce it deterministically.
   
   ### Anything Else?
   
   Proposed fix: sync the downloaded file before the MD5 check and the rename, 
and sync the image directory after the rename. A PR follows.
   
   A separate question for maintainers: should `Env.loadImage` fall back to the 
previous image when the newest one fails to load? Here the previous image and 
the journals after it were intact, and falling back would have avoided the 
manual recovery.
   
   ### Are you willing to submit PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to