mirror of
https://github.com/grpc/grpc-node.git
synced 2025-12-08 18:23:54 +00:00
grpc-js-xds: delay picker updates while updating children in weighted target and xds_cluster_manager
This commit is contained in:
parent
1b1930f535
commit
3e6730cd24
@ -181,7 +181,7 @@ export class WeightedTargetLoadBalancer implements LoadBalancer {
|
||||
trace('Target ' + this.name + ' ' + ConnectivityState[this.connectivityState] + ' -> ' + ConnectivityState[connectivityState]);
|
||||
this.connectivityState = connectivityState;
|
||||
this.picker = picker;
|
||||
this.parent.updateState();
|
||||
this.parent.maybeUpdateState();
|
||||
}
|
||||
|
||||
updateAddressList(addressList: SubchannelAddress[], lbConfig: WeightedTarget, attributes: { [key: string]: unknown; }): void {
|
||||
@ -238,9 +238,16 @@ export class WeightedTargetLoadBalancer implements LoadBalancer {
|
||||
* List of current target names.
|
||||
*/
|
||||
private targetList: string[] = [];
|
||||
private updatesPaused = false;
|
||||
|
||||
constructor(private channelControlHelper: ChannelControlHelper) {}
|
||||
|
||||
private maybeUpdateState() {
|
||||
if (!this.updatesPaused) {
|
||||
this.updateState()
|
||||
}
|
||||
}
|
||||
|
||||
private updateState() {
|
||||
const pickerList: WeightedPicker[] = [];
|
||||
let end = 0;
|
||||
@ -343,6 +350,7 @@ export class WeightedTargetLoadBalancer implements LoadBalancer {
|
||||
childAddressList.push(childAddress);
|
||||
}
|
||||
|
||||
this.updatesPaused = true;
|
||||
this.targetList = Array.from(lbConfig.getTargets().keys());
|
||||
for (const [targetName, targetConfig] of lbConfig.getTargets()) {
|
||||
let target = this.targets.get(targetName);
|
||||
@ -364,6 +372,7 @@ export class WeightedTargetLoadBalancer implements LoadBalancer {
|
||||
target.deactivate();
|
||||
}
|
||||
}
|
||||
this.updatesPaused = false;
|
||||
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ class XdsClusterManager implements LoadBalancer {
|
||||
trace('Child ' + this.name + ' ' + ConnectivityState[this.connectivityState] + ' -> ' + ConnectivityState[connectivityState]);
|
||||
this.connectivityState = connectivityState;
|
||||
this.picker = picker;
|
||||
this.parent.updateState();
|
||||
this.parent.maybeUpdateState();
|
||||
}
|
||||
updateAddressList(addressList: SubchannelAddress[], lbConfig: ClusterManagerChild, attributes: { [key: string]: unknown; }): void {
|
||||
const childConfig = getFirstUsableConfig(lbConfig.child_policy);
|
||||
@ -173,8 +173,15 @@ class XdsClusterManager implements LoadBalancer {
|
||||
private children: Map<string, XdsClusterManagerChild> = new Map<string, XdsClusterManagerChild>();
|
||||
// Shutdown is a placeholder value that will never appear in normal operation.
|
||||
private currentState: ConnectivityState = ConnectivityState.SHUTDOWN;
|
||||
private updatesPaused = false;
|
||||
constructor(private channelControlHelper: ChannelControlHelper) {}
|
||||
|
||||
private maybeUpdateState() {
|
||||
if (!this.updatesPaused) {
|
||||
this.updateState();
|
||||
}
|
||||
}
|
||||
|
||||
private updateState() {
|
||||
const pickerMap: Map<string, Picker> = new Map<string, Picker>();
|
||||
let anyReady = false;
|
||||
@ -250,6 +257,7 @@ class XdsClusterManager implements LoadBalancer {
|
||||
namesToRemove.push(name);
|
||||
}
|
||||
}
|
||||
this.updatesPaused = true;
|
||||
for (const name of namesToRemove) {
|
||||
this.children.get(name)!.destroy();
|
||||
this.children.delete(name);
|
||||
@ -262,6 +270,7 @@ class XdsClusterManager implements LoadBalancer {
|
||||
this.children.set(name, newChild);
|
||||
}
|
||||
}
|
||||
this.updatesPaused = false;
|
||||
this.updateState();
|
||||
}
|
||||
exitIdle(): void {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user