Skip to content

balacergroup: cleanup exitIdle()#8347

Merged
arjan-bal merged 6 commits intogrpc:masterfrom
hugehoo:balacergroup-exitidle
May 26, 2025
Merged

balacergroup: cleanup exitIdle()#8347
arjan-bal merged 6 commits intogrpc:masterfrom
hugehoo:balacergroup-exitidle

Conversation

@hugehoo
Copy link
Contributor

@hugehoo hugehoo commented May 21, 2025

context

exitIdle() is called in both ExitIdle() and ExitIdleOne()

func (bg *BalancerGroup) ExitIdle() {
	bg.outgoingMu.Lock()
	defer bg.outgoingMu.Unlock()
	if bg.outgoingClosed {
		return
	}
	for _, config := range bg.idToBalancerConfig {
		if !config.exitIdle() { // here
			bg.connect(config)
		}
	}
}

func (bg *BalancerGroup) ExitIdleOne(id string) {
	bg.outgoingMu.Lock()
	defer bg.outgoingMu.Unlock()
	if bg.outgoingClosed {
		return
	}
	if config := bg.idToBalancerConfig[id]; config != nil {
		if !config.exitIdle() { // here
			bg.connect(config)
		}
	}
}

it returns boolean value. if it returns false if-statement works.
But the current implementation of exitIdle() is returning only true.

As-Is

exitIdle method returns boolean type but implementation returns only true.

func (sbc *subBalancerWrapper) exitIdle() (complete bool) {
	b := sbc.balancer
	if b == nil {
		return true
	}
	b.ExitIdle()
	return true
}

To-be

so i simplified implementation as method only returns true.
And fixed comment too as Returns a true

// exitIdle invokes the sub-balancer's ExitIdle method. Returns a true
// indicating whether or not the operation was completed.
func (sbc *subBalancerWrapper) exitIdle() (complete bool) {
	if b := sbc.balancer; b != nil {
		b.ExitIdle()
	}
	return true
}

I'm not sure this refactoring is necessary but at least the comment on exitIdle seems to be updated.

RELEASE NOTES: N/A

@codecov
Copy link

codecov bot commented May 21, 2025

Codecov Report

Attention: Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 82.28%. Comparing base (32e57de) to head (827d468).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
internal/balancergroup/balancergroup.go 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8347      +/-   ##
==========================================
- Coverage   82.35%   82.28%   -0.07%     
==========================================
  Files         419      419              
  Lines       42034    42039       +5     
==========================================
- Hits        34615    34591      -24     
- Misses       5968     5985      +17     
- Partials     1451     1463      +12     
Files with missing lines Coverage Δ
internal/balancergroup/balancergroup.go 80.40% <75.00%> (+3.70%) ⬆️

... and 25 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


// exitIdle invokes the sub-balancer's ExitIdle method. Returns a boolean
// exitIdle invokes the sub-balancer's ExitIdle method. Returns a true
// indicating whether or not the operation was completed.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

nit) i suggest that whether or not to be whether.

@eshitachandwani eshitachandwani self-requested a review May 22, 2025 09:54
@eshitachandwani eshitachandwani self-assigned this May 22, 2025
b.ExitIdle()
}
b.ExitIdle()
return true

Choose a reason for hiding this comment

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

oh.. return true * 2 😅 hard to understand code.. refactor +1!

Copy link
Member

@eshitachandwani eshitachandwani left a comment

Choose a reason for hiding this comment

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

Hey @hugehoo , thank you for the PR , I have a few suggestions since the code has changed.
Since the function only returns true , you can change it to not return anything and just call ExitIdle and also remove the condition in balancerGroup because it is never executed and the functionality of connecting to all subconns has been passed down to gracefulSwitch Balancer and since the balancer in subBalancerWrapper has been changed to gracefulSwitch balancer, it will always have ExitIdle function:

func (sbc *subBalancerWrapper) exitIdle(){
	b := sbc.balancer
	if b == nil {
		return
	}
	b.ExitIdle()
}

And change the these parts as follows:

if config := bg.idToBalancerConfig[id]; config != nil {
	config.exitIdle()
}

@eshitachandwani eshitachandwani added Type: Internal Cleanup Refactors, etc Area: Resolvers/Balancers Includes LB policy & NR APIs, resolver/balancer/picker wrappers, LB policy impls and utilities. labels May 23, 2025
@eshitachandwani eshitachandwani added this to the 1.74 Release milestone May 23, 2025
Copy link
Member

@eshitachandwani eshitachandwani left a comment

Choose a reason for hiding this comment

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

Also do add this to the description:
RELEASE NOTES: N/A

@hugehoo hugehoo force-pushed the balacergroup-exitidle branch from 9db880d to cdf756e Compare May 23, 2025 22:39
Comment on lines -414 to -427
// connect attempts to connect to all subConns belonging to sb.
func (bg *BalancerGroup) connect(sb *subBalancerWrapper) {
bg.incomingMu.Lock()
defer bg.incomingMu.Unlock()
if bg.incomingClosed {
return
}
for sc, b := range bg.scToSubBalancer {
if b == sb {
sc.Connect()
}
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i removed here, it fails CI-test because it's unused.
image

@hugehoo hugehoo requested a review from eshitachandwani May 23, 2025 22:57
Copy link
Member

@eshitachandwani eshitachandwani left a comment

Choose a reason for hiding this comment

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

nit) i suggest that whether or not to be whether.

Can you add a clarification in comments that the sub-balancer is a graceful switch balancer

// exitIdle invokes the sub-balancer's ExitIdle method. Returns a boolean
// indicating whether or not the operation was completed.
func (sbc *subBalancerWrapper) exitIdle() (complete bool) {
// exitIdle invokes the sub-balancer's ExitIdle method.
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a clarification in comments that the sub-balancer is a graceful switch balancer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eshitachandwani I added it 👍🏻

Copy link
Member

@eshitachandwani eshitachandwani left a comment

Choose a reason for hiding this comment

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

LGTM modulo one minor comment , adding @arjan-bal for another review.

@hugehoo hugehoo requested a review from eshitachandwani May 26, 2025 13:59
Comment on lines +109 to +110
// exitIdle invokes the sub-balancer's ExitIdle method
// which is a graceful switch balancer.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// exitIdle invokes the sub-balancer's ExitIdle method
// which is a graceful switch balancer.
// exitIdle invokes the ExitIdle method on the sub-balancer, a gracefulswitch
// balancer.

@arjan-bal arjan-bal changed the title refactoring balacergroup exitIdle() balacergroup: cleanup exitIdle() May 26, 2025
@arjan-bal
Copy link
Contributor

LGTM, thanks for the cleanup!

@arjan-bal arjan-bal merged commit 4cab0e6 into grpc:master May 26, 2025
23 of 24 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Area: Resolvers/Balancers Includes LB policy & NR APIs, resolver/balancer/picker wrappers, LB policy impls and utilities. Type: Internal Cleanup Refactors, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants