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

   ### Motivation
   
   `ResetOffsetByTimeCommand` registers **two** options with the short name `c`:
   
   ```java
   opt = new Option("c", "cplus", false, "reset c++ client offset. 
Deprecated.");   // line 64
   ...
   opt = new Option("c", "cluster", true, "Cluster name or lmq parent topic, 
..."); // line 80
   ```
   
   commons-cli's `Options.addOption` keys the short-opt map by name, so the 
later `cluster` registration replaces `cplus` for `-c`. Consequences:
   
   1. The documented `-c`/`--cplus` deprecated switch can never be enabled 
through its short form.
   2. Any user passing `-c <cluster>` (the documented usage, e.g. to find the 
route for an LMQ parent topic) makes `isC = commandLine.hasOption('c')` true, 
so `resetOffsetByTimestamp(..., isC)` → 
`MQClientAPIImpl.invokeBrokerToResetOffset(..., isC)` sends the request with 
`LanguageCode.CPP`. The broker then replies with `ResetOffsetBodyForC` 
(`List<MessageQueueForC>`), which the Java client decodes as `ResetOffsetBody` 
(`Map<MessageQueue, Long>`) — garbage offsets/exception instead of a proper 
reset for every Java consumer group whenever `-c` is used.
   
   ### Modifications
   
   - Drop the short name from the deprecated `cplus` option (`--cplus` keeps 
working, `-c` no longer collides).
   - Compute `isC` from the long name: `commandLine.hasOption("cplus")`.
   - Extract `createDefaultMQAdminExt(RPCHook)` as a protected factory so the 
command can be tested with a stubbed admin client.
   
   ### Verification
   
   Fail-before (new test `testExecuteWithClusterOptionKeepsJavaClientProtocol`, 
run against the unpatched code — executes the command with `-g -t -s -f false 
-c default-cluster` and verifies the admin call):
   
   ```
   Tests run: 2, Failures: 1 -- ResetOffsetByTimeCommandTest
   Argument(s) are different! Wanted:
   defaultMQAdminExt.resetOffsetByTimestamp("default-cluster", "unit-test", 
"default-group", 1412131213231L, false, false);
   Actual invocations have different arguments:
   defaultMQAdminExt.resetOffsetByTimestamp("default-cluster", "unit-test", 
"default-group", 1412131213231L, false, true);
   ```
   
   Pass-after:
   
   ```
   Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 -- 
ResetOffsetByTimeCommandTest
   ```
   


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