24
24
import io .grpc .SynchronizationContext ;
25
25
import io .grpc .xds .RlqsFilterConfig ;
26
26
import io .grpc .xds .client .Bootstrapper .RemoteServerInfo ;
27
+ import java .util .Objects ;
27
28
import java .util .Set ;
28
29
import java .util .concurrent .ConcurrentHashMap ;
29
30
import java .util .concurrent .ScheduledExecutorService ;
@@ -41,7 +42,7 @@ public final class RlqsCache {
41
42
throw new RlqsPoolSynchronizationException (message , error );
42
43
});
43
44
44
- private final ConcurrentHashMap <String , RlqsEngine > enginePool = new ConcurrentHashMap <>();
45
+ private final ConcurrentHashMap <Long , RlqsEngine > enginePool = new ConcurrentHashMap <>();
45
46
Set <String > enginesToShutdown = Sets .newConcurrentHashSet ();
46
47
private final ScheduledExecutorService scheduler ;
47
48
@@ -65,7 +66,7 @@ public void shutdown() {
65
66
shutdown = true ;
66
67
logger .log (Level .FINER , "Shutting down RlqsCache" );
67
68
enginesToShutdown .clear ();
68
- for (String configHash : enginePool .keySet ()) {
69
+ for (long configHash : enginePool .keySet ()) {
69
70
enginePool .get (configHash ).shutdown ();
70
71
}
71
72
enginePool .clear ();
@@ -78,11 +79,11 @@ public void shutdownRlqsEngine(RlqsFilterConfig oldConfig) {
78
79
}
79
80
80
81
public RlqsEngine getOrCreateRlqsEngine (final RlqsFilterConfig config ) {
81
- String configHash = hashRlqsFilterConfig (config );
82
+ long configHash = hashRlqsFilterConfig (config );
82
83
return enginePool .computeIfAbsent (configHash , k -> newRlqsEngine (k , config ));
83
84
}
84
85
85
- private RlqsEngine newRlqsEngine (String configHash , RlqsFilterConfig config ) {
86
+ private RlqsEngine newRlqsEngine (long configHash , RlqsFilterConfig config ) {
86
87
// TODO(sergiitk): [IMPL] get channel creds from the bootstrap.
87
88
ChannelCredentials creds = InsecureChannelCredentials .create ();
88
89
return new RlqsEngine (
@@ -93,11 +94,13 @@ private RlqsEngine newRlqsEngine(String configHash, RlqsFilterConfig config) {
93
94
scheduler );
94
95
}
95
96
96
- private String hashRlqsFilterConfig (RlqsFilterConfig config ) {
97
+ private long hashRlqsFilterConfig (RlqsFilterConfig config ) {
97
98
// TODO(sergiitk): [QUESTION] better name? - ask Eric.
98
99
// TODO(sergiitk): [DESIGN] the key should be hashed (domain + buckets) merged config?
99
100
// 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 );
101
104
}
102
105
103
106
/**
0 commit comments