Skip to content

Commit

Permalink
Further reduce pick_first state space
Browse files Browse the repository at this point in the history
  • Loading branch information
murgatroid99 committed Aug 2, 2024
1 parent a6575c3 commit 3d43b1a
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions packages/grpc-js/src/load-balancer-pick-first.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
*/
private connectionDelayTimeout: NodeJS.Timeout;

private triedAllSubchannels = false;

/**
* The LB policy enters sticky TRANSIENT_FAILURE mode when all
* subchannels have failed to connect at least once, and it stays in that
Expand All @@ -225,12 +223,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {

private reportHealthStatus: boolean;

/**
* Indicates whether we called channelControlHelper.requestReresolution since
* the last call to updateAddressList
*/
private requestedResolutionSinceLastUpdate = false;

/**
* The most recent error reported by any subchannel as it transitioned to
* TRANSIENT_FAILURE.
Expand Down Expand Up @@ -259,6 +251,10 @@ export class PickFirstLoadBalancer implements LoadBalancer {
return this.children.every(child => child.hasReportedTransientFailure);
}

private resetChildrenReportedTF() {
this.children.every(child => child.hasReportedTransientFailure = false);
}

private calculateAndReportNewState() {
if (this.currentPick) {
if (this.reportHealthStatus && !this.currentPick.isHealthy()) {
Expand Down Expand Up @@ -291,23 +287,15 @@ export class PickFirstLoadBalancer implements LoadBalancer {
}

private requestReresolution() {
this.requestedResolutionSinceLastUpdate = true;
this.channelControlHelper.requestReresolution();
}

private maybeEnterStickyTransientFailureMode() {
if (!this.allChildrenHaveReportedTF()) {
return;
}
if (!this.requestedResolutionSinceLastUpdate) {
/* Each time we get an update we reset each subchannel's
* hasReportedTransientFailure flag, so the next time we get to this
* point after that, each subchannel has reported TRANSIENT_FAILURE
* at least once since then. That is the trigger for requesting
* reresolution, whether or not the LB policy is already in sticky TF
* mode. */
this.requestReresolution();
}
this.requestReresolution();
this.resetChildrenReportedTF();
if (this.stickyTransientFailureMode) {
return;
}
Expand Down Expand Up @@ -369,9 +357,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {

private startNextSubchannelConnecting(startIndex: number) {
clearTimeout(this.connectionDelayTimeout);
if (this.triedAllSubchannels) {
return;
}
for (const [index, child] of this.children.entries()) {
if (index >= startIndex) {
const subchannelState = child.subchannel.getConnectivityState();
Expand All @@ -384,7 +369,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
}
}
}
this.triedAllSubchannels = true;
this.maybeEnterStickyTransientFailureMode();
}

Expand Down Expand Up @@ -464,8 +448,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
}
this.currentSubchannelIndex = 0;
this.children = [];
this.triedAllSubchannels = false;
this.requestedResolutionSinceLastUpdate = false;
}

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

0 comments on commit 3d43b1a

Please sign in to comment.