• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

grpc / grpc-java / #19406

07 Aug 2024 12:12AM CUT coverage: 84.485% (+0.02%) from 84.464%
#19406

push

github

web-flow
Revert "Enable new PickFirst LB (#11348)" (#11425) (#11448)

This reverts commit ccfd351a2.

33249 of 39355 relevant lines covered (84.48%)

0.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.43
/../core/src/main/java/io/grpc/internal/PickFirstLoadBalancerProvider.java
1
/*
2
 * Copyright 2018 The gRPC Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package io.grpc.internal;
18

19
import com.google.common.annotations.VisibleForTesting;
20
import io.grpc.LoadBalancer;
21
import io.grpc.LoadBalancerProvider;
22
import io.grpc.NameResolver;
23
import io.grpc.NameResolver.ConfigOrError;
24
import io.grpc.Status;
25
import io.grpc.internal.PickFirstLeafLoadBalancer.PickFirstLeafLoadBalancerConfig;
26
import io.grpc.internal.PickFirstLoadBalancer.PickFirstLoadBalancerConfig;
27
import java.util.Map;
28

29
/**
30
 * Provider for the "pick_first" balancing policy.
31
 *
32
 * <p>This provides no load-balancing over the addresses from the {@link NameResolver}.  It walks
33
 * down the address list and sticks to the first that works.
34
 */
35
public final class PickFirstLoadBalancerProvider extends LoadBalancerProvider {
1✔
36
  public static final String GRPC_PF_USE_HAPPY_EYEBALLS = "GRPC_PF_USE_HAPPY_EYEBALLS";
37
  private static final String SHUFFLE_ADDRESS_LIST_KEY = "shuffleAddressList";
38

39
  private static boolean enableNewPickFirst =
1✔
40
      GrpcUtil.getFlag("GRPC_EXPERIMENTAL_ENABLE_NEW_PICK_FIRST", false);
1✔
41

42
  public static boolean isEnabledHappyEyeballs() {
43

44
    return GrpcUtil.getFlag(GRPC_PF_USE_HAPPY_EYEBALLS, false);
1✔
45
  }
46

47
  @Override
48
  public boolean isAvailable() {
49
    return true;
1✔
50
  }
51

52
  @Override
53
  public int getPriority() {
54
    return 5;
1✔
55
  }
56

57
  @Override
58
  public String getPolicyName() {
59
    return "pick_first";
1✔
60
  }
61

62
  @Override
63
  public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
64
    if (enableNewPickFirst) {
1✔
65
      return new PickFirstLeafLoadBalancer(helper);
×
66
    } else {
67
      return new PickFirstLoadBalancer(helper);
1✔
68
    }
69
  }
70

71
  @Override
72
  public ConfigOrError parseLoadBalancingPolicyConfig(Map<String, ?> rawLbPolicyConfig) {
73
    try {
74
      Object config = getLbPolicyConfig(rawLbPolicyConfig);
1✔
75
      return ConfigOrError.fromConfig(config);
1✔
76
    } catch (RuntimeException e) {
×
77
      return ConfigOrError.fromError(
×
78
          Status.UNAVAILABLE.withCause(e).withDescription(
×
79
              "Failed parsing configuration for " + getPolicyName()));
×
80
    }
81
  }
82

83
  private static Object getLbPolicyConfig(Map<String, ?> rawLbPolicyConfig) {
84
    Boolean shuffleAddressList = JsonUtil.getBoolean(rawLbPolicyConfig, SHUFFLE_ADDRESS_LIST_KEY);
1✔
85
    if (enableNewPickFirst) {
1✔
86
      return new PickFirstLeafLoadBalancerConfig(shuffleAddressList);
×
87
    } else {
88
      return new PickFirstLoadBalancerConfig(shuffleAddressList);
1✔
89
    }
90
  }
91

92
  @VisibleForTesting
93
  public static boolean isEnabledNewPickFirst() {
94
    return enableNewPickFirst;
1✔
95
  }
96
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc