kirito632 opened a new pull request, #3499:
URL: https://github.com/apache/kvrocks/pull/3499

   ## What
   
   This PR introduces the `XACKDEL` and `XDELEX` stream commands with 
configurable
   PEL cleanup behaviors.
   
   It also fixes an existing issue in `XINFO CONSUMERS` where consumer metadata
   from different groups could leak into the same scan result.
   
   ## XINFO CONSUMERS Fix
   
   Root cause:
   `GetConsumerInfo()` sets `iterate_upper_bound` by incrementing only the 
version
   while keeping the sub-key prefix (which includes the group name) unchanged.
   Since the version field precedes the sub-key in the InternalKey encoding
   (`[version][sub_key]`), consumer keys from other groups can fall within the
   `[version, version+1)` range when their group name sorts lexicographically
   at or after the target group's name prefix.
   
   Fix:
   Extract and validate the group name from each internal key during iteration,
   filtering out consumers belonging to other groups.
   
   ## XACKDEL / XDELEX
   
   Supported deletion strategies:
   
   - `KEEPREF` (default):
     Delete the stream entry only.
   
   - `DELREF`:
     Delete the stream entry and remove it from all groups' PELs.
   
   - `ACKED`:
     Delete the stream entry only if it has been acknowledged by all consumer 
groups.
   
   Both commands return per-ID status codes:
   
   - `1`: entry deleted
   - `2`: entry retained (e.g. ACKED condition not satisfied)
   - `-1`: entry not found or duplicate ID within the same request
   
   ## Implementation Notes
   
   - Pending-number decrements are aggregated in memory and flushed once
     through a single `WriteBatch`, avoiding repeated metadata updates during
     DELREF operations.
   
   - Duplicate IDs within the same request are deduplicated to preserve
     idempotency and prevent stream metadata corruption.
   
   - The originating command name (`XACKDEL` or `XDELEX`) is propagated into
     `WriteBatchExtractor` so replicas replay the exact same semantics.
   
   - Internal stream metadata / PEL delete events are filtered out in
     `WriteBatchExtractor` by skipping synthetic subkeys whose entry-id prefix
     starts with `UINT64_MAX`, preventing invalid replicated `XDEL` commands.
   
   ## Testing
   
   Added Go integration tests covering:
   
   - multi-group DELREF cleanup
   - ACKED blocking semantics
   - duplicate-ID idempotency
   - invalid syntax handling
   - XINFO CONSUMERS group isolation
   
   ## AI-Assisted Contribution Disclosure
   
   This contribution complies with the ASF AI-assisted contribution guidelines.
   
   AI tools were used to assist with English phrasing and some test scaffolding.
   The core C++ implementation, debugging, correctness analysis, and final 
verification
   were independently completed by me.


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