Skip to content

Commit 79d8cc9

Browse files
committed
Fix review comments
1 parent ab677e1 commit 79d8cc9

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

gateway-ha/src/main/java/io/trino/gateway/ha/router/BaseRoutingManager.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import jakarta.ws.rs.HttpMethod;
2929

3030
import java.net.HttpURLConnection;
31+
import java.net.URI;
3132
import java.net.URL;
3233
import java.util.HashMap;
3334
import java.util.List;
@@ -208,7 +209,7 @@ private String searchAllBackendForQuery(String queryId)
208209
Future<Integer> call =
209210
executorService.submit(
210211
() -> {
211-
URL url = new URL(target);
212+
URL url = URI.create(target).toURL();
212213
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
213214
conn.setConnectTimeout((int) TimeUnit.SECONDS.toMillis(5));
214215
conn.setReadTimeout((int) TimeUnit.SECONDS.toMillis(5));
@@ -232,7 +233,10 @@ private String searchAllBackendForQuery(String queryId)
232233
log.warn("Query id [%s] not found", queryId);
233234
}
234235
// Fallback on first active backend if queryId mapping not found.
235-
return gatewayBackendManager.getActiveBackends(defaultRoutingGroup).get(0).getProxyTo();
236+
return gatewayBackendManager.getActiveBackends(defaultRoutingGroup).stream()
237+
.findFirst()
238+
.map(ProxyBackendConfiguration::getProxyTo)
239+
.orElseThrow(() -> new IllegalStateException("No active backends available for default routing group: " + defaultRoutingGroup));
236240
}
237241

238242
/**
@@ -255,7 +259,7 @@ private String findExternalUrlForUnknownQueryId(String queryId)
255259
return externalUrl;
256260
}
257261

258-
private static LoadingCache<String, String> buildCache(Function<String, String> loader)
262+
private LoadingCache<String, String> buildCache(Function<String, String> loader)
259263
{
260264
return CacheBuilder.newBuilder()
261265
.maximumSize(10000)

gateway-ha/src/main/java/io/trino/gateway/ha/router/QueryCountBasedRouter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ public synchronized void updateClusterStats(List<ClusterStats> stats)
231231
@Override
232232
protected synchronized Optional<ProxyBackendConfiguration> selectBackend(List<ProxyBackendConfiguration> backends, String user)
233233
{
234-
Optional<ProxyBackendConfiguration> cluster = backends.stream().min((a, b) -> compareStats(clusterStats.get(a.getName()), clusterStats.get(b.getName()), user));
234+
Optional<ProxyBackendConfiguration> cluster = backends.stream()
235+
.filter(backend -> clusterStats.containsKey(backend.getName()))
236+
.min((a, b) -> compareStats(clusterStats.get(a.getName()), clusterStats.get(b.getName()), user));
235237
cluster.ifPresent(c -> updateLocalStats(clusterStats.get(c.getName()), user));
236238
return cluster;
237239
}

0 commit comments

Comments
 (0)