Skip to content

Commit d245ee2

Browse files
committed
hash config to a long
1 parent c479f05 commit d245ee2

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

xds/src/main/java/io/grpc/xds/RlqsFilterConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ public final String typeUrl() {
3535

3636
public abstract String domain();
3737

38+
// TODO(sergiitk): make not nullable, introduce RlqsFilterConfigOverride
3839
@Nullable
3940
public abstract GrpcService rlqsService();
4041

42+
// TODO(sergiitk): make not nullable, introduce RlqsFilterConfigOverride
4143
@Nullable
4244
public abstract Matcher<HttpMatchInput, RlqsBucketSettings> bucketMatchers();
4345

xds/src/main/java/io/grpc/xds/internal/rlqs/RlqsCache.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.grpc.SynchronizationContext;
2525
import io.grpc.xds.RlqsFilterConfig;
2626
import io.grpc.xds.client.Bootstrapper.RemoteServerInfo;
27+
import java.util.Objects;
2728
import java.util.Set;
2829
import java.util.concurrent.ConcurrentHashMap;
2930
import java.util.concurrent.ScheduledExecutorService;
@@ -41,7 +42,7 @@ public final class RlqsCache {
4142
throw new RlqsPoolSynchronizationException(message, error);
4243
});
4344

44-
private final ConcurrentHashMap<String, RlqsEngine> enginePool = new ConcurrentHashMap<>();
45+
private final ConcurrentHashMap<Long, RlqsEngine> enginePool = new ConcurrentHashMap<>();
4546
Set<String> enginesToShutdown = Sets.newConcurrentHashSet();
4647
private final ScheduledExecutorService scheduler;
4748

@@ -65,7 +66,7 @@ public void shutdown() {
6566
shutdown = true;
6667
logger.log(Level.FINER, "Shutting down RlqsCache");
6768
enginesToShutdown.clear();
68-
for (String configHash : enginePool.keySet()) {
69+
for (long configHash : enginePool.keySet()) {
6970
enginePool.get(configHash).shutdown();
7071
}
7172
enginePool.clear();
@@ -78,11 +79,11 @@ public void shutdownRlqsEngine(RlqsFilterConfig oldConfig) {
7879
}
7980

8081
public RlqsEngine getOrCreateRlqsEngine(final RlqsFilterConfig config) {
81-
String configHash = hashRlqsFilterConfig(config);
82+
long configHash = hashRlqsFilterConfig(config);
8283
return enginePool.computeIfAbsent(configHash, k -> newRlqsEngine(k, config));
8384
}
8485

85-
private RlqsEngine newRlqsEngine(String configHash, RlqsFilterConfig config) {
86+
private RlqsEngine newRlqsEngine(long configHash, RlqsFilterConfig config) {
8687
// TODO(sergiitk): [IMPL] get channel creds from the bootstrap.
8788
ChannelCredentials creds = InsecureChannelCredentials.create();
8889
return new RlqsEngine(
@@ -93,11 +94,13 @@ private RlqsEngine newRlqsEngine(String configHash, RlqsFilterConfig config) {
9394
scheduler);
9495
}
9596

96-
private String hashRlqsFilterConfig(RlqsFilterConfig config) {
97+
private long hashRlqsFilterConfig(RlqsFilterConfig config) {
9798
// TODO(sergiitk): [QUESTION] better name? - ask Eric.
9899
// TODO(sergiitk): [DESIGN] the key should be hashed (domain + buckets) merged config?
99100
// TODO(sergiitk): [IMPL] Hash buckets
100-
return config.rlqsService().targetUri() + config.domain();
101+
int k1 = Objects.hash(config.rlqsService().targetUri(), config.domain());
102+
int k2 = config.bucketMatchers().hashCode();
103+
return Long.rotateLeft(Integer.toUnsignedLong(k1), 32) + Integer.toUnsignedLong(k2);
101104
}
102105

103106
/**

xds/src/main/java/io/grpc/xds/internal/rlqs/RlqsEngine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ public class RlqsEngine {
3838
private final RlqsClient rlqsClient;
3939
private final Matcher<HttpMatchInput, RlqsBucketSettings> bucketMatchers;
4040
private final RlqsBucketCache bucketCache;
41-
private final String configHash;
41+
private final long configHash;
4242
private final ScheduledExecutorService scheduler;
4343
private final ConcurrentMap<Long, ScheduledFuture<?>> timers = new ConcurrentHashMap<>();
4444

4545
public RlqsEngine(
4646
RemoteServerInfo rlqsServer, String domain,
47-
Matcher<HttpMatchInput, RlqsBucketSettings> bucketMatchers, String configHash,
47+
Matcher<HttpMatchInput, RlqsBucketSettings> bucketMatchers, long configHash,
4848
ScheduledExecutorService scheduler) {
4949
this.bucketMatchers = bucketMatchers;
5050
this.configHash = configHash;

0 commit comments

Comments
 (0)