Skip to content

Commit 3d43b1a

Browse files
committed
Further reduce pick_first state space
1 parent a6575c3 commit 3d43b1a

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

packages/grpc-js/src/load-balancer-pick-first.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
213213
*/
214214
private connectionDelayTimeout: NodeJS.Timeout;
215215

216-
private triedAllSubchannels = false;
217-
218216
/**
219217
* The LB policy enters sticky TRANSIENT_FAILURE mode when all
220218
* subchannels have failed to connect at least once, and it stays in that
@@ -225,12 +223,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
225223

226224
private reportHealthStatus: boolean;
227225

228-
/**
229-
* Indicates whether we called channelControlHelper.requestReresolution since
230-
* the last call to updateAddressList
231-
*/
232-
private requestedResolutionSinceLastUpdate = false;
233-
234226
/**
235227
* The most recent error reported by any subchannel as it transitioned to
236228
* TRANSIENT_FAILURE.
@@ -259,6 +251,10 @@ export class PickFirstLoadBalancer implements LoadBalancer {
259251
return this.children.every(child => child.hasReportedTransientFailure);
260252
}
261253

254+
private resetChildrenReportedTF() {
255+
this.children.every(child => child.hasReportedTransientFailure = false);
256+
}
257+
262258
private calculateAndReportNewState() {
263259
if (this.currentPick) {
264260
if (this.reportHealthStatus && !this.currentPick.isHealthy()) {
@@ -291,23 +287,15 @@ export class PickFirstLoadBalancer implements LoadBalancer {
291287
}
292288

293289
private requestReresolution() {
294-
this.requestedResolutionSinceLastUpdate = true;
295290
this.channelControlHelper.requestReresolution();
296291
}
297292

298293
private maybeEnterStickyTransientFailureMode() {
299294
if (!this.allChildrenHaveReportedTF()) {
300295
return;
301296
}
302-
if (!this.requestedResolutionSinceLastUpdate) {
303-
/* Each time we get an update we reset each subchannel's
304-
* hasReportedTransientFailure flag, so the next time we get to this
305-
* point after that, each subchannel has reported TRANSIENT_FAILURE
306-
* at least once since then. That is the trigger for requesting
307-
* reresolution, whether or not the LB policy is already in sticky TF
308-
* mode. */
309-
this.requestReresolution();
310-
}
297+
this.requestReresolution();
298+
this.resetChildrenReportedTF();
311299
if (this.stickyTransientFailureMode) {
312300
return;
313301
}
@@ -369,9 +357,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
369357

370358
private startNextSubchannelConnecting(startIndex: number) {
371359
clearTimeout(this.connectionDelayTimeout);
372-
if (this.triedAllSubchannels) {
373-
return;
374-
}
375360
for (const [index, child] of this.children.entries()) {
376361
if (index >= startIndex) {
377362
const subchannelState = child.subchannel.getConnectivityState();
@@ -384,7 +369,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
384369
}
385370
}
386371
}
387-
this.triedAllSubchannels = true;
388372
this.maybeEnterStickyTransientFailureMode();
389373
}
390374

@@ -464,8 +448,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
464448
}
465449
this.currentSubchannelIndex = 0;
466450
this.children = [];
467-
this.triedAllSubchannels = false;
468-
this.requestedResolutionSinceLastUpdate = false;
469451
}
470452

471453
private connectToAddressList(addressList: SubchannelAddress[]) {
@@ -511,7 +493,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
511493
if (!(lbConfig instanceof PickFirstLoadBalancingConfig)) {
512494
return;
513495
}
514-
this.requestedResolutionSinceLastUpdate = false;
515496
/* Previously, an update would be discarded if it was identical to the
516497
* previous update, to minimize churn. Now the DNS resolver is
517498
* rate-limited, so that is less of a concern. */

0 commit comments

Comments
 (0)