Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor BalancedAllocator.Balancer to LocalShardsBalancer #4761

Merged
merged 2 commits into from
Oct 17, 2022

Conversation

kotwanikunal
Copy link
Member

@kotwanikunal kotwanikunal commented Oct 13, 2022

Signed-off-by: Kunal Kotwani kkotwani@amazon.com

Description

Issues Resolved

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff
  • Commit changes are listed out in CHANGELOG.md file (See: Changelog)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@kotwanikunal kotwanikunal requested review from a team and reta as code owners October 13, 2022 04:52
@kotwanikunal kotwanikunal marked this pull request as draft October 13, 2022 04:53
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@codecov-commenter
Copy link

codecov-commenter commented Oct 13, 2022

Codecov Report

Merging #4761 (11e8c23) into main (d15795a) will increase coverage by 0.05%.
The diff coverage is 83.75%.

@@             Coverage Diff              @@
##               main    #4761      +/-   ##
============================================
+ Coverage     70.66%   70.72%   +0.05%     
- Complexity    57578    57717     +139     
============================================
  Files          4661     4663       +2     
  Lines        276662   276671       +9     
  Branches      40325    40317       -8     
============================================
+ Hits         195501   195668     +167     
+ Misses        64926    64697     -229     
- Partials      16235    16306      +71     
Impacted Files Coverage Δ
...r/routing/allocation/allocator/ShardsBalancer.java 33.33% <33.33%> (ø)
.../allocation/allocator/BalancedShardsAllocator.java 90.90% <72.72%> (+3.77%) ⬆️
...ting/allocation/allocator/LocalShardsBalancer.java 84.37% <84.37%> (ø)
...ster/routing/allocation/AllocationConstraints.java 100.00% <100.00%> (ø)
.../index/shard/IndexShardNotRecoveringException.java 0.00% <0.00%> (-100.00%) ⬇️
...a/org/opensearch/client/cluster/SniffModeInfo.java 0.00% <0.00%> (-52.95%) ⬇️
.../java/org/opensearch/node/NodeClosedException.java 50.00% <0.00%> (-50.00%) ⬇️
...ch/transport/ReceiveTimeoutTransportException.java 50.00% <0.00%> (-50.00%) ⬇️
.../org/opensearch/client/indices/AnalyzeRequest.java 31.00% <0.00%> (-44.00%) ⬇️
...rch/client/transport/NoNodeAvailableException.java 28.57% <0.00%> (-42.86%) ⬇️
... and 471 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Signed-off-by: Kunal Kotwani <kkotwani@amazon.com>
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

*
* @opensearch.internal
*/
public class LocalShardsBalancer extends ShardsBalancer {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure how conservative we need to be here, but in the interest of compatibility it seems like we could leave the inner class 'Balancer' in place with its current name and just change it to extend the newly introduced interface. These things are tagged opensearch.internal but that doesn't mean they aren't used somewhere (though I couldn't find any usage of Balancer in any other repo in opensearch-project). What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. Why do we want to expose the Balancer outside BalancedShardAllocator
  2. Can we use a factory for Balancer creation?

Copy link
Member

Choose a reason for hiding this comment

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

Why do we want to expose the Balancer outside BalancedShardAllocator

I don't think we want to, but it is already used in org.opensearch.cluster.routing.allocation.AllocationConstraints which requires it to be public.

Can we use a factory for Balancer creation?

The approach here (#4759) calls for having 2 balancers with one running after the other, so I'm not sure a factory would help.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure how conservative we need to be here, but in the interest of compatibility it seems like we could leave the inner class 'Balancer' in place with its current name and just change it to extend the newly introduced interface. These things are tagged opensearch.internal but that doesn't mean they aren't used somewhere (though I couldn't find any usage of Balancer in any other repo in opensearch-project). What do you think?

I wanted to improve the readability and maintainability by splitting it across appropriate classes. We can keep LocalShardsBalancer and BalancedShardsAllocator.Balancer and deprecate the latter. We can get rid of it with 3.0.0.

Signed-off-by: Kunal Kotwani <kkotwani@amazon.com>
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

*
* @opensearch.internal
*/
public class LocalShardsBalancer extends ShardsBalancer {
Copy link
Member

Choose a reason for hiding this comment

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

nit - Make this class final?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good suggestion. I recently updated the PR to add back the Balancer class to maintain BWC, which essentially extends LocalShardsBalancer.
I'll do that with v3.0 when we get rid of the Balancer class.

@kotwanikunal kotwanikunal merged commit 1d65485 into opensearch-project:main Oct 17, 2022
@kotwanikunal kotwanikunal added the backport 2.x Backport to 2.x branch label Oct 17, 2022
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-4761-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 1d654851ff2ea50b0fbb07b7602945f3a0e4cc88
# Push it to GitHub
git push --set-upstream origin backport/backport-4761-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-4761-to-2.x.

kotwanikunal added a commit to kotwanikunal/OpenSearch that referenced this pull request Oct 17, 2022
…h-project#4761)

* Refactor BalancedAllocator.Balancer to LocalShardsBalancer

Signed-off-by: Kunal Kotwani <kkotwani@amazon.com>

* Deprecate Balancer to maintain BWC

Signed-off-by: Kunal Kotwani <kkotwani@amazon.com>

Signed-off-by: Kunal Kotwani <kkotwani@amazon.com>
(cherry picked from commit 1d65485)
kotwanikunal added a commit to kotwanikunal/OpenSearch that referenced this pull request Oct 19, 2022
…h-project#4761)

* Refactor BalancedAllocator.Balancer to LocalShardsBalancer

Signed-off-by: Kunal Kotwani <kkotwani@amazon.com>

* Deprecate Balancer to maintain BWC

Signed-off-by: Kunal Kotwani <kkotwani@amazon.com>

Signed-off-by: Kunal Kotwani <kkotwani@amazon.com>
(cherry picked from commit 1d65485)
andrross pushed a commit that referenced this pull request Oct 19, 2022
…4818)

* Refactor BalancedAllocator.Balancer to LocalShardsBalancer (#4761)

* Refactor BalancedAllocator.Balancer to LocalShardsBalancer

Signed-off-by: Kunal Kotwani <kkotwani@amazon.com>

* Deprecate Balancer to maintain BWC

Signed-off-by: Kunal Kotwani <kkotwani@amazon.com>

Signed-off-by: Kunal Kotwani <kkotwani@amazon.com>
(cherry picked from commit 1d65485)

* Update changelog

Signed-off-by: Kunal Kotwani <kkotwani@amazon.com>

Signed-off-by: Kunal Kotwani <kkotwani@amazon.com>
ashking94 pushed a commit to ashking94/OpenSearch that referenced this pull request Nov 7, 2022
…h-project#4761)

* Refactor BalancedAllocator.Balancer to LocalShardsBalancer

Signed-off-by: Kunal Kotwani <kkotwani@amazon.com>

* Deprecate Balancer to maintain BWC

Signed-off-by: Kunal Kotwani <kkotwani@amazon.com>

Signed-off-by: Kunal Kotwani <kkotwani@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants