HDDS-16130. Remove Pair usage from Safe-mode APIs and callers. - #10993
Conversation
|
Hi @szetszwo , Kindly review once you get some time. |
|
@sreejasahithi would u like to review this? |
szetszwo
left a comment
There was a problem hiding this comment.
@navinko , thanks for working on this! Since there is already a SafeModeRuleStatusProto, let's just use it and do not add SafeModeRuleStatus.
BTW, Ozone use 120 characters for line width. Please combine the existing short lines when you are changing the related code.
| /** | ||
| * Status of SCM safe mode exit rule. | ||
| */ | ||
| public final class SafeModeRuleStatus { |
There was a problem hiding this comment.
In this case, do not add SafeModeRuleStatus. Just use SafeModeRuleStatusProto.
There was a problem hiding this comment.
Thanks @szetszwo for the review
My bad , please allow me to correct and update the PR
|
Thanks @szetszwo for the review . |
szetszwo
left a comment
There was a problem hiding this comment.
@navinko , thanks for the update!
Using Map in this case in unnecessary (since get(key) is never called) and inefficient. Let's change them to List; see https://issues.apache.org/jira/secure/attachment/13083934/10993_review.patch
Thanks @szetszwo for the review. Successful CI : https://github.com/navinko/ozone/actions/runs/31964576589/job/95219220076 |
| String host1 = HddsUtils.getHostName(address1).orElse(address1); | ||
| String host2 = HddsUtils.getHostName(address2).orElse(address2); | ||
|
|
||
| boolean hostsMatch = host1.equalsIgnoreCase(host2); | ||
| if (!hostsMatch) { | ||
| InetAddress inet1 = InetAddress.getByName(host1); | ||
| InetAddress inet2 = InetAddress.getByName(host2); | ||
| hostsMatch = inet1.equals(inet2); | ||
| } | ||
| if (!hostsMatch) { | ||
| // Parse both addresses into host:port components | ||
| String[] parts1 = address1.split(":", 2); | ||
| String[] parts2 = address2.split(":", 2); | ||
|
|
||
| String host1 = parts1[0]; | ||
| String host2 = parts2[0]; | ||
|
|
||
| // Hostnames must match | ||
| if (!host1.equalsIgnoreCase(host2)) { |
There was a problem hiding this comment.
@navinko , This change is unrelated. If there is a need, let's do it separately.
The PR looks good other than that.
There was a problem hiding this comment.
I got these unrelated changes post resolving conflict and accepted changes from master .
There was a problem hiding this comment.
@navinko I think you might have accepted wrong changes
as this is the latest commit to this particular file SafeModeCheckSubcommand.java
https://github.com/apache/ozone/pull/10831/changes#diff-1ef0fa9c02403bdd29621610c5d5ee82c08a9a2b5dc96de3e738a9568b7feb42L188-R207
Could you please check this out.
There was a problem hiding this comment.
Thanks @sreejasahithi for review , Ideally once we resolve the conflict we shud accept the changes coming from master . I also did the same , But instead of rebasing on master and resolving locally, used a shortcut and resolved the conflict in the GitHub UI , that merged master's changes to SafeModeCheckSubcommand.java into my diff and caused the unrelated changes. I've now rebased properly on the latest master and addressed the review comments. The PR now contains only the safe-mode changes and is List-based end-to-end, with no conflicts.
CI Build already triggered , will monitor and mark the PR for review.
sreejasahithi
left a comment
There was a problem hiding this comment.
Thanks @navinko for this improvement
overall changes LGTM
| String host1 = HddsUtils.getHostName(address1).orElse(address1); | ||
| String host2 = HddsUtils.getHostName(address2).orElse(address2); | ||
|
|
||
| boolean hostsMatch = host1.equalsIgnoreCase(host2); | ||
| if (!hostsMatch) { | ||
| InetAddress inet1 = InetAddress.getByName(host1); | ||
| InetAddress inet2 = InetAddress.getByName(host2); | ||
| hostsMatch = inet1.equals(inet2); | ||
| } | ||
| if (!hostsMatch) { | ||
| // Parse both addresses into host:port components | ||
| String[] parts1 = address1.split(":", 2); | ||
| String[] parts2 = address2.split(":", 2); | ||
|
|
||
| String host1 = parts1[0]; | ||
| String host2 = parts2[0]; | ||
|
|
||
| // Hostnames must match | ||
| if (!host1.equalsIgnoreCase(host2)) { |
There was a problem hiding this comment.
@navinko I think you might have accepted wrong changes
as this is the latest commit to this particular file SafeModeCheckSubcommand.java
https://github.com/apache/ozone/pull/10831/changes#diff-1ef0fa9c02403bdd29621610c5d5ee82c08a9a2b5dc96de3e738a9568b7feb42L188-R207
Could you please check this out.
| * @return map of rule statuses. | ||
| */ |
There was a problem hiding this comment.
Could you please also update this comment as it is stale now.
088cbb2 to
1dd5fc4
Compare
sreejasahithi
left a comment
There was a problem hiding this comment.
Thanks for the update @navinko . The List change in the verbose path looks correct and matches the review feedback.
However, commit 1dd5fc4 changed too much in SafeModeCheckSubcommand.java. While trying to remove unrelated changes, it also removed findLeaderNode() and the HA branch in executeForSingleNode() and printSafeModeRules(). That logic is already on master so please restore it.
Also, matchesAddress() should stay as on master (HddsUtils.getHostName() + InetAddress for IPv6), not the older split(":") version.
For this file, the intended change is only in the verbose block inside queryNode() and also printSafeModeRules():
before: Map<String, Pair<Boolean, String>>
after: List<SafeModeRuleStatusProto>
Everything else in SafeModeCheckSubcommand.java should match master.
|
|
||
| private void executeForSingleNode(ScmClient scmClient, ScmNodeTarget targetScmNode) throws IOException { | ||
| SCMNodeInfo targetNode; | ||
| if (serviceId != null) { | ||
| // HA mode: find leader | ||
| targetNode = findLeaderNode(scmClient); | ||
| if (targetNode == null) { | ||
| throw new IOException("Could not determine leader node"); | ||
| } | ||
| } else { | ||
| // Non-HA mode: use single node | ||
| targetNode = nodes.get(0); |
There was a problem hiding this comment.
Why was this code removed?
There was a problem hiding this comment.
Thanks the PR was in DRAFT and changes in flight .
| } | ||
|
|
||
| /** | ||
| * Find the leader node from SCM roles. | ||
| * @param scmClient the SCM client | ||
| * @return the leader SCMNodeInfo | ||
| */ | ||
| private SCMNodeInfo findLeaderNode(ScmClient scmClient) throws IOException { | ||
| try { | ||
| List<String> roles = scmClient.getScmRoles(); | ||
| for (String role : roles) { | ||
| String[] parts; | ||
| try { | ||
| parts = HddsUtils.parseRatisRoleString(role); | ||
| } catch (IllegalArgumentException e) { | ||
| continue; | ||
| } | ||
| if (!"LEADER".equalsIgnoreCase(parts[2])) { | ||
| continue; | ||
| } | ||
| String leaderHost = parts[0]; | ||
| String leaderIp = parts[4]; | ||
| for (SCMNodeInfo node : nodes) { | ||
| String nodeHost = HddsUtils.getHostName(node.getScmClientAddress()).orElse(""); | ||
|
|
||
| if (matchesAddress(leaderHost, nodeHost) || (!leaderIp.isEmpty() && | ||
| matchesAddress(leaderIp, nodeHost))) { | ||
| return node; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
why was this code removed?
There was a problem hiding this comment.
Thanks the PR was in DRAFT and changes in flight .
2fa7167 to
434462e
Compare
|
Thanks @sreejasahithi , @szetszwo for the review. I fixed the unintentional changes and PR is ready to review. |
szetszwo
left a comment
There was a problem hiding this comment.
+1 the change looks good.
sreejasahithi
left a comment
There was a problem hiding this comment.
Thanks @navinko for updating the PR
LGTM
nit: (non-blocking) javadoc in ScmClient still says returns map for getSafeModeRuleStatuses
Thanks @sreejasahithi my bad , corrected doc. |
|
Sure @szetszwo will make sure going forward. I saw new conflict today so rebased and force push. |
Thanks @Gargi-jais11 sure! |
Please do merge instead of force push. If there is a need, please ask on the PR first before force-pushing it. As a reviewer, I really want to minimize my time on reviwing. |
Thanks @szetszwo, makes sense. My intent was just to keep the history clean, but now am aware that it forces reviewers to re-read everything from the beginning. I'll follow the suggested approach going forward . |
szetszwo
left a comment
There was a problem hiding this comment.
+1 the change looks good.
|
@sreejasahithi , @Gargi-jais11 , thanks also for reviewing this! |
|
Thanks @sreejasahithi @Gargi-jais11 @szetszwo for reviewing and merging the PR. |
What changes were proposed in this pull request?
This PR splits out the safe-mode API and caller updates from the larger HDDS-15942 change set in PR #10962 into a separate subtask.
Why are the changes needed?
It replaces the old
Pair<Boolean, String>based safe-mode status contract with the newSafeModeRuleStatustype across the SCM protocol, SCM server, andcli-admin. Replacing it with SafeModeRuleStatus gives the fields a clear meaning, self-describing and easier to maintain.What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-16130
How was this patch tested?
Updated the respective Test cases and validated locally.
Successful CI : https://github.com/navinko/ozone/actions/runs/31507651933