MCPcopy Create free account
hub / github.com/grpc/grpc-java / GrpclbState

Class GrpclbState

grpclb/src/main/java/io/grpc/grpclb/GrpclbState.java:90–1281  ·  view source on GitHub ↗

The states of a GRPCLB working session of GrpclbLoadBalancer. Created when GrpclbLoadBalancer switches to GRPCLB mode. Closed and discarded when GrpclbLoadBalancer switches away from GRPCLB mode.

Source from the content-addressed store, hash-verified

88 * switches away from GRPCLB mode.
89 */
90@NotThreadSafe
91final class GrpclbState {
92 static final long FALLBACK_TIMEOUT_MS = TimeUnit.SECONDS.toMillis(10);
93 private static final Attributes LB_PROVIDED_BACKEND_ATTRS =
94 Attributes.newBuilder().set(GrpclbConstants.ATTR_LB_PROVIDED_BACKEND, true).build();
95
96 // Temporary workaround to reduce log spam for a grpclb server that incessantly sends updates
97 // Tracked by b/198440401
98 static final boolean SHOULD_LOG_SERVER_LISTS =
99 Boolean.parseBoolean(System.getProperty("io.grpc.grpclb.LogServerLists", "true"));
100
101 @VisibleForTesting
102 static final PickResult DROP_PICK_RESULT =
103 PickResult.withDrop(Status.UNAVAILABLE.withDescription("Dropped as requested by balancer"));
104 @VisibleForTesting
105 static final Status NO_AVAILABLE_BACKENDS_STATUS =
106 Status.UNAVAILABLE.withDescription("LoadBalancer responded without any backends");
107 @VisibleForTesting
108 static final Status BALANCER_TIMEOUT_STATUS =
109 Status.UNAVAILABLE.withDescription("Timeout waiting for remote balancer");
110 @VisibleForTesting
111 static final Status BALANCER_REQUESTED_FALLBACK_STATUS =
112 Status.UNAVAILABLE.withDescription("Fallback requested by balancer");
113 @VisibleForTesting
114 static final Status NO_FALLBACK_BACKENDS_STATUS =
115 Status.UNAVAILABLE.withDescription("Unable to fallback, no fallback addresses found");
116 // This error status should never be propagated to RPC failures, as "no backend or balancer
117 // addresses found" should be directly handled as a name resolution error. So in cases of no
118 // balancer address, fallback should never fail.
119 private static final Status NO_LB_ADDRESS_PROVIDED_STATUS =
120 Status.UNAVAILABLE.withDescription("No balancer address found");
121
122
123 @VisibleForTesting
124 static final RoundRobinEntry BUFFER_ENTRY = new RoundRobinEntry() {
125 @Override
126 public PickResult picked(PickSubchannelArgs args) {
127 return PickResult.withNoResult();
128 }
129
130 @Override
131 public String toString() {
132 return "BUFFER_ENTRY";
133 }
134 };
135 @VisibleForTesting
136 static final String NO_USE_AUTHORITY_SUFFIX = "-notIntendedToBeUsed";
137
138 enum Mode {
139 ROUND_ROBIN,
140 PICK_FIRST,
141 }
142
143 private final String serviceName;
144 private final long fallbackTimeoutMs;
145 private final Helper helper;
146 private final Context context;
147 private final SynchronizationContext syncContext;

Callers

nothing calls this directly

Calls 11

newBuilderMethod · 0.95
withDropMethod · 0.95
withNoResultMethod · 0.95
parseBooleanMethod · 0.80
getPropertyMethod · 0.80
withDescriptionMethod · 0.80
emptyListMethod · 0.80
asListMethod · 0.80
buildMethod · 0.65
setMethod · 0.65
createMethod · 0.65

Tested by

no test coverage detected