Skip to content

[server] Fix TabletServer fails to restart after unclean shutdown due to EOFException in log recovery - #2942

Merged
wuchong merged 2 commits into
apache:mainfrom
LiebingYu:fix-recover-log
May 11, 2026
Merged

wuchong merged 2 commits into
apache:mainfrom
LiebingYu:fix-recover-log

Conversation

@LiebingYu

Copy link
Copy Markdown
Contributor

Purpose

Linked issue: close #2941

Brief change log

Tests

API and Format

Documentation

@LiebingYu
LiebingYu force-pushed the fix-recover-log branch 2 times, most recently from 65ef17f to 51fa15a Compare March 30, 2026 01:51

@fresh-borzoni fresh-borzoni left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LiebingYu Thanks for the PR, we bumped into this issue last week, so I studied this code

The unconditional-recoverSegment change is right (matches Kafka), but the fix doesn't actually close this issue in my opinion.

I was able to reproduced the crash by appending 40 zero bytes to the active .log (typical shape after an interrupted write). The crash is inside recover() itself: it asks for max-timestamp before doing anything, the getter scans the whole file to compute it, and the scan walks into the corrupt tail.

The possible fix might be small: track max-timestamp in a local variable inside the loop instead of going through the getter. Recovery is iterating every batch anyway.

The new test passes against the buggy code: its garbage bytes happen to decode as a huge length, so the iterator rejects the would-be batch before reaching the bug. If we switch the bytes to zeros, then it fails on this branch.

Three smaller things I noticed in the same area, all pre-existing:

  • recover()'s catch is for CorruptRecordException, but it can also fail with CRC check with CorruptMessageException, for example
  • an unrecognised magic byte throws an uncaught IllegalArgumentException from the parser, and we had it during our unclean shutdown when garbage was interpreted this way

@wuchong

wuchong commented May 9, 2026

Copy link
Copy Markdown
Member

Thanks @fresh-borzoni for the review comments. Your finding sounds make sense to me. I think we should address them as well. What do you think @LiebingYu @swuferhong ?

@LiebingYu

Copy link
Copy Markdown
Contributor Author

@fresh-borzoni Thank you for your insightful discovery.

The new test does exactly bypass the batch parsing, and has been modified to use 40 zero bytes.

On this issue, the core differences between Fluss and Kafka are:

  1. When calling maxTimestampSoFar(), Fluss also reads the .log file to find a more precise maxTimestampSoFar, whereas Kafka does not. This causes the exception to occur prematurely. Regarding the fix here, I agree with your approach — since we are already iterating through all batches, there is no need to read the precise maxTimestampSoFar upfront before starting. Instead, we can simply update it after reading each batch.

  2. Compared to Kafka, Fluss may encounter more types of exceptions during batch validation, including:

  • CorruptRecordException
  • InvalidRecordException
  • CorruptMessageException
  • IllegalArgumentException
  • IndexOutOfBoundsException

All of these have been handled. Could you please help review it again? Feel free to let me know if you have any concerns.

CC @wuchong @swuferhong

@wuchong wuchong left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@fresh-borzoni @swuferhong could you take another look?

@fresh-borzoni fresh-borzoni left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you @LiebingYu

@wuchong
wuchong merged commit 56dc6de into apache:main May 11, 2026
17 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[server] TabletServer fails to restart after unclean shutdown due to EOFException in log recovery

3 participants