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

xds: ignore balancing state update from downstream after LB shutdown #8134

Conversation

voidzcy
Copy link
Contributor

@voidzcy voidzcy commented May 3, 2021

Similar correspondence of #8132 for xDS.

LoadBalancers should not propagate balancing state updates after itself being shutdown.

For LB policies that maintain a group of child LB policies with each having its independent lifetime, balancing state update propagations from each child LB policy can go out of the lifetime of its parent easily, especially for cases that balancing state update is put to the back of the queue and not propagated up inline.

For LBs that are simple pass-through in the middle of the LB tree structure, it isn't a big issue as its lifecycle would be the same as its child. Transitively, It would behave correctly as long as its downstream is doing in the right way.

This change is a sanity cleanup for LB policies that maintain multiple child LB policies to preserve the invariant that further balancing state updates from their child policies will not get propagated.

…he entire priority load balancer is shut down.
…after the entire weighted-target load balancer is shut down.
@voidzcy voidzcy force-pushed the bugfix/ignore_balancing_state_update_after_lb_shutdown branch from e6efda3 to 97515bb Compare May 3, 2021 19:48
@voidzcy voidzcy requested a review from dapengzhang0 May 4, 2021 01:29
@@ -98,6 +100,7 @@ public void setUp() {
lbConfigInventory.put("childB", new Object());
lbConfigInventory.put("childC", null);
clusterManagerLoadBalancer = new ClusterManagerLoadBalancer(helper);
reset(helper);
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a code smell. The javadoc says "The only reason we added reset() method is to make it possible to work with container-injected mocks."

The purpose here seems to be Mockito.clearInvocations(helper), which should also be avoided as much as possible, unless you are unable to efficiently test your program.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to throw away the interactions happened in the constructor (aka, calling the getters such as getSynchronizationContext() on Helper). We don't care those interactions, so just reset the mock memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to throw away the interactions happened in the constructor (aka, calling the getters such as getSynchronizationContext() on Helper). We don't care those interactions, so just reset the mock memory.

Copy link
Member

Choose a reason for hiding this comment

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

This is to throw away the interactions

Mockito.clearInvocations(helper) is more appropriate than reset().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, changed to use Mockito.clearInvocations().

There isn't much difference in this case. reset() is potential code smell if it is used in the middle of a test method as it probably means it is trying to verify too much. Similar to this answer, the usages of reset() in our case seems legit.

@voidzcy voidzcy merged commit fcaf9a9 into grpc:master May 4, 2021
voidzcy added a commit to voidzcy/grpc-java that referenced this pull request May 10, 2021
…rpc#8134)

LoadBalancers should not propagate balancing state updates after itself being shutdown.

For LB policies that maintain a group of child LB policies with each having its independent lifetime, balancing state update propagations from each child LB policy can go out of the lifetime of its parent easily, especially for cases that balancing state update is put to the back of the queue and not propagated up inline.

For LBs that are simple pass-through in the middle of the LB tree structure, it isn't a big issue as its lifecycle would be the same as its child. Transitively, It would behave correctly as long as its downstream is doing in the right way.

This change is a sanity cleanup for LB policies that maintain multiple child LB policies to preserve the invariant that further balancing state updates from their child policies will not get propagated.
voidzcy added a commit that referenced this pull request May 10, 2021
…(v1.37 backport) (#8134) (#8156)

LoadBalancers should not propagate balancing state updates after itself being shutdown.

For LB policies that maintain a group of child LB policies with each having its independent lifetime, balancing state update propagations from each child LB policy can go out of the lifetime of its parent easily, especially for cases that balancing state update is put to the back of the queue and not propagated up inline.

For LBs that are simple pass-through in the middle of the LB tree structure, it isn't a big issue as its lifecycle would be the same as its child. Transitively, It would behave correctly as long as its downstream is doing in the right way.

This change is a sanity cleanup for LB policies that maintain multiple child LB policies to preserve the invariant that further balancing state updates from their child policies will not get propagated.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants