AdyChechani opened a new pull request, #10831:
URL: https://github.com/apache/ozone/pull/10831

   Generated-by: Claude Code (Opus 4.6)
   
   ## What changes were proposed in this pull request?
   `SCMRatisServerImpl.getRatisRoles()` encodes each peer as a colon-delimited 
string `host:ratisPort:ROLE:uuid:hostIP`. Five consumers split this string on 
`:` with hardcoded indices. When the host or hostIP is an IPv6 literal (e.g. 
`2001:db8::1`), the extra colons shatter the split, `parts[2]` is no longer 
`LEADER`/`FOLLOWER`, and downstream code crashes or silently produces wrong 
results.
   
   
   ### This PR fixes both the producer and all consumers:
   * **Producer** (`SCMRatisServerImpl.getRatisRoles()`):
       * Normalizes `peer.getAddress()` through `HddsUtils.getHostName()` / 
`getHostPort()` / `getHostPortString()`, which brackets IPv6 hosts (e.g. 
`[2001:db8::1]:9894`).
       * Brackets `peerInetAddress.getHostAddress()` when it contains colons.
   
   The resulting string for IPv6 is now: 
`[2001:db8::1]:9894:LEADER:peer1:[2001:db8:0:0:0:0:0:1]`
   
   * **Shared parser** (`HddsUtils.parseRatisRoleString()`):
       * New utility that parses the role string from right to left, handling 
bracketed IPv6 in both the host:port prefix and the hostIP suffix. Uses Guava 
`HostAndPort` for the host:port portion. Returns a 5-element `String[]`: 
`[host, port, role, id, hostIP]`.
   
   * **Consumers** (all 4 sites):
       * `StorageContainerManager.getScmRatisRoles()` — replaced 
`role.split(":")` with `HddsUtils.parseRatisRoleString(role)`.
       * `GetScmRatisRolesSubcommand` (table and JSON paths) — same replacement.
       * `StorageContainerServiceProviderImpl.getSCMDBSnapshot()` (Recon) — 
same.
       * `SafeModeCheckSubcommand.findLeaderNode()` — same, plus fixed node 
address comparison to use `HddsUtils.getHostName()` instead of `split(":")[0]`.
   
   No `.proto` schema change is needed: the wire field remains `repeated string 
peerRoles` in `GetScmInfoResponseProto`. Only the string content changes (IPv6 
literals are now bracketed), which is transparent to protobuf.
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-15774
   
     ## How was this patch tested?
   
     - Added `TestHddsUtils#testParseRatisRoleStringIPv4`, 
`testParseRatisRoleStringIPv6`, `testParseRatisRoleStringIPv6Follower`, and 
`testParseRatisRoleStringEmptyHostIp` covering the parser with IPv4, IPv6 
(leader/follower), and edge cases.
     - Added `TestSCMRatisServerImpl#testGetRatisRolesWithIPv6`, end-to-end 
test that creates a mock RaftPeer with a bracketed IPv6 address and verifies 
the produced string parses correctly.
     - Added `TestGetScmRatisRolesSubcommand#testGetScmHARatisRolesIPv6`, 
verifies the CLI `--table` output renders correctly for IPv6 role strings.
     - Existing `testGetScmHARatisRoles` (IPv4) continues to pass unchanged.
     - `checkstyle.sh, rat.sh, and author.sh ` pass locally
     - `mvn clean install -DskipTests` succeeds


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to