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

grpc / grpc-java / #19915

18 Jul 2025 04:05PM UTC coverage: 88.58% (-0.01%) from 88.593%
#19915

push

github

ejona86
xds: Implement equals in RingHashConfig

Lack of equals causes cluster_resolver to consider every update a
different configuration and restart itself.

b/430347751

34647 of 39114 relevant lines covered (88.58%)

0.89 hits per line

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

94.92
/../xds/src/main/java/io/grpc/xds/RingHashLoadBalancer.java
1
/*
2
 * Copyright 2021 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.xds;
18

19
import static com.google.common.base.Preconditions.checkArgument;
20
import static com.google.common.base.Preconditions.checkNotNull;
21
import static com.google.common.base.Preconditions.checkState;
22
import static io.grpc.ConnectivityState.CONNECTING;
23
import static io.grpc.ConnectivityState.IDLE;
24
import static io.grpc.ConnectivityState.READY;
25
import static io.grpc.ConnectivityState.SHUTDOWN;
26
import static io.grpc.ConnectivityState.TRANSIENT_FAILURE;
27

28
import com.google.common.annotations.VisibleForTesting;
29
import com.google.common.base.Joiner;
30
import com.google.common.base.MoreObjects;
31
import com.google.common.collect.HashMultiset;
32
import com.google.common.collect.Multiset;
33
import com.google.common.primitives.UnsignedInteger;
34
import io.grpc.Attributes;
35
import io.grpc.ConnectivityState;
36
import io.grpc.EquivalentAddressGroup;
37
import io.grpc.InternalLogId;
38
import io.grpc.LoadBalancer;
39
import io.grpc.Metadata;
40
import io.grpc.Status;
41
import io.grpc.SynchronizationContext;
42
import io.grpc.util.MultiChildLoadBalancer;
43
import io.grpc.xds.ThreadSafeRandom.ThreadSafeRandomImpl;
44
import io.grpc.xds.client.XdsLogger;
45
import io.grpc.xds.client.XdsLogger.XdsLogLevel;
46
import java.net.SocketAddress;
47
import java.util.ArrayList;
48
import java.util.Collection;
49
import java.util.Collections;
50
import java.util.HashMap;
51
import java.util.HashSet;
52
import java.util.List;
53
import java.util.Map;
54
import java.util.Objects;
55
import java.util.Set;
56
import java.util.stream.Collectors;
57
import javax.annotation.Nullable;
58

59
/**
60
 * A {@link LoadBalancer} that provides consistent hashing based load balancing to upstream hosts.
61
 * It implements the "Ketama" hashing that maps hosts onto a circle (the "ring") by hashing its
62
 * addresses. Each request is routed to a host by hashing some property of the request and finding
63
 * the nearest corresponding host clockwise around the ring. Each host is placed on the ring some
64
 * number of times proportional to its weight. With the ring partitioned appropriately, the
65
 * addition or removal of one host from a set of N hosts will affect only 1/N requests.
66
 */
67
final class RingHashLoadBalancer extends MultiChildLoadBalancer {
68
  private static final Status RPC_HASH_NOT_FOUND =
1✔
69
      Status.INTERNAL.withDescription("RPC hash not found. Probably a bug because xds resolver"
1✔
70
          + " config selector always generates a hash.");
71
  private static final XxHash64 hashFunc = XxHash64.INSTANCE;
1✔
72

73
  private final LoadBalancer.Factory lazyLbFactory =
1✔
74
      new LazyLoadBalancer.Factory(pickFirstLbProvider);
75
  private final XdsLogger logger;
76
  private final SynchronizationContext syncContext;
77
  private final ThreadSafeRandom random;
78
  private List<RingEntry> ring;
79
  @Nullable private Metadata.Key<String> requestHashHeaderKey;
80

81
  RingHashLoadBalancer(Helper helper) {
82
    this(helper, ThreadSafeRandomImpl.instance);
1✔
83
  }
1✔
84

85
  @VisibleForTesting
86
  RingHashLoadBalancer(Helper helper, ThreadSafeRandom random) {
87
    super(helper);
1✔
88
    syncContext = checkNotNull(helper.getSynchronizationContext(), "syncContext");
1✔
89
    logger = XdsLogger.withLogId(InternalLogId.allocate("ring_hash_lb", helper.getAuthority()));
1✔
90
    logger.log(XdsLogLevel.INFO, "Created");
1✔
91
    this.random = checkNotNull(random, "random");
1✔
92
  }
1✔
93

94
  @Override
95
  public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
96
    logger.log(XdsLogLevel.DEBUG, "Received resolution result: {0}", resolvedAddresses);
1✔
97
    List<EquivalentAddressGroup> addrList = resolvedAddresses.getAddresses();
1✔
98
    Status addressValidityStatus = validateAddrList(addrList);
1✔
99
    if (!addressValidityStatus.isOk()) {
1✔
100
      return addressValidityStatus;
1✔
101
    }
102

103
    // Now do the ringhash specific logic with weights and building the ring
104
    RingHashConfig config = (RingHashConfig) resolvedAddresses.getLoadBalancingPolicyConfig();
1✔
105
    if (config == null) {
1✔
106
      throw new IllegalArgumentException("Missing RingHash configuration");
×
107
    }
108
    requestHashHeaderKey =
1✔
109
        config.requestHashHeader.isEmpty()
1✔
110
            ? null
1✔
111
            : Metadata.Key.of(config.requestHashHeader, Metadata.ASCII_STRING_MARSHALLER);
1✔
112
    Map<EquivalentAddressGroup, Long> serverWeights = new HashMap<>();
1✔
113
    long totalWeight = 0L;
1✔
114
    for (EquivalentAddressGroup eag : addrList) {
1✔
115
      Long weight = eag.getAttributes().get(XdsAttributes.ATTR_SERVER_WEIGHT);
1✔
116
      // Support two ways of server weighing: either multiple instances of the same address
117
      // or each address contains a per-address weight attribute. If a weight is not provided,
118
      // each occurrence of the address will be counted a weight value of one.
119
      if (weight == null) {
1✔
120
        weight = 1L;
×
121
      }
122
      totalWeight += weight;
1✔
123
      EquivalentAddressGroup addrKey = stripAttrs(eag);
1✔
124
      if (serverWeights.containsKey(addrKey)) {
1✔
125
        serverWeights.put(addrKey, serverWeights.get(addrKey) + weight);
×
126
      } else {
127
        serverWeights.put(addrKey, weight);
1✔
128
      }
129
    }
1✔
130
    // Calculate scale
131
    long minWeight = Collections.min(serverWeights.values());
1✔
132
    double normalizedMinWeight = (double) minWeight / totalWeight;
1✔
133
    // Scale up the number of hashes per host such that the least-weighted host gets a whole
134
    // number of hashes on the the ring. Other hosts might not end up with whole numbers, and
135
    // that's fine (the ring-building algorithm can handle this). This preserves the original
136
    // implementation's behavior: when weights aren't provided, all hosts should get an equal
137
    // number of hashes. In the case where this number exceeds the max_ring_size, it's scaled
138
    // back down to fit.
139
    double scale = Math.min(
1✔
140
        Math.ceil(normalizedMinWeight * config.minRingSize) / normalizedMinWeight,
1✔
141
        (double) config.maxRingSize);
142

143
    // Build the ring
144
    ring = buildRing(serverWeights, totalWeight, scale);
1✔
145

146
    return super.acceptResolvedAddresses(resolvedAddresses);
1✔
147
  }
148

149

150
  /**
151
   * Updates the overall balancing state by aggregating the connectivity states of all subchannels.
152
   *
153
   * <p>Aggregation rules (in order of dominance):
154
   * <ol>
155
   *   <li>If there is at least one subchannel in READY state, overall state is READY</li>
156
   *   <li>If there are <em>2 or more</em> subchannels in TRANSIENT_FAILURE, overall state is
157
   *   TRANSIENT_FAILURE (to allow timely failover to another policy)</li>
158
   *   <li>If there is at least one subchannel in CONNECTING state, overall state is
159
   *   CONNECTING</li>
160
   *   <li> If there is one subchannel in TRANSIENT_FAILURE state and there is
161
   *    more than one subchannel, report CONNECTING </li>
162
   *   <li>If there is at least one subchannel in IDLE state, overall state is IDLE</li>
163
   *   <li>Otherwise, overall state is TRANSIENT_FAILURE</li>
164
   * </ol>
165
   */
166
  @Override
167
  protected void updateOverallBalancingState() {
168
    checkState(!getChildLbStates().isEmpty(), "no subchannel has been created");
1✔
169
    if (this.currentConnectivityState == SHUTDOWN) {
1✔
170
      // Ignore changes that happen after shutdown is called
171
      logger.log(XdsLogLevel.DEBUG, "UpdateOverallBalancingState called after shutdown");
×
172
      return;
×
173
    }
174

175
    // Calculate the current overall state to report
176
    int numIdle = 0;
1✔
177
    int numReady = 0;
1✔
178
    int numConnecting = 0;
1✔
179
    int numTF = 0;
1✔
180

181
    forloop:
182
    for (ChildLbState childLbState : getChildLbStates()) {
1✔
183
      ConnectivityState state = childLbState.getCurrentState();
1✔
184
      switch (state) {
1✔
185
        case READY:
186
          numReady++;
1✔
187
          break forloop;
1✔
188
        case CONNECTING:
189
          numConnecting++;
1✔
190
          break;
1✔
191
        case IDLE:
192
          numIdle++;
1✔
193
          break;
1✔
194
        case TRANSIENT_FAILURE:
195
          numTF++;
1✔
196
          break;
1✔
197
        default:
198
          // ignore it
199
      }
200
    }
1✔
201

202
    ConnectivityState overallState;
203
    if (numReady > 0) {
1✔
204
      overallState = READY;
1✔
205
    } else if (numTF >= 2) {
1✔
206
      overallState = TRANSIENT_FAILURE;
1✔
207
    } else if (numConnecting > 0) {
1✔
208
      overallState = CONNECTING;
1✔
209
    } else if (numTF == 1 && getChildLbStates().size() > 1) {
1✔
210
      overallState = CONNECTING;
1✔
211
    } else if (numIdle > 0) {
1✔
212
      overallState = IDLE;
1✔
213
    } else {
214
      overallState = TRANSIENT_FAILURE;
×
215
    }
216

217
    RingHashPicker picker =
1✔
218
        new RingHashPicker(syncContext, ring, getChildLbStates(), requestHashHeaderKey, random);
1✔
219
    getHelper().updateBalancingState(overallState, picker);
1✔
220
    this.currentConnectivityState = overallState;
1✔
221
  }
1✔
222

223
  @Override
224
  protected ChildLbState createChildLbState(Object key) {
225
    return new ChildLbState(key, lazyLbFactory);
1✔
226
  }
227

228
  private Status validateAddrList(List<EquivalentAddressGroup> addrList) {
229
    if (addrList.isEmpty()) {
1✔
230
      Status unavailableStatus = Status.UNAVAILABLE.withDescription("Ring hash lb error: EDS "
×
231
              + "resolution was successful, but returned server addresses are empty.");
232
      handleNameResolutionError(unavailableStatus);
×
233
      return unavailableStatus;
×
234
    }
235

236
    String dupAddrString = validateNoDuplicateAddresses(addrList);
1✔
237
    if (dupAddrString != null) {
1✔
238
      Status unavailableStatus = Status.UNAVAILABLE.withDescription("Ring hash lb error: EDS "
1✔
239
              + "resolution was successful, but there were duplicate addresses: " + dupAddrString);
240
      handleNameResolutionError(unavailableStatus);
1✔
241
      return unavailableStatus;
1✔
242
    }
243

244
    long totalWeight = 0;
1✔
245
    for (EquivalentAddressGroup eag : addrList) {
1✔
246
      Long weight = eag.getAttributes().get(XdsAttributes.ATTR_SERVER_WEIGHT);
1✔
247

248
      if (weight == null) {
1✔
249
        weight = 1L;
×
250
      }
251

252
      if (weight < 0) {
1✔
253
        Status unavailableStatus = Status.UNAVAILABLE.withDescription(
1✔
254
            String.format("Ring hash lb error: EDS resolution was successful, but returned a "
1✔
255
                        + "negative weight for %s.", stripAttrs(eag)));
1✔
256
        handleNameResolutionError(unavailableStatus);
1✔
257
        return unavailableStatus;
1✔
258
      }
259
      if (weight > UnsignedInteger.MAX_VALUE.longValue()) {
1✔
260
        Status unavailableStatus = Status.UNAVAILABLE.withDescription(
1✔
261
            String.format("Ring hash lb error: EDS resolution was successful, but returned a weight"
1✔
262
                + " too large to fit in an unsigned int for %s.", stripAttrs(eag)));
1✔
263
        handleNameResolutionError(unavailableStatus);
1✔
264
        return unavailableStatus;
1✔
265
      }
266
      totalWeight += weight;
1✔
267
    }
1✔
268

269
    if (totalWeight > UnsignedInteger.MAX_VALUE.longValue()) {
1✔
270
      Status unavailableStatus = Status.UNAVAILABLE.withDescription(
1✔
271
          String.format(
1✔
272
              "Ring hash lb error: EDS resolution was successful, but returned a sum of weights too"
273
                  + " large to fit in an unsigned int (%d).", totalWeight));
1✔
274
      handleNameResolutionError(unavailableStatus);
1✔
275
      return unavailableStatus;
1✔
276
    }
277

278
    return Status.OK;
1✔
279
  }
280

281
  @Nullable
282
  private String validateNoDuplicateAddresses(List<EquivalentAddressGroup> addrList) {
283
    Set<SocketAddress> addresses = new HashSet<>();
1✔
284
    Multiset<String> dups = HashMultiset.create();
1✔
285
    for (EquivalentAddressGroup eag : addrList) {
1✔
286
      for (SocketAddress address : eag.getAddresses()) {
1✔
287
        if (!addresses.add(address)) {
1✔
288
          dups.add(address.toString());
1✔
289
        }
290
      }
1✔
291
    }
1✔
292

293
    if (!dups.isEmpty()) {
1✔
294
      return dups.entrySet().stream()
1✔
295
          .map((dup) ->
1✔
296
              String.format("Address: %s, count: %d", dup.getElement(), dup.getCount() + 1))
1✔
297
          .collect(Collectors.joining("; "));
1✔
298
    }
299

300
    return null;
1✔
301
  }
302

303
  private static List<RingEntry> buildRing(
304
      Map<EquivalentAddressGroup, Long> serverWeights, long totalWeight, double scale) {
305
    List<RingEntry> ring = new ArrayList<>();
1✔
306
    double currentHashes = 0.0;
1✔
307
    double targetHashes = 0.0;
1✔
308
    for (Map.Entry<EquivalentAddressGroup, Long> entry : serverWeights.entrySet()) {
1✔
309
      Endpoint endpoint = new Endpoint(entry.getKey());
1✔
310
      double normalizedWeight = (double) entry.getValue() / totalWeight;
1✔
311
      // Per GRFC A61 use the first address for the hash
312
      StringBuilder sb = new StringBuilder(entry.getKey().getAddresses().get(0).toString());
1✔
313
      sb.append('_');
1✔
314
      int lengthWithoutCounter = sb.length();
1✔
315
      targetHashes += scale * normalizedWeight;
1✔
316
      long i = 0L;
1✔
317
      while (currentHashes < targetHashes) {
1✔
318
        sb.append(i);
1✔
319
        long hash = hashFunc.hashAsciiString(sb.toString());
1✔
320
        ring.add(new RingEntry(hash, endpoint));
1✔
321
        i++;
1✔
322
        currentHashes++;
1✔
323
        sb.setLength(lengthWithoutCounter);
1✔
324
      }
1✔
325
    }
1✔
326
    Collections.sort(ring);
1✔
327
    return Collections.unmodifiableList(ring);
1✔
328
  }
329

330
  @SuppressWarnings("ReferenceEquality")
331
  public static EquivalentAddressGroup stripAttrs(EquivalentAddressGroup eag) {
332
    if (eag.getAttributes() == Attributes.EMPTY) {
1✔
333
      return eag;
×
334
    }
335
    return new EquivalentAddressGroup(eag.getAddresses());
1✔
336
  }
337

338
  private static final class RingHashPicker extends SubchannelPicker {
339
    private final SynchronizationContext syncContext;
340
    private final List<RingEntry> ring;
341
    // Avoid synchronization between pickSubchannel and subchannel's connectivity state change,
342
    // freeze picker's view of subchannel's connectivity state.
343
    // TODO(chengyuanzhang): can be more performance-friendly with
344
    //  IdentityHashMap<Subchannel, ConnectivityStateInfo> and RingEntry contains Subchannel.
345
    private final Map<Endpoint, SubchannelView> pickableSubchannels;  // read-only
346
    @Nullable private final Metadata.Key<String> requestHashHeaderKey;
347
    private final ThreadSafeRandom random;
348
    private final boolean hasEndpointInConnectingState;
349

350
    private RingHashPicker(
351
        SynchronizationContext syncContext, List<RingEntry> ring,
352
        Collection<ChildLbState> children, Metadata.Key<String> requestHashHeaderKey,
353
        ThreadSafeRandom random) {
1✔
354
      this.syncContext = syncContext;
1✔
355
      this.ring = ring;
1✔
356
      this.requestHashHeaderKey = requestHashHeaderKey;
1✔
357
      this.random = random;
1✔
358
      pickableSubchannels = new HashMap<>(children.size());
1✔
359
      boolean hasConnectingState = false;
1✔
360
      for (ChildLbState childLbState : children) {
1✔
361
        pickableSubchannels.put((Endpoint)childLbState.getKey(),
1✔
362
            new SubchannelView(childLbState, childLbState.getCurrentState()));
1✔
363
        if (childLbState.getCurrentState() == CONNECTING) {
1✔
364
          hasConnectingState = true;
1✔
365
        }
366
      }
1✔
367
      this.hasEndpointInConnectingState = hasConnectingState;
1✔
368
    }
1✔
369

370
    // Find the ring entry with hash next to (clockwise) the RPC's hash (binary search).
371
    private int getTargetIndex(long requestHash) {
372
      if (ring.size() <= 1) {
1✔
373
        return 0;
×
374
      }
375

376
      int low = 0;
1✔
377
      int high = ring.size() - 1;
1✔
378
      int mid = (low + high) / 2;
1✔
379
      do {
380
        long midVal = ring.get(mid).hash;
1✔
381
        long midValL = mid == 0 ? 0 : ring.get(mid - 1).hash;
1✔
382
        if (requestHash <= midVal && requestHash > midValL) {
1✔
383
          break;
1✔
384
        }
385
        if (midVal < requestHash) {
1✔
386
          low = mid + 1;
1✔
387
        } else {
388
          high =  mid - 1;
1✔
389
        }
390
        mid = (low + high) / 2;
1✔
391
      } while (mid < ring.size() && low <= high);
1✔
392
      return mid;
1✔
393
    }
394

395
    @Override
396
    public PickResult pickSubchannel(PickSubchannelArgs args) {
397
      // Determine request hash.
398
      boolean usingRandomHash = false;
1✔
399
      long requestHash;
400
      if (requestHashHeaderKey == null) {
1✔
401
        // Set by the xDS config selector.
402
        Long rpcHashFromCallOptions = args.getCallOptions().getOption(XdsNameResolver.RPC_HASH_KEY);
1✔
403
        if (rpcHashFromCallOptions == null) {
1✔
404
          return PickResult.withError(RPC_HASH_NOT_FOUND);
×
405
        }
406
        requestHash = rpcHashFromCallOptions;
1✔
407
      } else {
1✔
408
        Iterable<String> headerValues = args.getHeaders().getAll(requestHashHeaderKey);
1✔
409
        if (headerValues != null) {
1✔
410
          requestHash = hashFunc.hashAsciiString(Joiner.on(",").join(headerValues));
1✔
411
        } else {
412
          requestHash = random.nextLong();
1✔
413
          usingRandomHash = true;
1✔
414
        }
415
      }
416

417
      int targetIndex = getTargetIndex(requestHash);
1✔
418

419
      if (!usingRandomHash) {
1✔
420
        // Per gRFC A61, because of sticky-TF with PickFirst's auto reconnect on TF, we ignore
421
        // all TF subchannels and find the first ring entry in READY, CONNECTING or IDLE.  If
422
        // CONNECTING or IDLE we return a pick with no results.  Additionally, if that entry is in
423
        // IDLE, we initiate a connection.
424
        for (int i = 0; i < ring.size(); i++) {
1✔
425
          int index = (targetIndex + i) % ring.size();
1✔
426
          SubchannelView subchannelView = pickableSubchannels.get(ring.get(index).addrKey);
1✔
427
          ChildLbState childLbState = subchannelView.childLbState;
1✔
428

429
          if (subchannelView.connectivityState  == READY) {
1✔
430
            return childLbState.getCurrentPicker().pickSubchannel(args);
1✔
431
          }
432

433
          // RPCs can be buffered if the next subchannel is pending (per A62). Otherwise, RPCs
434
          // are failed unless there is a READY connection.
435
          if (subchannelView.connectivityState == CONNECTING) {
1✔
436
            return PickResult.withNoResult();
1✔
437
          }
438

439
          if (subchannelView.connectivityState == IDLE) {
1✔
440
            syncContext.execute(() -> {
1✔
441
              childLbState.getLb().requestConnection();
1✔
442
            });
1✔
443

444
            return PickResult.withNoResult(); // Indicates that this should be retried after backoff
1✔
445
          }
446
        }
447
      } else {
448
        // Using a random hash. Find and use the first READY ring entry, triggering at most one
449
        // entry to attempt connection.
450
        boolean requestedConnection = hasEndpointInConnectingState;
1✔
451
        for (int i = 0; i < ring.size(); i++) {
1✔
452
          int index = (targetIndex + i) % ring.size();
1✔
453
          SubchannelView subchannelView = pickableSubchannels.get(ring.get(index).addrKey);
1✔
454
          ChildLbState childLbState = subchannelView.childLbState;
1✔
455
          if (subchannelView.connectivityState == READY) {
1✔
456
            return childLbState.getCurrentPicker().pickSubchannel(args);
1✔
457
          }
458
          if (!requestedConnection && subchannelView.connectivityState == IDLE) {
1✔
459
            syncContext.execute(
1✔
460
                () -> {
461
                  childLbState.getLb().requestConnection();
1✔
462
                });
1✔
463
            requestedConnection = true;
1✔
464
          }
465
        }
466
        if (requestedConnection) {
1✔
467
          return PickResult.withNoResult();
1✔
468
        }
469
      }
470

471
      // return the pick from the original subchannel hit by hash, which is probably an error
472
      ChildLbState originalSubchannel =
1✔
473
          pickableSubchannels.get(ring.get(targetIndex).addrKey).childLbState;
1✔
474
      return originalSubchannel.getCurrentPicker().pickSubchannel(args);
1✔
475
    }
476

477
  }
478

479
  /**
480
   * An unmodifiable view of a subchannel with state not subject to its real connectivity
481
   * state changes.
482
   */
483
  private static final class SubchannelView {
484
    private final ChildLbState childLbState;
485
    private final ConnectivityState connectivityState;
486

487
    private SubchannelView(ChildLbState childLbState, ConnectivityState state) {
1✔
488
      this.childLbState = childLbState;
1✔
489
      this.connectivityState = state;
1✔
490
    }
1✔
491
  }
492

493
  private static final class RingEntry implements Comparable<RingEntry> {
494
    private final long hash;
495
    private final Endpoint addrKey;
496

497
    private RingEntry(long hash, Endpoint addrKey) {
1✔
498
      this.hash = hash;
1✔
499
      this.addrKey = addrKey;
1✔
500
    }
1✔
501

502
    @Override
503
    public int compareTo(RingEntry entry) {
504
      return Long.compare(hash, entry.hash);
1✔
505
    }
506
  }
507

508
  /**
509
   * Configures the ring property. The larger the ring is (that is, the more hashes there are
510
   * for each provided host) the better the request distribution will reflect the desired weights.
511
   */
512
  static final class RingHashConfig {
513
    final long minRingSize;
514
    final long maxRingSize;
515
    final String requestHashHeader;
516

517
    RingHashConfig(long minRingSize, long maxRingSize, String requestHashHeader) {
1✔
518
      checkArgument(minRingSize > 0, "minRingSize <= 0");
1✔
519
      checkArgument(maxRingSize > 0, "maxRingSize <= 0");
1✔
520
      checkArgument(minRingSize <= maxRingSize, "minRingSize > maxRingSize");
1✔
521
      checkNotNull(requestHashHeader);
1✔
522
      this.minRingSize = minRingSize;
1✔
523
      this.maxRingSize = maxRingSize;
1✔
524
      this.requestHashHeader = requestHashHeader;
1✔
525
    }
1✔
526

527
    @Override
528
    public boolean equals(Object o) {
529
      if (!(o instanceof RingHashConfig)) {
1✔
530
        return false;
1✔
531
      }
532
      RingHashConfig that = (RingHashConfig) o;
1✔
533
      return this.minRingSize == that.minRingSize
1✔
534
          && this.maxRingSize == that.maxRingSize
535
          && Objects.equals(this.requestHashHeader, that.requestHashHeader);
1✔
536
    }
537

538
    @Override
539
    public int hashCode() {
540
      return Objects.hash(minRingSize, maxRingSize, requestHashHeader);
1✔
541
    }
542

543
    @Override
544
    public String toString() {
545
      return MoreObjects.toStringHelper(this)
1✔
546
          .add("minRingSize", minRingSize)
1✔
547
          .add("maxRingSize", maxRingSize)
1✔
548
          .add("requestHashHeader", requestHashHeader)
1✔
549
          .toString();
1✔
550
    }
551
  }
552
}
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