itxaiohanglover opened a new pull request, #10532:
URL: https://github.com/apache/rocketmq/pull/10532

   ## What is the purpose of the change
   
   Fixes #10421
   
   In the timer message RocksDB store, `DELETE_KEY_CACHE_FOR_TIMER` is used to 
prevent an `UPDATE` record from re-inserting an already-deleted key (which 
would leave a ghost record in RocksDB).
   
   However, the cache uses `byte[]` as its key type. Since `byte[].equals()` 
compares object references rather than content, and 
`TimerRocksDBRecord.getKeyBytes()` returns a new byte array each time, 
`cache.getIfPresent(keyBytes)` always returns `null` even when the same key 
content was previously put. As a result, the `UPDATE` path always writes the 
record back, producing ghost records.
   
   ## Brief changelog
   
   In `MessageRocksDBStorage.java`:
   - Change `DELETE_KEY_CACHE_FOR_TIMER` cache key type from `Cache<byte[], 
byte[]>` to `Cache<ByteBuffer, byte[]>`. `ByteBuffer` implements content-based 
`equals()`/`hashCode()`, so cache lookups match on key content rather than 
array identity.
   - Wrap keys with `ByteBuffer.wrap(keyBytes)` in both `cache.put(...)` and 
`cache.getIfPresent(...)` calls.
   
   ## Verifying this change
   
   - The `DELETE` branch now correctly stores a `ByteBuffer`-wrapped key, and 
the `UPDATE` branch correctly retrieves it by content, so already-deleted keys 
are skipped as intended.
   - `java.nio.ByteBuffer` is already imported in the file, so no new imports 
are required.
   
   Follow this checklist to request a review from a maintainer:
   - [x] Make sure there is a [Github 
issue](https://github.com/apache/rocketmq/issues) filed for the change (usually 
before you start working on it). Trivial changes like typos do not require a 
Github issue. Your pull request should address just this issue, without pulling 
in other changes.
   - [x] Each commit in the pull request should have a meaningful subject line 
and body.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Check the style with `./mvnw -T 2C clean checkstyle:check`.
   - [x] Run `./mvnw -T 2C clean test -Dtest=...` to make sure unit tests pass.


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