Skip to content

HDDS-16130. Remove Pair usage from Safe-mode APIs and callers. - #10993

Merged
szetszwo merged 3 commits into
apache:masterfrom
navinko:HDDS-16130
Aug 20, 2026
Merged

HDDS-16130. Remove Pair usage from Safe-mode APIs and callers.#10993
szetszwo merged 3 commits into
apache:masterfrom
navinko:HDDS-16130

Conversation

@navinko

@navinko navinko commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

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 new SafeModeRuleStatus type across the SCM protocol, SCM server, and cli-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

@navinko

navinko commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Hi @szetszwo , Kindly review once you get some time.

@Gargi-jais11

Copy link
Copy Markdown
Contributor

@sreejasahithi would u like to review this?

@szetszwo szetszwo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, do not add SafeModeRuleStatus. Just use SafeModeRuleStatusProto.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @szetszwo for the review
My bad , please allow me to correct and update the PR

@navinko
navinko marked this pull request as draft August 14, 2026 04:24
@navinko
navinko marked this pull request as ready for review August 15, 2026 07:00
@navinko

navinko commented Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @szetszwo for the review .
I tried addressing the suggestions. kindly review once you get some time.
Successful CI : https://github.com/navinko/ozone/actions/runs/31826571802

@navinko
navinko requested a review from szetszwo August 15, 2026 18:20

@szetszwo szetszwo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

@navinko

navinko commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

@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.
Updated the changes as per review patch. Switched the safe-mode status flow to List end-to-end and removed the unnecessary map conversion.

Successful CI : https://github.com/navinko/ozone/actions/runs/31964576589/job/95219220076

@navinko
navinko marked this pull request as ready for review August 16, 2026 21:23
@navinko
navinko requested a review from szetszwo August 16, 2026 21:23
Comment on lines +196 to +204
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)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@navinko , This change is unrelated. If there is a need, let's do it separately.

The PR looks good other than that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got these unrelated changes post resolving conflict and accepted changes from master .

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 sreejasahithi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @navinko for this improvement
overall changes LGTM

Comment on lines +196 to +204
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)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines 2098 to 2099
* @return map of rule statuses.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please also update this comment as it is stale now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@navinko
navinko force-pushed the HDDS-16130 branch 3 times, most recently from 088cbb2 to 1dd5fc4 Compare August 17, 2026 17:00
@navinko
navinko marked this pull request as draft August 17, 2026 17:38

@sreejasahithi sreejasahithi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 83 to -94

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this code removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks the PR was in DRAFT and changes in flight .

Comment on lines 98 to -128
}

/**
* 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;
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this code removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks the PR was in DRAFT and changes in flight .

@navinko
navinko force-pushed the HDDS-16130 branch 2 times, most recently from 2fa7167 to 434462e Compare August 17, 2026 18:03
@navinko
navinko marked this pull request as ready for review August 17, 2026 19:10
@navinko
navinko marked this pull request as draft August 17, 2026 19:18
@navinko

navinko commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @sreejasahithi , @szetszwo for the review. I fixed the unintentional changes and PR is ready to review.
Successfull CI : https://github.com/navinko/ozone/actions/runs/32058141015

@navinko
navinko marked this pull request as ready for review August 18, 2026 15:34

@szetszwo szetszwo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 the change looks good.

@sreejasahithi sreejasahithi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @navinko for updating the PR
LGTM

nit: (non-blocking) javadoc in ScmClient still says returns map for getSafeModeRuleStatuses

@navinko

navinko commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

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.

@szetszwo

Copy link
Copy Markdown
Contributor

navinko force-pushed the HDDS-16130 branch from b5ca8de to 571d322 12 hours ago

@navinko , after force-pushed, reviewers cannot easily tell what are the new changes from the last review. So, please don't force-pushed since you are also forcing reviewers reading the changes from the beginning.

@navinko

navinko commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Sure @szetszwo will make sure going forward. I saw new conflict today so rebased and force push.

@Gargi-jais11

Copy link
Copy Markdown
Contributor

Sure @szetszwo will make sure going forward. I saw new conflict today so rebased and force push.

@navinko you can use git --merge master instead of git --rebase to avoid the force push in case of conflicts.
git pull --merge apache master

@navinko

navinko commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Sure @szetszwo will make sure going forward. I saw new conflict today so rebased and force push.

@navinko you can use git --merge master instead of git --rebase to avoid the force push in case of conflicts.
git pull --merge apache master

Thanks @Gargi-jais11 sure!

@szetszwo

Copy link
Copy Markdown
Contributor

... merge master instead of git --rebase to avoid the force push in case of conflicts.

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.

@navinko

navinko commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

... merge master instead of git --rebase to avoid the force push in case of conflicts.

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 .
Also in this PR particularly, do we need to redo rebase ?

@szetszwo szetszwo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 the change looks good.

@szetszwo
szetszwo merged commit 9e7ba24 into apache:master Aug 20, 2026
45 checks passed
@szetszwo

szetszwo commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

@sreejasahithi , @Gargi-jais11 , thanks also for reviewing this!

@navinko

navinko commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @sreejasahithi @Gargi-jais11 @szetszwo for reviewing and merging the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants