Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion xds/src/main/java/io/grpc/xds/XdsNameResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ final class XdsNameResolver extends NameResolver {
// put()/remove() must be called in SyncContext, and get() can be called in any thread.
private final ConcurrentMap<String, ClusterRefState> clusterRefs = new ConcurrentHashMap<>();
private final ConfigSelector configSelector = new ConfigSelector();
private final long randomChannelId;

private volatile RoutingConfig routingConfig = RoutingConfig.empty;
private Listener2 listener;
Expand Down Expand Up @@ -162,6 +163,7 @@ final class XdsNameResolver extends NameResolver {
this.xdsClientPoolFactory.setBootstrapOverride(bootstrapOverride);
this.random = checkNotNull(random, "random");
this.filterRegistry = checkNotNull(filterRegistry, "filterRegistry");
randomChannelId = random.nextLong();
logId = InternalLogId.allocate("xds-resolver", name);
logger = XdsLogger.withLogId(logId);
logger.log(XdsLogLevel.INFO, "Created resolver for {0}", name);
Expand Down Expand Up @@ -586,7 +588,7 @@ private long generateHash(List<HashPolicy> hashPolicies, Metadata headers) {
newHash = hashFunc.hashAsciiString(value);
}
} else if (policy.type() == HashPolicy.Type.CHANNEL_ID) {
newHash = hashFunc.hashLong(logId.getId());
newHash = hashFunc.hashLong(randomChannelId);
}
if (newHash != null ) {
// Rotating the old value prevents duplicate hash rules from cancelling each other out
Expand Down
1 change: 1 addition & 0 deletions xds/src/test/java/io/grpc/xds/XdsNameResolverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ public void resolved_rpcHashingByChannelId() {
// A different resolver/Channel.
resolver.shutdown();
reset(mockListener);
when(mockRandom.nextLong()).thenReturn(123L);
resolver = new XdsNameResolver(null, AUTHORITY, null, serviceConfigParser,
syncContext, scheduler,
xdsClientPoolFactory, mockRandom, FilterRegistry.getDefaultRegistry(), null);
Expand Down