-
Couldn't load subscription status.
- Fork 118
Add time-based cluster scheduling feature #781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hashroute3
wants to merge
6
commits into
trinodb:main
Choose a base branch
from
hashroute3:feature/cluster-scheduler-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ef2ee6d
First draft
hashroute3 0876dcd
fmt
hashroute3 efc3315
Test class and format fix
hashroute3 14f5b52
Test fixes and code compliance changes
hashroute3 2a3672d
addressing sourcery-ai
hashroute3 ffbc046
Replaces slf logger with airlift logger
hashroute3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # Example configuration for time-based cluster activation | ||
| # This file shows how to configure cluster schedules for the Trino Gateway | ||
|
|
||
| # Main configuration | ||
| server: | ||
| applicationConnectors: | ||
| - type: http | ||
| port: 8080 | ||
| adminConnectors: | ||
| - type: http | ||
| port: 8081 | ||
|
|
||
| # Database configuration | ||
| dataStore: | ||
| jdbcUrl: jdbc:h2:./gateway-ha/gateway-ha;DB_CLOSE_DELAY=-1;MODE=MYSQL | ||
| user: sa | ||
| password: "" | ||
| driverClass: org.h2.Driver | ||
|
|
||
| # Monitor configuration | ||
| monitor: | ||
| active: true | ||
| connectionTimeout: 10s | ||
| refreshInterval: 10s | ||
| backends: ["trino-1", "trino-2"] | ||
|
|
||
| # Backend configurations | ||
| backends: | ||
| - name: trino-1 | ||
| proxyTo: http://localhost:8080 | ||
| active: true | ||
| routingGroup: adhoc | ||
| externalUrl: http://localhost:8080 | ||
| - name: trino-2 | ||
| proxyTo: http://localhost:8081 | ||
| active: true | ||
| routingGroup: adhoc | ||
| externalUrl: http://localhost:8081 | ||
|
|
||
| # Schedule configuration for time-based activation | ||
| scheduleConfiguration: | ||
| enabled: true | ||
| checkInterval: 5m # Check every 5 minutes | ||
| schedules: | ||
| - clusterName: trino-1 | ||
| cronExpression: "0 0 9-17 * * ?" # Active from 9 AM to 5 PM every day | ||
| activeDuringCron: true # Active when cron matches | ||
| - clusterName: trino-2 | ||
| cronExpression: "0 0 17-9 * * ?" # Active from 5 PM to 9 AM every day | ||
| activeDuringCron: true # Active when cron matches | ||
|
|
||
| # Authentication configuration (example) | ||
| authentication: | ||
| type: none | ||
|
|
||
| # Authorization configuration (example) | ||
| authorization: | ||
| type: none |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
gateway-ha/src/main/java/io/trino/gateway/ha/config/ClusterSchedulerConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.trino.gateway.ha.config; | ||
|
|
||
| import com.google.inject.Inject; | ||
| import io.airlift.log.Logger; | ||
| import io.trino.gateway.ha.scheduler.ClusterScheduler; | ||
| import jakarta.annotation.Nullable; | ||
| import jakarta.annotation.PostConstruct; | ||
| import jakarta.annotation.PreDestroy; | ||
|
|
||
| public class ClusterSchedulerConfiguration | ||
| { | ||
| private static final Logger log = Logger.get(ClusterSchedulerConfiguration.class); | ||
|
|
||
| private final ClusterScheduler scheduler; | ||
|
|
||
| @Inject | ||
| public ClusterSchedulerConfiguration(@Nullable ClusterScheduler scheduler) | ||
| { | ||
| this.scheduler = scheduler; | ||
| } | ||
|
|
||
| @PostConstruct | ||
| public void start() | ||
| { | ||
| if (scheduler != null) { | ||
| scheduler.start(); | ||
| } | ||
| } | ||
|
|
||
| @PreDestroy | ||
| public void stop() | ||
| { | ||
| if (scheduler != null) { | ||
| try { | ||
| scheduler.close(); | ||
| } | ||
| catch (Exception e) { | ||
| log.error(e, "Exception occurred while shutting down ClusterScheduler"); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
gateway-ha/src/main/java/io/trino/gateway/ha/config/ScheduleConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.trino.gateway.ha.config; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import io.airlift.units.Duration; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class ScheduleConfiguration | ||
| { | ||
| private boolean enabled; | ||
| private Duration checkInterval = new Duration(5, java.util.concurrent.TimeUnit.MINUTES); | ||
| private String timezone = "GMT"; // Default to GMT if not specified | ||
| private List<ClusterSchedule> schedules = new ArrayList<>(); | ||
|
|
||
| @JsonProperty | ||
| public boolean isEnabled() | ||
| { | ||
| return enabled; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public void setEnabled(boolean enabled) | ||
| { | ||
| this.enabled = enabled; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public Duration getCheckInterval() | ||
| { | ||
| return checkInterval; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public void setCheckInterval(Duration checkInterval) | ||
| { | ||
| this.checkInterval = requireNonNull(checkInterval, "checkInterval is null"); | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public String getTimezone() | ||
| { | ||
| return timezone; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public void setTimezone(String timezone) | ||
| { | ||
| this.timezone = requireNonNull(timezone, "timezone is null"); | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public List<ClusterSchedule> getSchedules() | ||
| { | ||
| return schedules; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public void setSchedules(List<ClusterSchedule> schedules) | ||
| { | ||
| this.schedules = schedules; | ||
| } | ||
|
|
||
| public static class ClusterSchedule | ||
| { | ||
| private String clusterName; | ||
| private String cronExpression; | ||
| private boolean activeDuringCron; | ||
|
|
||
| @JsonProperty | ||
| public String getClusterName() | ||
| { | ||
| return clusterName; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public void setClusterName(String clusterName) | ||
| { | ||
| this.clusterName = requireNonNull(clusterName, "clusterName is null"); | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public String getCronExpression() | ||
| { | ||
| return cronExpression; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public void setCronExpression(String cronExpression) | ||
| { | ||
| this.cronExpression = requireNonNull(cronExpression, "cronExpression is null"); | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public boolean isActiveDuringCron() | ||
| { | ||
| return activeDuringCron; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public void setActiveDuringCron(boolean activeDuringCron) | ||
| { | ||
| this.activeDuringCron = activeDuringCron; | ||
| } | ||
| } | ||
| } | ||
71 changes: 71 additions & 0 deletions
71
gateway-ha/src/main/java/io/trino/gateway/ha/module/ClusterSchedulerModule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.trino.gateway.ha.module; | ||
|
|
||
| import com.google.inject.AbstractModule; | ||
| import com.google.inject.Provides; | ||
| import io.airlift.log.Logger; | ||
| import io.trino.gateway.ha.config.HaGatewayConfiguration; | ||
| import io.trino.gateway.ha.config.ScheduleConfiguration; | ||
| import io.trino.gateway.ha.router.GatewayBackendManager; | ||
| import io.trino.gateway.ha.scheduler.ClusterScheduler; | ||
| import jakarta.inject.Singleton; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class ClusterSchedulerModule | ||
| extends AbstractModule | ||
| { | ||
| private static final Logger log = Logger.get(ClusterSchedulerModule.class); | ||
| private final HaGatewayConfiguration configuration; | ||
|
|
||
| // We require all modules to take HaGatewayConfiguration as the only parameter | ||
| public ClusterSchedulerModule(HaGatewayConfiguration configuration) | ||
| { | ||
| this.configuration = requireNonNull(configuration, "configuration is null"); | ||
| } | ||
|
|
||
| @Override | ||
| public void configure() | ||
| { | ||
| // Configuration-based binding is handled in the provider methods | ||
| if (configuration.getScheduleConfiguration() != null | ||
| && configuration.getScheduleConfiguration().isEnabled()) { | ||
| log.info("ClusterScheduler configuration is enabled"); | ||
| } | ||
| else { | ||
| log.info("ClusterScheduler is disabled or not configured"); | ||
| } | ||
| } | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| public ScheduleConfiguration provideScheduleConfiguration() | ||
| { | ||
| return configuration.getScheduleConfiguration(); | ||
| } | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| public ClusterScheduler provideClusterScheduler( | ||
| GatewayBackendManager backendManager, | ||
| ScheduleConfiguration scheduleConfiguration) | ||
| { | ||
| if (scheduleConfiguration == null || !scheduleConfiguration.isEnabled()) { | ||
| return null; | ||
| } | ||
| log.info("Creating ClusterScheduler instance"); | ||
| return new ClusterScheduler(backendManager, scheduleConfiguration); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.