Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xds: CHANNEL_ID hash should be random for the channel #9453

Merged
merged 2 commits into from Aug 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion xds/src/main/java/io/grpc/xds/XdsNameResolver.java
Expand Up @@ -84,6 +84,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -123,6 +124,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 = ThreadLocalRandom.current().nextLong();
ejona86 marked this conversation as resolved.
Show resolved Hide resolved

private volatile RoutingConfig routingConfig = RoutingConfig.empty;
private Listener2 listener;
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