1313 */
1414package io .trino .gateway .ha .router ;
1515
16+ import com .github .benmanes .caffeine .cache .Caffeine ;
17+ import com .github .benmanes .caffeine .cache .LoadingCache ;
1618import com .google .common .annotations .VisibleForTesting ;
1719import com .google .common .base .Function ;
1820import com .google .common .base .Strings ;
19- import com .google .common .cache .CacheBuilder ;
20- import com .google .common .cache .CacheLoader ;
21- import com .google .common .cache .LoadingCache ;
2221import io .airlift .log .Logger ;
2322import io .trino .gateway .ha .clustermonitor .ClusterStats ;
2423import io .trino .gateway .ha .clustermonitor .TrinoStatus ;
3635import java .util .Map ;
3736import java .util .Optional ;
3837import java .util .concurrent .ConcurrentHashMap ;
39- import java .util .concurrent .ExecutionException ;
4038import java .util .concurrent .ExecutorService ;
4139import java .util .concurrent .Executors ;
4240import java .util .concurrent .Future ;
@@ -123,7 +121,7 @@ public String findBackendForQueryId(String queryId)
123121 try {
124122 backendAddress = queryIdBackendCache .get (queryId );
125123 }
126- catch (ExecutionException e ) {
124+ catch (RuntimeException e ) {
127125 log .warn ("Exception while loading queryId from cache %s" , e .getLocalizedMessage ());
128126 }
129127 return backendAddress ;
@@ -137,7 +135,7 @@ public String findExternalUrlForQueryId(String queryId)
137135 try {
138136 externalUrl = queryIdExternalUrlCache .get (queryId );
139137 }
140- catch (ExecutionException e ) {
138+ catch (RuntimeException e ) {
141139 log .warn ("Exception while loading queryId from cache %s" , e .getLocalizedMessage ());
142140 }
143141 return externalUrl ;
@@ -155,7 +153,7 @@ public String findRoutingGroupForQueryId(String queryId)
155153 try {
156154 routingGroup = queryIdRoutingGroupCache .get (queryId );
157155 }
158- catch (ExecutionException e ) {
156+ catch (RuntimeException e ) {
159157 log .warn ("Exception while loading queryId from routing group cache %s" , e .getLocalizedMessage ());
160158 }
161159 return routingGroup ;
@@ -245,35 +243,23 @@ private String searchAllBackendForQuery(String queryId)
245243 */
246244 private String findRoutingGroupForUnknownQueryId (String queryId )
247245 {
248- String routingGroup = queryHistoryManager .getRoutingGroupForQueryId (queryId );
249- setRoutingGroupForQueryId (queryId , routingGroup );
250- return routingGroup ;
246+ return queryHistoryManager .getRoutingGroupForQueryId (queryId );
251247 }
252248
253249 /**
254250 * Attempts to look up the external url associated with the query id from query history table
255251 */
256252 private String findExternalUrlForUnknownQueryId (String queryId )
257253 {
258- String externalUrl = queryHistoryManager .getExternalUrlForQueryId (queryId );
259- setExternalUrlForQueryId (queryId , externalUrl );
260- return externalUrl ;
254+ return queryHistoryManager .getExternalUrlForQueryId (queryId );
261255 }
262256
263257 private LoadingCache <String , String > buildCache (Function <String , String > loader )
264258 {
265- return CacheBuilder .newBuilder ()
259+ return Caffeine .newBuilder ()
266260 .maximumSize (10000 )
267261 .expireAfterAccess (30 , TimeUnit .MINUTES )
268- .build (
269- new CacheLoader <>()
270- {
271- @ Override
272- public String load (String queryId )
273- {
274- return loader .apply (queryId );
275- }
276- });
262+ .build (loader ::apply );
277263 }
278264
279265 private boolean isBackendHealthy (String backendId )
0 commit comments