Skip to content

Commit cdc2ee2

Browse files
vishalyaebyhr
authored andcommitted
Fix querycount based router
1 parent 4fd6d0d commit cdc2ee2

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.airlift.log.Logger;
2222
import io.trino.gateway.ha.clustermonitor.ClusterStats;
2323
import io.trino.gateway.ha.clustermonitor.TrinoStatus;
24+
import io.trino.gateway.ha.config.ProxyBackendConfiguration;
2425
import io.trino.gateway.ha.config.RoutingConfiguration;
2526

2627
import java.util.ArrayList;
@@ -51,6 +52,7 @@ static class LocalStats
5152
private int queuedQueryCount;
5253
private TrinoStatus trinoStatus;
5354
private String proxyTo;
55+
private String externalUrl;
5456
private String routingGroup;
5557
private String clusterId;
5658
private Map<String, Integer> userQueuedCount;
@@ -62,6 +64,7 @@ static class LocalStats
6264
queuedQueryCount = stats.queuedQueryCount();
6365
trinoStatus = stats.trinoStatus();
6466
proxyTo = stats.proxyTo();
67+
externalUrl = stats.externalUrl();
6568
routingGroup = stats.routingGroup();
6669
if (stats.userQueuedCount() != null) {
6770
userQueuedCount = new HashMap<String, Integer>(stats.userQueuedCount());
@@ -116,6 +119,16 @@ public void proxyTo(String proxyTo)
116119
this.proxyTo = proxyTo;
117120
}
118121

122+
public String getExternalUrl()
123+
{
124+
return this.externalUrl;
125+
}
126+
127+
public void externalUrl(String externalUrl)
128+
{
129+
this.externalUrl = externalUrl;
130+
}
131+
119132
public String routingGroup()
120133
{
121134
return this.routingGroup;
@@ -135,6 +148,16 @@ public void userQueuedCount(Map<String, Integer> userQueuedCount)
135148
{
136149
this.userQueuedCount = userQueuedCount;
137150
}
151+
152+
ProxyBackendConfiguration backendConfiguration()
153+
{
154+
ProxyBackendConfiguration backendConfiguration = new ProxyBackendConfiguration();
155+
backendConfiguration.setExternalUrl(externalUrl);
156+
backendConfiguration.setProxyTo(proxyTo);
157+
backendConfiguration.setRoutingGroup(routingGroup);
158+
backendConfiguration.setActive(true);
159+
return backendConfiguration;
160+
}
138161
}
139162

140163
@Inject
@@ -233,6 +256,21 @@ public String provideDefaultCluster(String user)
233256
return getBackendForRoutingGroup(defaultRoutingGroup, user).orElseThrow(() -> new RouterException("did not find any cluster for the default routing group: " + defaultRoutingGroup));
234257
}
235258

259+
public Optional<ProxyBackendConfiguration> getBackendConfigurationForRoutingGroup(String routingGroup, String user)
260+
{
261+
Optional<LocalStats> localStats = getClusterToRoute(user, routingGroup);
262+
localStats.ifPresent(stats -> updateLocalStats(stats, user));
263+
return localStats.map(LocalStats::backendConfiguration);
264+
}
265+
266+
@Override
267+
public ProxyBackendConfiguration provideBackendConfiguration(String routingGroup, String user)
268+
{
269+
return getBackendConfigurationForRoutingGroup(routingGroup, user)
270+
.orElseGet(() -> getBackendConfigurationForRoutingGroup(defaultRoutingGroup, user)
271+
.orElseThrow(() -> new RouterException("did not find any cluster for the default routing group: " + defaultRoutingGroup)));
272+
}
273+
236274
@Override
237275
public String provideClusterForRoutingGroup(String routingGroup, String user)
238276
{

0 commit comments

Comments
 (0)