Skip to content

Commit 3a43cba

Browse files
committed
grpc-js-xds: Implement ring_hash LB policy
1 parent 3096f22 commit 3a43cba

30 files changed

+1081
-204
lines changed

packages/grpc-js-xds/gulpfile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const compile = checkTask(() => execNpmCommand('compile'));
6363
const runTests = checkTask(() => {
6464
process.env.GRPC_EXPERIMENTAL_XDS_FEDERATION = 'true';
6565
process.env.GRPC_EXPERIMENTAL_XDS_CUSTOM_LB_CONFIG = 'true';
66+
process.env.GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH = 'true';
6667
return gulp.src(`${outDir}/test/**/*.js`)
6768
.pipe(mocha({reporter: 'mocha-jenkins-reporter',
6869
require: ['ts-node/register']}));

packages/grpc-js-xds/src/environment.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ export const EXPERIMENTAL_OUTLIER_DETECTION = (process.env.GRPC_EXPERIMENTAL_ENA
2020
export const EXPERIMENTAL_RETRY = (process.env.GRPC_XDS_EXPERIMENTAL_ENABLE_RETRY ?? 'true') === 'true';
2121
export const EXPERIMENTAL_FEDERATION = (process.env.GRPC_EXPERIMENTAL_XDS_FEDERATION ?? 'false') === 'true';
2222
export const EXPERIMENTAL_CUSTOM_LB_CONFIG = (process.env.GRPC_EXPERIMENTAL_XDS_CUSTOM_LB_CONFIG ?? 'false') === 'true';
23+
export const EXPERIMENTAL_RING_HASH = (process.env.GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH ?? 'false') === 'true';

packages/grpc-js-xds/src/http-filter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export function validateTopLevelFilter(httpFilter: HttpFilter__Output): boolean
116116
try {
117117
typeUrl = getTopLevelFilterUrl(encodedConfig);
118118
} catch (e) {
119-
trace(httpFilter.name + ' validation failed with error ' + e.message);
119+
trace(httpFilter.name + ' validation failed with error ' + (e as Error).message);
120120
return false;
121121
}
122122
const registryEntry = FILTER_REGISTRY.get(typeUrl);
@@ -243,4 +243,4 @@ export function createHttpFilter(config: HttpFilterConfig, overrideConfig?: Http
243243
} else {
244244
return null;
245245
}
246-
}
246+
}

packages/grpc-js-xds/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import * as load_balancer_priority from './load-balancer-priority';
2323
import * as load_balancer_weighted_target from './load-balancer-weighted-target';
2424
import * as load_balancer_xds_cluster_manager from './load-balancer-xds-cluster-manager';
2525
import * as xds_wrr_locality from './load-balancer-xds-wrr-locality';
26+
import * as ring_hash from './load-balancer-ring-hash';
2627
import * as router_filter from './http-filter/router-filter';
2728
import * as fault_injection_filter from './http-filter/fault-injection-filter';
2829
import * as csds from './csds';
@@ -41,6 +42,7 @@ export function register() {
4142
load_balancer_weighted_target.setup();
4243
load_balancer_xds_cluster_manager.setup();
4344
xds_wrr_locality.setup();
45+
ring_hash.setup();
4446
router_filter.setup();
4547
fault_injection_filter.setup();
4648
csds.setup();

packages/grpc-js-xds/src/load-balancer-priority.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,26 @@ const DEFAULT_FAILOVER_TIME_MS = 10_000;
4141
const DEFAULT_RETENTION_INTERVAL_MS = 15 * 60 * 1000;
4242

4343
export interface LocalityEndpoint extends Endpoint {
44+
/**
45+
* A sequence of strings that determines how to divide endpoints up in priority and
46+
* weighted_target.
47+
*/
4448
localityPath: string[];
49+
/**
50+
* The locality this endpoint is in. Used in wrr_locality and xds_cluster_impl.
51+
*/
4552
locality: Locality__Output;
46-
weight: number;
53+
/**
54+
* The load balancing weight for the entire locality that contains this
55+
* endpoint. Used in xds_wrr_locality.
56+
*/
57+
localityWeight: number;
58+
/**
59+
* The overall load balancing weight for this endpoint, calculated as the
60+
* product of the load balancing weight for this endpoint within its locality
61+
* and the load balancing weight of the locality. Used in ring_hash.
62+
*/
63+
endpointWeight: number;
4764
};
4865

4966
export function isLocalityEndpoint(
@@ -317,7 +334,7 @@ export class PriorityLoadBalancer implements LoadBalancer {
317334
* so that when the picker calls exitIdle, that in turn calls exitIdle on
318335
* the PriorityChildImpl, which will start the failover timer. */
319336
if (state === ConnectivityState.IDLE) {
320-
picker = new QueuePicker(this);
337+
picker = new QueuePicker(this, picker);
321338
}
322339
this.channelControlHelper.updateState(state, picker);
323340
}

0 commit comments

Comments
 (0)