Skip to content

[ISSUE #11574] fix(broker): keep RocksDB half record on transient commitLog read failure - #11576

Open
frotmo wants to merge 1 commit into
apache:developfrom
frotmo:fix/tx-rocksdb-null-read
Open

frotmo wants to merge 1 commit into
apache:developfrom
frotmo:fix/tx-rocksdb-null-read

Conversation

@frotmo

@frotmo frotmo commented Nov 23, 2026 •

Copy link
Copy Markdown

Which Issue(s) This PR Fixes

Brief Description

This PR prevents the RocksDB transaction check path from deleting a half
record when the half message body cannot be read.

Background

TransactionalMessageRocksDBService#checkTransRecordsStatus currently treats
getMessage() == null as "the message does not exist" and sets
halfRecord.setDelete(true). However, TransMessageRocksDBStore#getMessage
retries three times, and StoreUtil.getMessage returns null when:

  • messageStore.getData(...) returns false (commitLog/mmap read failure,
    truncated file, invalid offset, ...);
  • MessageDecoder.decode(...) throws (partial/corrupt bytes);
  • any exception occurs while reading.

So null is an ambiguous "could not read/validate" result, not a proof of
absence. Deleting the record on the first null removes the only durable handle
used for transaction check-back. The old
TransactionalMessageServiceImpl path retries/advances and only calls
resolveDiscardMsg after needDiscard/needSkip; the default listener moves
the message to TRANS_CHECK_MAXTIME_TOPIC instead of silently deleting it.

Scope: this only affects deployments with transRocksDBEnable=true; the
default path is unchanged.

Change

When getMessage returns null:

  1. If the record is invalid (negative offset, non-positive size, or size >
    maxMessageSize), keep the existing cleanup behavior: mark it deleted.
  2. If the record is older than the commitLog min physical offset, the body has
    definitely been purged; keep the existing cleanup behavior: mark it deleted.
  3. Otherwise, treat the result as transient/unknown: do not delete the record,
    do not increment checkTimes, log a warning, and retry on the next
    transactionCheckInterval.

Key part of the diff:

if (null == msgExt) {
    if (isInvalidHalfRecord(halfRecord) || isExpiredHalfRecord(halfRecord)) {
        halfRecord.setDelete(true);
        updateList.add(halfRecord);
    } else {
        log.warn("... keep record for next check ...");
    }
    continue;
}
private boolean isInvalidHalfRecord(TransRocksDBRecord halfRecord) {
    return halfRecord.getOffsetPy() < 0L
        || halfRecord.getSizePy() <= 0
        || halfRecord.getSizePy() > messageStore.getMessageStoreConfig().getMaxMessageSize();
}

private boolean isExpiredHalfRecord(TransRocksDBRecord halfRecord) {
    return halfRecord.getOffsetPy() < messageStore.getMinPhyOffset();
}

Why this design

  • It does not assume that null means "permanently missing"; it distinguishes
    "definitely invalid/purged" from "unknown".
  • minPhyOffset is a conservative discriminator: below it, the commitLog file
    containing the record is already gone; otherwise the message may still be
    valid and the read may succeed on the next scan.
  • checkTimes is left untouched on a read failure. It is the transaction
    check-back counter, not a read-failure counter; incrementing it would let a
    transient outage exhaust transactionCheckMax and indirectly delete the
    record.
  • The existing max-check behavior for successfully read messages is unchanged.

Alternatives considered

  • Typed read result: change getMessage to return
    FOUND / NOT_FOUND / READ_ERROR / INVALID. Cleaner long term, but a larger
    API change; happy to follow up if maintainers prefer this direction.
  • Retain every null: simplest, but permanent orphans would accumulate and
    log every interval; the invalid/expired checks avoid that for the obvious
    cases.
  • Keep current behavior: avoids the orphan-retention concern, but loses the
    recovery handle on transient read failures.

Known limitation / follow-up

A record whose offset is still within [minPhyOffset, maxPhyOffset] but whose
body is permanently corrupt/unreadable will be retained and logged on each
scan. This PR intentionally favors data safety over silent deletion. A
follow-up can add an age/quarantine policy or a dedicated read-failure metric
without conflating it with checkTimes.

This PR is intentionally opened as a draft to confirm the null/read-failure
contract first. If maintainers prefer a typed getMessage result, I can
rework this PR around that design instead.

How Did You Test This Change?

Added TransactionalMessageRocksDBServiceNullReadRegressionTest with six
cases:

  1. valid offset, null read: record retained, checkTimes unchanged, no
    updateRecordsForTrans call;
  2. offset == minPhyOffset, null read: record retained (boundary);
  3. offset < minPhyOffset, null read: record deleted as expired;
  4. size <= 0, null read: record deleted as invalid;
  5. negative offset, null read: record deleted as invalid;
  6. size > maxMessageSize, null read: record deleted as invalid.

The two "retain" cases fail against the unmodified code (delete=true) and
pass with this change. The expired/invalid cases keep the previous cleanup
behavior, and the two new invalid cases cover both remaining invalid-record
branches. The existing TransactionalMessageRocksDBServiceTest also passes.

Commands:

mvn -pl broker \
  -Dtest=TransactionalMessageRocksDBServiceNullReadRegressionTest,TransactionalMessageRocksDBServiceTest \
  test

Result:

Tests run: 7, Failures: 0, Errors: 0, Skipped: 0
[KEEP] offsetPy=123 sizePy=100 checkTimes=0 delete=false
BUILD SUCCESS

checkstyle: check passed and spotbugs:check reported BugInstance size is 0.

The tests use reflection to invoke the private checkTransRecordsStatus
method, following the existing TransactionalMessageRocksDBServiceTest
pattern. No production API or configuration is changed.

@codecov-commenter

codecov-commenter commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.11%. Comparing base (38ddb48) to head (c4c1b79).
⚠️ Report is 5 commits behind head on develop.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop   #11576      +/-   ##
=============================================
+ Coverage      50.04%   50.11%   +0.06%     
- Complexity     14515    14547      +32     
=============================================
  Files           1391     1391              
  Lines         103460   103466       +6     
  Branches       13558    13561       +3     
=============================================
+ Hits           51777    51852      +75     
+ Misses         45449    45377      -72     
- Partials        6234     6237       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@frotmo
frotmo marked this pull request as ready for review November 23, 2026 11:41
…nt commitLog read failure

TransMessageRocksDBStore#getMessage returns null after retries when the
half message body cannot be read or decoded. Treating that as permanent
absence deletes the only durable handle used for transaction check-back.

Only delete records that are invalid or older than the commitLog min
physical offset; keep ambiguous read failures for the next check and do
not consume transaction check attempts.

Add regression cases for transient read failure, the minPhyOffset
boundary, expired records, and invalid offset/size values.
@frotmo
frotmo force-pushed the fix/tx-rocksdb-null-read branch from 61bbe97 to c4c1b79 Compare November 23, 2026 12:22
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.

[Bug] RocksDB transaction check deletes half record when commitLog message cannot be read

2 participants