frotmo opened a new issue, #11574:
URL: https://github.com/apache/rocketmq/issues/11574

   ### Before Creating the Bug Report
   
   - [x] I found a bug, not just asking a question, which should be created in 
GitHub Discussions.
   - [x] I have searched the GitHub Issues and GitHub Discussions of this 
repository and believe that this is not a duplicate.
   - [x] I have confirmed that this bug belongs to the current repository, not 
other repositories of RocketMQ.
   
   ### Runtime platform environment
   
   OS: Ubuntu 24.04 (WSL2); the issue is platform-independent broker logic.
   Component: broker transaction check, with `transRocksDBEnable=true`.
   
   ### RocketMQ version
   
   - branch: develop
   - version: 5.5.1
   - Git commit id: b1dadbd3d8a311dd79ce72a3899a64dbfa1bc455
   
   ### JDK Version
   
   Compiler/runtime: OpenJDK 8u514.
   The behavior is not JDK-version specific.
   
   ### Describe the Bug
   
   **TL;DR**
   
   `TransactionalMessageRocksDBService#checkTransRecordsStatus` treats
   `getMessage() == null` as "the half message does not exist" and marks the
   RocksDB record deleted. But `getMessage` can return null after a transient
   commitLog read/decode failure, so a temporary failure can permanently remove
   the only durable handle used for transaction check-back.
   
   **Code path**
   
   In `TransactionalMessageRocksDBService`:
   
   ```java
   MessageExt msgExt = transMessageRocksDBStore.getMessage(offsetPy, sizePy);
   if (null == msgExt) {
       log.error("... msgExt is null ...");
       halfRecord.setDelete(true);
       updateList.add(halfRecord);
       continue;
   }
   ```
   
   In `TransMessageRocksDBStore#getMessage`:
   
   - invalid parameters return null;
   - the method retries `MAX_GET_MSG_TIMES = 3` times;
   - each attempt uses `StoreUtil.getMessage`, which returns null when
     `messageStore.getData(...)` is false, when `MessageDecoder.decode(...)`
     throws, or when any exception occurs while reading.
   
   So null means "I could not read/validate the message this time", not
   "the message definitely does not exist".
   
   **Impact**
   
   The half record is what allows the broker to check back with the producer
   when the commit/rollback request is lost or delayed. If it is deleted:
   
   - a local transaction may have committed while the final message was never
     delivered;
   - downstream consumers may miss the event;
   - the broker can no longer resolve the transaction via check-back.
   
   **Scope**
   
   `transRocksDBEnable` is `false` by default, so this only affects deployments
   that explicitly enable the RocksDB transaction path. I am reporting it to
   clarify the intended contract before proposing a behavior change.
   
   ### Steps to Reproduce
   
   The behavior can be reproduced deterministically with a unit test that mocks
   the read boundary (no real disk error is required):
   
   ```java
   TransRocksDBRecord record =
       new TransRocksDBRecord(123L, "topicA", "uniqKeyA", 100, 0);
   
   // simulate getMessage() after its internal retries exhausted
   when(transMessageRocksDBStore.getMessage(123L, 100)).thenReturn(null);
   
   // invoke private checkTransRecordsStatus(List<TransRocksDBRecord>)
   // through reflection, then capture updateRecordsForTrans(...)
   // observed: record.isDelete() == true
   ```
   
   I have a full JUnit test that asserts the record is retained; it fails on the
   current code with `delete=true` and passes with the conservative behavior
   described below. I can include it in a PR if the maintainers agree on the
   intended semantics.
   
   In a real deployment, the same path is reached when the half message body
   cannot be read from commitLog (transient IO/mmap issue, truncated file,
   decode failure) while the RocksDB transaction record is still present.
   
   ### What Did You Expect to See?
   
   A null result that does not prove permanent absence should not delete the
   half record. Possible behaviors:
   
   1. Treat null as transient/unknown: keep the record, retry on the next
      `transactionCheckInterval`, and use a separate orphan policy for records
      that are provably expired (for example, below the commitLog min physical
      offset or older than a configured age).
   2. Make the read result typed (`FOUND / NOT_FOUND / READ_ERROR / INVALID`);
      only `NOT_FOUND`/`INVALID` should lead to archive/delete, while
      `READ_ERROR` should be retried.
   3. If the current behavior is intentional, please document the contract and
      add tests so users know that an unreadable half message is abandoned.
   
   ### What Did You See Instead?
   
   The first null result after the internal retries marks the half record
   `delete=true`, and `updateRecordsForTrans` persists that deletion. The
   record's `checkTimes` is not incremented, no archive copy is made, and the
   transaction check-back handle is lost.
   
   ### Additional Context
   
   **Comparison with the old path**
   
   | Path | On unreadable half message |
   |---|---|
   | `TransactionalMessageServiceImpl` (default) | `getHalfMsg` distinguishes 
pull status; retries/advances on null; only calls `resolveDiscardMsg` after 
`needDiscard`/`needSkip`; the default listener moves the message to 
`TRANS_CHECK_MAXTIME_TOPIC` |
   | `TransactionalMessageRocksDBService` (`transRocksDBEnable=true`) | 
`getMessage == null` immediately sets `delete=true`; `checkTimes` is unchanged; 
no archive |
   
   The `TransactionalMessageService#check` Javadoc says a message is discarded
   when the check count exceeds `transactionCheckMax`, not when a read fails.
   
   **History (context only, not blame)**
   
   The branch appears to have been present since the initial RIP-82 RocksDB
   transaction implementation (#9787) and is unchanged. The RIP-82 wiki focuses
   on simplifying the transaction/index implementation with a KV model; I could
   not find a documented contract or a dedicated test for the null/read-failure
   case. I may be missing context from the original design discussion: if this
   was a deliberate decision, could you point me to the rationale?
   
   One plausible motivation is orphan-index cleanup: if the commitLog body is
   permanently gone, keeping a dangling RocksDB record only produces repeated
   errors and log noise. That makes sense, but the current check cannot
   distinguish permanent absence from a transient read failure; a typed result
   or a min-offset/age check would.
   
   **Open questions**
   
   1. Is `getMessage() == null` intended to mean "permanently absent"?
   2. If yes, can we make that explicit in the store API (typed status) instead
      of inferring it from a null that also represents read failures?
   3. If the goal is only to avoid stuck records, should cleanup be based on
      min physical offset/age rather than on a read failure?
   
   **Suggested direction**
   
   - Preserve the record on `READ_ERROR`/unknown results and retry.
   - Add a separate orphan policy for `NOT_FOUND`/`INVALID`/below-min-offset
     records (archive or delete with metrics).
   - Keep `transactionCheckMax` for actual check-back attempts; do not count
     read failures as check-back attempts.
   - Add tests for: transient null then success; repeated null; expired offset;
     invalid size/offset; and the existing max-check behavior.
   
   If the maintainers agree, I am happy to submit a PR with the regression test
   and the chosen behavior. If the current behavior is intentional, I can help
   add documentation, tests, or a typed read result instead.
   
   Thanks for the RIP-82 work — the KV-based model simplifies a lot. This report
   is about pinning down one ambiguous failure path, not questioning the overall
   design.


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