Skip to content

SOLR-17054: Remove unused and duplicate code in DistributedZkUpdateProcessor - #2038

Merged
bruno-roustant merged 3 commits into
apache:mainfrom
pvcnt:rm-code-distributedzkupdateprocessor
Oct 26, 2023
Merged

SOLR-17054: Remove unused and duplicate code in DistributedZkUpdateProcessor#2038
bruno-roustant merged 3 commits into
apache:mainfrom
pvcnt:rm-code-distributedzkupdateprocessor

Conversation

@pvcnt

@pvcnt pvcnt commented Oct 23, 2023

Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/SOLR-17054

Description

There is dead code and duplicate code in DistributedZkUpdateProcessor. It makes understanding this already complex class more difficult.

Solution

Dead code and duplicate code has been removed, using automated refactoring tools available in Intellij whenever possible, to reduce the risk of errors.

Tests

No new code.

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation for the Reference Guide

useNodes = nodes;
params.set(DISTRIB_UPDATE_PARAM, DistribPhase.TOLEADER.toString());
params.set(COMMIT_END_POINT, "leaders");
if (useNodes != null) {

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.

Was always non-null.

// that means I want to forward onto my replicas...
// so get the replicas...
forwardToLeader = false;
String leaderCoreNodeName = leaderReplica.getName();

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.

Was exactly the same as getReplicaNodesForLeader, except for the timeout (has been added as an argument of the method).

}

private List<SolrCmdDistributor.Node> getCollectionUrls(
String collection, EnumSet<Replica.Type> types, boolean onlyLeaders) {

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.

onlyLeaders was always true therefore types was not used.

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.

I looked at the git history.
This code comes from a refactor in 2019 of DistributedUpdateProcessor to extract the code specific to cloud. At that time this method signature already contained the boolean.
Looking earlier, I saw that the boolean was added in 2018 in a commit “Make massive improvements to the tests”. It added the boolean and modified the single call to pass true. Well, I believe it was a perf optimization to always limit to leaders. At that time the intent was clearly to ignore the dead code, and I think the dead code should have been removed from the method instead of adding this boolean.
So after looking at the context, I’m +1 to remove this dead code.

@pvcnt
pvcnt marked this pull request as ready for review October 23, 2023 08:53

@bruno-roustant bruno-roustant 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 Vincent!

}

private List<SolrCmdDistributor.Node> getCollectionUrls(
String collection, EnumSet<Replica.Type> types, boolean onlyLeaders) {

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.

I looked at the git history.
This code comes from a refactor in 2019 of DistributedUpdateProcessor to extract the code specific to cloud. At that time this method signature already contained the boolean.
Looking earlier, I saw that the boolean was added in 2018 in a commit “Make massive improvements to the tests”. It added the boolean and modified the single call to pass true. Well, I believe it was a perf optimization to always limit to leaders. At that time the intent was clearly to ignore the dead code, and I think the dead code should have been removed from the method instead of adding this boolean.
So after looking at the context, I’m +1 to remove this dead code.

@bruno-roustant

Copy link
Copy Markdown
Contributor

Could you create a JIRA issue for this PR to give it more visibility?
I agree it's only a cleanup, but since I investigated to be sure of the dead code removal, for me it means it's not fully trivial so I expect to have a JIRA in this case.

@pvcnt pvcnt changed the title Remove unused and duplicate code in DistributedZkUpdateProcessor SOLR-17054: Remove unused and duplicate code in DistributedZkUpdateProcessor Oct 26, 2023
@pvcnt

pvcnt commented Oct 26, 2023

Copy link
Copy Markdown
Contributor Author

@bruno-roustant JIRA ticket has been created: https://issues.apache.org/jira/browse/SOLR-17054

@bruno-roustant

Copy link
Copy Markdown
Contributor

Thanks Vincent, let's merge it!

@bruno-roustant
bruno-roustant merged commit 959029c into apache:main Oct 26, 2023
@pvcnt
pvcnt deleted the rm-code-distributedzkupdateprocessor branch October 26, 2023 08:59
bruno-roustant pushed a commit that referenced this pull request Oct 26, 2023
…ocessor (#2038)

Co-authored-by: Vincent Primault <vprimault@salesforce.com>
@epugh

epugh commented Oct 26, 2023

Copy link
Copy Markdown
Contributor

Nice clean up!

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.

3 participants