Skip to content

Commit

Permalink
xds: Rename ring_hash LB Policy to ring_hash_experimental (#8776)
Browse files Browse the repository at this point in the history
Ring hash can only be used from within xds currently, because that's
the only way to get a hash assigned to RPCs which is required for it
to function. So it should be using the _experimental suffix like the
other only-used-from-xds policies.
  • Loading branch information
sergiitk committed Jan 7, 2022
1 parent d44de50 commit 23a2202
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion xds/src/main/java/io/grpc/xds/CdsLoadBalancer2.java
Expand Up @@ -187,7 +187,7 @@ private void handleClusterDiscovered() {
LoadBalancerProvider lbProvider = null;
Object lbConfig = null;
if (root.result.lbPolicy() == LbPolicy.RING_HASH) {
lbProvider = lbRegistry.getProvider("ring_hash");
lbProvider = lbRegistry.getProvider("ring_hash_experimental");
lbConfig = new RingHashConfig(root.result.minRingSize(), root.result.maxRingSize());
}
if (lbProvider == null) {
Expand Down
Expand Up @@ -672,7 +672,7 @@ private static PriorityChildConfig generateDnsBasedPriorityChildConfig(
* Generates configs to be used in the priority LB policy for priorities in an EDS cluster.
*
* <p>priority LB -> cluster_impl LB (one per priority) -> (weighted_target LB
* -> round_robin (one per locality)) / ring_hash
* -> round_robin (one per locality)) / ring_hash_experimental
*/
private static Map<String, PriorityChildConfig> generateEdsBasedPriorityChildConfigs(
String cluster, @Nullable String edsServiceName, @Nullable ServerInfo lrsServerInfo,
Expand All @@ -687,9 +687,9 @@ private static Map<String, PriorityChildConfig> generateEdsBasedPriorityChildCon
// created. If the endpoint-level LB policy is round_robin, it creates a two-level LB
// hierarchy: a locality-level LB policy that balances load according to locality weights
// followed by an endpoint-level LB policy that simply rounds robin the endpoints within
// the locality. If the endpoint-level LB policy is ring_hash, it creates a unified LB
// policy that balances load by weighing the product of each endpoint's weight and the
// weight of the locality it belongs to.
// the locality. If the endpoint-level LB policy is ring_hash_experimental, it creates
// a unified LB policy that balances load by weighing the product of each endpoint's weight
// and the weight of the locality it belongs to.
if (endpointLbPolicy.getProvider().getPolicyName().equals("round_robin")) {
Map<Locality, Integer> localityWeights = prioritizedLocalityWeights.get(priority);
Map<String, WeightedPolicySelection> targets = new HashMap<>();
Expand Down
Expand Up @@ -68,7 +68,7 @@ public LoadBalancer newLoadBalancer(Helper helper) {
static final class ClusterResolverConfig {
// Ordered list of clusters to be resolved.
final List<DiscoveryMechanism> discoveryMechanisms;
// Endpoint-level load balancing policy with config (round_robin or ring_hash).
// Endpoint-level load balancing policy with config (round_robin or ring_hash_experimental).
final PolicySelection lbPolicy;

ClusterResolverConfig(List<DiscoveryMechanism> discoveryMechanisms, PolicySelection lbPolicy) {
Expand Down
Expand Up @@ -29,7 +29,7 @@
import java.util.Map;

/**
* The provider for the "ring_hash" balancing policy.
* The provider for the "ring_hash_experimental" balancing policy.
*/
@Internal
public final class RingHashLoadBalancerProvider extends LoadBalancerProvider {
Expand Down Expand Up @@ -66,7 +66,7 @@ public int getPriority() {

@Override
public String getPolicyName() {
return "ring_hash";
return "ring_hash_experimental";
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions xds/src/main/java/io/grpc/xds/XdsClient.java
Expand Up @@ -113,10 +113,10 @@ abstract static class CdsUpdate implements ResourceUpdate {
// Endpoint-level load balancing policy.
abstract LbPolicy lbPolicy();

// Only valid if lbPolicy is "ring_hash".
// Only valid if lbPolicy is "ring_hash_experimental".
abstract long minRingSize();

// Only valid if lbPolicy is "ring_hash".
// Only valid if lbPolicy is "ring_hash_experimental".
abstract long maxRingSize();

// Alternative resource name to be used in EDS requests.
Expand Down
4 changes: 2 additions & 2 deletions xds/src/test/java/io/grpc/xds/CdsLoadBalancer2Test.java
Expand Up @@ -120,7 +120,7 @@ public void setUp() {
when(helper.getSynchronizationContext()).thenReturn(syncContext);
lbRegistry.register(new FakeLoadBalancerProvider(CLUSTER_RESOLVER_POLICY_NAME));
lbRegistry.register(new FakeLoadBalancerProvider("round_robin"));
lbRegistry.register(new FakeLoadBalancerProvider("ring_hash"));
lbRegistry.register(new FakeLoadBalancerProvider("ring_hash_experimental"));
loadBalancer = new CdsLoadBalancer2(helper, lbRegistry);
loadBalancer.handleResolvedAddresses(
ResolvedAddresses.newBuilder()
Expand Down Expand Up @@ -283,7 +283,7 @@ public void discoverAggregateCluster() {
assertDiscoveryMechanism(childLbConfig.discoveryMechanisms.get(2), cluster4,
DiscoveryMechanism.Type.EDS, null, null, LRS_SERVER_INFO, 300L, null);
assertThat(childLbConfig.lbPolicy.getProvider().getPolicyName())
.isEqualTo("ring_hash"); // dominated by top-level cluster's config
.isEqualTo("ring_hash_experimental"); // dominated by top-level cluster's config
assertThat(((RingHashConfig) childLbConfig.lbPolicy.getConfig()).minRingSize).isEqualTo(100L);
assertThat(((RingHashConfig) childLbConfig.lbPolicy.getConfig()).maxRingSize).isEqualTo(1000L);
}
Expand Down
4 changes: 2 additions & 2 deletions xds/src/test/java/io/grpc/xds/ClientXdsClientTestBase.java
Expand Up @@ -1483,8 +1483,8 @@ public void cdsResourceFound_ringHashLbPolicy() {
DiscoveryRpcCall call = startResourceWatcher(CDS, CDS_RESOURCE, cdsResourceWatcher);
Message ringHashConfig = mf.buildRingHashLbConfig("xx_hash", 10L, 100L);
Any clusterRingHash = Any.pack(
mf.buildEdsCluster(CDS_RESOURCE, null, "ring_hash", ringHashConfig, false, null,
"envoy.transport_sockets.tls", null
mf.buildEdsCluster(CDS_RESOURCE, null, "ring_hash_experimental", ringHashConfig, false,
null, "envoy.transport_sockets.tls", null
));
call.sendResponse(ResourceType.CDS, clusterRingHash, VERSION_1, "0000");

Expand Down
4 changes: 2 additions & 2 deletions xds/src/test/java/io/grpc/xds/ClientXdsClientV2Test.java
Expand Up @@ -438,7 +438,7 @@ protected Message buildAggregateCluster(String clusterName, String lbPolicy,
Cluster.Builder builder = Cluster.newBuilder().setName(clusterName).setClusterType(type);
if (lbPolicy.equals("round_robin")) {
builder.setLbPolicy(LbPolicy.ROUND_ROBIN);
} else if (lbPolicy.equals("ring_hash")) {
} else if (lbPolicy.equals("ring_hash_experimental")) {
builder.setLbPolicy(LbPolicy.RING_HASH);
builder.setRingHashLbConfig((RingHashLbConfig) ringHashLbConfig);
} else {
Expand All @@ -454,7 +454,7 @@ private Cluster.Builder initClusterBuilder(String clusterName, String lbPolicy,
builder.setName(clusterName);
if (lbPolicy.equals("round_robin")) {
builder.setLbPolicy(LbPolicy.ROUND_ROBIN);
} else if (lbPolicy.equals("ring_hash")) {
} else if (lbPolicy.equals("ring_hash_experimental")) {
builder.setLbPolicy(LbPolicy.RING_HASH);
builder.setRingHashLbConfig((RingHashLbConfig) ringHashLbConfig);
} else {
Expand Down
4 changes: 2 additions & 2 deletions xds/src/test/java/io/grpc/xds/ClientXdsClientV3Test.java
Expand Up @@ -494,7 +494,7 @@ protected Message buildAggregateCluster(String clusterName, String lbPolicy,
Cluster.Builder builder = Cluster.newBuilder().setName(clusterName).setClusterType(type);
if (lbPolicy.equals("round_robin")) {
builder.setLbPolicy(LbPolicy.ROUND_ROBIN);
} else if (lbPolicy.equals("ring_hash")) {
} else if (lbPolicy.equals("ring_hash_experimental")) {
builder.setLbPolicy(LbPolicy.RING_HASH);
builder.setRingHashLbConfig((RingHashLbConfig) ringHashLbConfig);
} else {
Expand All @@ -511,7 +511,7 @@ private Cluster.Builder initClusterBuilder(String clusterName, String lbPolicy,
builder.setName(clusterName);
if (lbPolicy.equals("round_robin")) {
builder.setLbPolicy(LbPolicy.ROUND_ROBIN);
} else if (lbPolicy.equals("ring_hash")) {
} else if (lbPolicy.equals("ring_hash_experimental")) {
builder.setLbPolicy(LbPolicy.RING_HASH);
builder.setRingHashLbConfig((RingHashLbConfig) ringHashLbConfig);
} else {
Expand Down
Expand Up @@ -135,7 +135,7 @@ public void uncaughtException(Thread t, Throwable e) {
private final PolicySelection roundRobin =
new PolicySelection(new FakeLoadBalancerProvider("round_robin"), null);
private final PolicySelection ringHash = new PolicySelection(
new FakeLoadBalancerProvider("ring_hash"), new RingHashConfig(10L, 100L));
new FakeLoadBalancerProvider("ring_hash_experimental"), new RingHashConfig(10L, 100L));
private final List<FakeLoadBalancer> childBalancers = new ArrayList<>();
private final List<FakeNameResolver> resolvers = new ArrayList<>();
private final FakeXdsClient xdsClient = new FakeXdsClient();
Expand Down Expand Up @@ -260,7 +260,7 @@ public void edsClustersWithRingHashEndpointLbPolicy() {
ClusterImplConfig clusterImplConfig =
(ClusterImplConfig) priorityChildConfig.policySelection.getConfig();
assertClusterImplConfig(clusterImplConfig, CLUSTER1, EDS_SERVICE_NAME1, LRS_SERVER_INFO, 100L,
tlsContext, Collections.<DropOverload>emptyList(), "ring_hash");
tlsContext, Collections.<DropOverload>emptyList(), "ring_hash_experimental");
RingHashConfig ringHashConfig =
(RingHashConfig) clusterImplConfig.childPolicy.getConfig();
assertThat(ringHashConfig.minRingSize).isEqualTo(10L);
Expand Down

0 comments on commit 23a2202

Please sign in to comment.