Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ RUN \
microdnf install -y tar less shadow-utils && \
groupadd trino --gid 1000 && \
useradd trino --uid 1000 --gid 1000 --create-home && \
mkdir -p /usr/lib/trino-gateway /etc/trino-gateway && \
chown -R "trino:trino" /usr/lib/trino-gateway /etc/trino-gateway
mkdir -p /usr/lib/trino-gateway /data/trino-gateway && \
chown -R "trino:trino" /usr/lib/trino-gateway /data/trino-gateway

COPY --chown=trino:trino gateway-ha /usr/lib/trino-gateway
ARG TRINO_GATEWAY_VERSION
COPY --chown=trino:trino trino-gateway-server-${TRINO_GATEWAY_VERSION} /usr/lib/trino-gateway
COPY --chown=trino:trino default/etc /etc/trino-gateway

EXPOSE 8080
USER trino:trino
CMD java -jar /usr/lib/trino-gateway/gateway-ha-jar-with-dependencies.jar "/etc/trino-gateway/config.yaml"
CMD ["/usr/lib/trino-gateway/bin/run-trino-gateway"]

HEALTHCHECK --interval=10s --timeout=5s --start-period=10s \
CMD /usr/lib/trino-gateway/bin/health-check
10 changes: 10 additions & 0 deletions docker/bin/run-trino-gateway
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -xeuo pipefail

launcher_opts=(--etc-dir /etc/trino-gateway --config /etc/trino-gateway/config.yaml)
if ! grep -s -q 'node.id' /etc/trino-gateway/node.properties; then
launcher_opts+=("-Dnode.id=${HOSTNAME}")
fi

exec /usr/lib/trino-gateway/bin/launcher run "${launcher_opts[@]}" "$@"
21 changes: 11 additions & 10 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,23 @@ check_environment

if [ -n "$TRINO_GATEWAY_VERSION" ]; then
echo "🎣 Downloading Trino Gateway server artifact for release version ${TRINO_GATEWAY_VERSION}"
"${SOURCE_DIR}/mvnw" -C dependency:get -Dtransitive=false -Dartifact="io.trino.gateway:gateway-ha:${TRINO_GATEWAY_VERSION}:jar:jar-with-dependencies"
"${SOURCE_DIR}/mvnw" -C dependency:get -Dtransitive=false -Dartifact="io.trino.gateway:trino-gateway-server:${TRINO_GATEWAY_VERSION}:tar.gz"
local_repo=$("${SOURCE_DIR}/mvnw" -B help:evaluate -Dexpression=settings.localRepository -q -DforceStdout)
trino_gateway_ha="$local_repo/io/trino/gateway/gateway-ha/${TRINO_GATEWAY_VERSION}/gateway-ha-${TRINO_GATEWAY_VERSION}-jar-with-dependencies.jar"
trino_gateway_ha="$local_repo/io/trino/gateway/trino-gateway-server/${TRINO_GATEWAY_VERSION}/trino-gateway-server-${TRINO_GATEWAY_VERSION}.tar.gz"
chmod +x "$trino_gateway_ha"
else
TRINO_GATEWAY_VERSION=$("${SOURCE_DIR}/mvnw" -f "${SOURCE_DIR}/pom.xml" --quiet help:evaluate -Dexpression=project.version -DforceStdout)
echo "🎯 Using currently built artifacts from the gateway-ha module with version ${TRINO_GATEWAY_VERSION}"
trino_gateway_ha="${SOURCE_DIR}/gateway-ha/target/gateway-ha-${TRINO_GATEWAY_VERSION}-jar-with-dependencies.jar"
echo "🎯 Using currently built artifacts with version ${TRINO_GATEWAY_VERSION}"
trino_gateway_ha="${SOURCE_DIR}/trino-gateway-server/target/trino-gateway-server-${TRINO_GATEWAY_VERSION}.tar.gz"
fi

echo "🧱 Preparing the image build context directory"
WORK_DIR="$(mktemp -d)"
GATEWAY_WORK_DIR="${WORK_DIR}/gateway-ha"
mkdir "${GATEWAY_WORK_DIR}"
cp "$trino_gateway_ha" "${GATEWAY_WORK_DIR}/gateway-ha-jar-with-dependencies.jar"
cp -R bin "${GATEWAY_WORK_DIR}"
cp "${SCRIPT_DIR}/Dockerfile" "${WORK_DIR}"
cp "$trino_gateway_ha" "${WORK_DIR}/"
tar -C "${WORK_DIR}" -xzf "${WORK_DIR}/trino-gateway-server-${TRINO_GATEWAY_VERSION}.tar.gz"
rm "${WORK_DIR}/trino-gateway-server-${TRINO_GATEWAY_VERSION}.tar.gz"
cp -R bin "${WORK_DIR}/trino-gateway-server-${TRINO_GATEWAY_VERSION}"
cp -R default "${WORK_DIR}/"

TAG_PREFIX="trino-gateway:${TRINO_GATEWAY_VERSION}"
#version file is used by the Helm chart test
Expand All @@ -131,7 +131,8 @@ for arch in "${ARCHITECTURES[@]}"; do
--build-arg TRINO_GATEWAY_BASE_IMAGE="${TRINO_GATEWAY_BASE_IMAGE}" \
--platform "linux/$arch" \
-f Dockerfile \
-t "${TAG_PREFIX}-$arch"
-t "${TAG_PREFIX}-$arch" \
--build-arg "TRINO_GATEWAY_VERSION=${TRINO_GATEWAY_VERSION}"
done

echo "🧹 Cleaning up the build context directory"
Expand Down
File renamed without changes.
16 changes: 16 additions & 0 deletions docker/default/etc/jvm.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-server
-XX:InitialRAMPercentage=80
-XX:MaxRAMPercentage=80
-XX:G1HeapRegionSize=32M
-XX:+ExplicitGCInvokesConcurrent
-XX:+HeapDumpOnOutOfMemoryError
-XX:+ExitOnOutOfMemoryError
-XX:-OmitStackTraceInFastThrow
-XX:ReservedCodeCacheSize=256M
-XX:PerMethodRecompilationCutoff=10000
-XX:PerBytecodeRecompilationCutoff=10000
-Djdk.attach.allowAttachSelf=true
-Djdk.nio.maxCachedBufferSize=2000000
-Dfile.encoding=UTF-8
# Allow loading dynamic agent used by JOL
-XX:+EnableDynamicAgentLoading
2 changes: 2 additions & 0 deletions docker/default/etc/log.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Enable verbose logging from Trino
#io.trino=DEBUG
2 changes: 2 additions & 0 deletions docker/default/etc/node.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node.environment=docker
node.data-dir=/data/trino-gateway
4 changes: 0 additions & 4 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ services:
start_period: 20s
ports:
- "8080:8080"
volumes:
- target: /etc/trino-gateway/config.yaml
source: ./config.yaml
type: bind

postgres:
image: ${TRINO_GATEWAY_POSTGRES_IMAGE:-postgres}
Expand Down
4 changes: 2 additions & 2 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ To enable them, set the environment variable `TG_RUN_ORACLE_TESTS=true`. These t
will always be run in GitHub CI.

```shell
cd gateway-ha/target/
java -jar gateway-ha-{{VERSION}}-jar-with-dependencies.jar ../config.yaml
cd trino-gateway-server/target/trino-gateway-server-{{VERSION}}
bin/launcher start --config path/to/config.yaml
```

#### In Docker
Expand Down
3 changes: 1 addition & 2 deletions docs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ details found in the `docker-compose.yml` file.

## Configuration

The image uses the configuration file `docker/config.yaml` from the project
checkout, and mounts it at `/etc/trino-gateway/config.yaml`.
The image uses the configuration file `docker/default/etc/config.yaml` from the project checkout.

## Health check

Expand Down
15 changes: 6 additions & 9 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,10 @@ Find more information in [the related Trino documentation](https://trino.io/docs

## Configuration

After downloading or building the JAR, rename it to `gateway-ha.jar`,
and place it in a directory with read and write access such as `/opt/trinogateway`.
After downloading or building the TAR, extract it to `trino-gateway-server`.

Copy the example config file `config.yaml` from the `gateway-ha/`
directory into the same directory, and update the configuration as needed.
directory and JVM configuration file `docker/default/etc/jvm.config` into etc directory inside trino-gateway-server, and update the configuration as needed.

Each component of the Trino Gateway has a corresponding node in the
configuration YAML file.
Expand Down Expand Up @@ -224,12 +223,10 @@ proxyResponseConfiguration:

## Running Trino Gateway

Start Trino Gateway with the following java command in the directory of the
JAR and YAML files:
Start Trino Gateway with the following command by cd to the Trino Gateway server directory :

```shell
java -XX:MinRAMPercentage=50 -XX:MaxRAMPercentage=80 \
-jar gateway-ha.jar config.yaml
bin/launcher start --config=etc/config.yaml
```

### Helm <a name="helm"></a>
Expand Down Expand Up @@ -296,10 +293,10 @@ However, a [Secret](https://kubernetes.io/docs/concepts/configuration/secret/)
is recommended to protect the database credentials required for this
configuration.

By default, the Trino Gateway process is started with the following command:
By default, the Trino Gateway process is started with the following command from the trino-gateway-server directory after extracting the TAR:

```shell
java -XX:MinRAMPercentage=80.0 -XX:MaxRAMPercentage=80.0 -jar /usr/lib/trino-gateway/gateway-ha-jar-with-dependencies.jar /etc/trino-gateway/config.yaml
bin/launcher start --config=etc/config.yaml
```

You can customize details with the `command` node. It accepts a list, that must
Expand Down
12 changes: 3 additions & 9 deletions docs/migration-to-airlift.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,12 @@ serverConfig:
```
* The `log.levels-file` JVM option is no longer supported.

### JVM startup arguments
### Server startup command

The first arg `server` has been removed.
cd to the Trino Gateway server directory after extracting the TAR and use the following command:

Old config:
```bash
java -jar gateway-ha.jar server config.yaml
```

New config:
```bash
java -jar gateway-ha.jar config.yaml
bin/launcher start --config=etc/config.yaml
```

### Format of `extraWhitelistPaths`
Expand Down
34 changes: 19 additions & 15 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,31 @@ under the project root folder, and run it at the temporary directory.

It copies the following, necessary files to current directory:

- `gateway-ha.jar` from Maven Central using the version specified in the script
- `config.yaml` from the `docs` folder of the current project folder
- `trino-gateway-server.tar.gz` from Maven Central using the version specified in the script
- `config.yaml` from the `docs` folder of the current project folder to etc directory of the Trino Gateway server

```shell
#!/usr/bin/env sh

VERSION=15
BASE_URL="https://repo1.maven.org/maven2/io/trino/gateway/gateway-ha"
JAR_FILE="gateway-ha-$VERSION-jar-with-dependencies.jar"
GATEWAY_JAR="gateway-ha.jar"
VERSION=16
BASE_URL="https://repo1.maven.org/maven2/io/trino/gateway/trino-gateway-server"
GATEWAY_TAR="trino-gateway-server-$VERSION.tar.gz"
GATEWAY_DIR="trino-gateway-server-$VERSION"
CONFIG_YAML="config.yaml"

# Copy necessary files
copy_files() {
if [[ ! -f "$GATEWAY_JAR" ]]; then
echo "Fetching $GATEWAY_JAR version $VERSION"
curl -O "$BASE_URL/$VERSION/$JAR_FILE"
mv "$JAR_FILE" "$GATEWAY_JAR"
copy_and_extract_files() {
if [[ ! -f "$GATEWAY_TAR" ]]; then
echo "Fetching $GATEWAY_TAR"
curl -O "$BASE_URL/$VERSION/$GATEWAY_TAR"
fi

[[ ! -f "$CONFIG_YAML" ]] && cp ../docs/$CONFIG_YAML .
tar -xzf "$GATEWAY_TAR"
mkdir -p "$GATEWAY_DIR"/etc
echo -e "-server\n-XX:MinRAMPercentage=80\n-XX:MaxRAMPercentage=80" > "$GATEWAY_DIR"/etc/jvm.config

[[ ! -f "$CONFIG_YAML" ]] && cp docs/$CONFIG_YAML .
cp $CONFIG_YAML "$GATEWAY_DIR"/etc/
}

# Start PostgreSQL database if not running
Expand All @@ -51,19 +55,19 @@ start_postgres_db() {
}

# Main execution flow
copy_files
copy_and_extract_files
start_postgres_db

# Start Trino Gateway server
echo "Starting Trino Gateway server..."
java -Xmx1g -jar ./$GATEWAY_JAR ./$CONFIG_YAML
./$GATEWAY_DIR/bin/launcher start --config=$GATEWAY_DIR/etc/$CONFIG_YAML
```

You can clean up by running

```shell
docker kill local-postgres && docker rm local-postgres
kill -5 $(jps | grep gateway-ha.jar | cut -d' ' -f1)
kill -5 $(jps | grep HaGatewayLauncher | cut -d' ' -f1)
```

## Add Trino backends
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ public static void main(String[] args)
throws Exception
{
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
if (args.length != 1) {
throw new IllegalArgumentException("Expected exactly one argument (path of configuration file)");
String configFile = System.getProperty("config");
if (configFile == null) {
throw new IllegalArgumentException("Configuration file not specified. Use -Dconfig=<config-file>");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in other code you didn't use -D option there, so do you need it here too?

bin/launcher start --config=etc/config.yaml

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including the pr changes, there are three ways to start the gateway:

  1. Using the launcher script
  2. Running the gateway JAR
  3. Executing HaGatewayLauncher.java

When using the launcher script, it internally runs the Java command and passes the configuration as a system property with '-D%s=%s'. To ensure consistency across all three methods and allow execution with the other two options, the configuration file should also be provided as a system property.

}
String config = Files.readString(Path.of(args[0]));
String config = Files.readString(Path.of(configFile));
HaGatewayConfiguration haGatewayConfiguration = objectMapper.readValue(replaceEnvironmentVariables(config), HaGatewayConfiguration.class);
FlywayMigration.migrate(haGatewayConfiguration.getDataStore());
List<Module> modules = addModules(haGatewayConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public static void main(String[] args)
mysql.withCopyFileToContainer(forClasspathResource("add_backends_mysql.sql"), "/docker-entrypoint-initdb.d/2-add_backends_mysql.sql");
mysql.setPortBindings(List.of("3306:3306"));
mysql.start();
HaGatewayLauncher.main(new String[] {"gateway-ha/config.yaml"});
System.setProperty("config", "gateway-ha/config.yaml");
HaGatewayLauncher.main(new String[] {});

log.info("======== SERVER STARTED ========");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public MockResponse dispatch(RecordedRequest request)
HaGatewayTestUtils.buildGatewayConfig(postgresql, routerPort, "test-config-template.yml");

// Start Gateway
String[] args = {testConfigFile.getAbsolutePath()};
HaGatewayLauncher.main(args);
System.setProperty("config", testConfigFile.getAbsolutePath());
HaGatewayLauncher.main(new String[] {});
// Now populate the backend
HaGatewayTestUtils.setUpBackend(
"trino1", "http://localhost:" + backend1Port, "externalUrl", true, "adhoc", routerPort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ void setup()
File testConfigFile =
HaGatewayTestUtils.buildGatewayConfig(postgresql, routerPort, "test-config-template.yml");
// Start Gateway
String[] args = {testConfigFile.getAbsolutePath()};
HaGatewayLauncher.main(args);
System.setProperty("config", testConfigFile.getAbsolutePath());
HaGatewayLauncher.main(new String[] {});
// Now populate the backend
HaGatewayTestUtils.setUpBackend(
"trino1", "http://localhost:" + backendPort, "externalUrl", true, "adhoc", routerPort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ void setup()
File testConfigFile =
HaGatewayTestUtils.buildGatewayConfig(postgresql, routerPort, "test-config-with-routing-template.yml");
// Start Gateway
String[] args = {testConfigFile.getAbsolutePath()};
HaGatewayLauncher.main(args);
System.setProperty("config", testConfigFile.getAbsolutePath());
HaGatewayLauncher.main(new String[] {});
// Now populate the backend
HaGatewayTestUtils.setUpBackend(
"trino1", "http://localhost:" + backendPort, "externalUrl", true, "system", routerPort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ void setup()
File testConfigFile =
HaGatewayTestUtils.buildGatewayConfig(postgresql, routerPort, "test-config-without-x-forwarded-template.yml");
// Start Gateway
String[] args = {testConfigFile.getAbsolutePath()};
HaGatewayLauncher.main(args);
System.setProperty("config", testConfigFile.getAbsolutePath());
HaGatewayLauncher.main(new String[] {});
// Now populate the backend
HaGatewayTestUtils.setUpBackend(
"trino1", "http://localhost:" + backendPort, "externalUrl", true, "adhoc", routerPort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ void setup()
resourceGroupManager = new HaResourceGroupsManager(connectionManager);

// Start Trino Gateway so migrations are run to create tables before inserting test data
String[] args = {testConfigFile.getAbsolutePath()};
HaGatewayLauncher.main(args);
System.setProperty("config", testConfigFile.getAbsolutePath());
HaGatewayLauncher.main(new String[] {});

prepareData();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ void setup()
File testConfigFile =
HaGatewayTestUtils.buildGatewayConfig(postgresql, routerPort, "test-config-with-routing-rules-api.yml");
// Start Gateway
String[] args = {testConfigFile.getAbsolutePath()};
HaGatewayLauncher.main(args);
System.setProperty("config", testConfigFile.getAbsolutePath());
HaGatewayLauncher.main(new String[] {});
// Now populate the backend
HaGatewayTestUtils.setUpBackend(
"trino1", "http://localhost:" + backendPort, "externalUrl", true, "adhoc", routerPort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ void setup()
{
postgresql.start();
File testConfigFile = HaGatewayTestUtils.buildGatewayConfig(postgresql, routerPort, "auth/auth-test-config.yml");
String[] args = {testConfigFile.getAbsolutePath()};
HaGatewayLauncher.main(args);
System.setProperty("config", testConfigFile.getAbsolutePath());
HaGatewayLauncher.main(new String[] {});
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ void setup()
.buildOrThrow();
File testConfigFile =
HaGatewayTestUtils.buildGatewayConfig("auth/oauth-test-config.yml", additionalVars);
String[] args = {testConfigFile.getAbsolutePath()};
System.out.println(ROUTER_PORT);
HaGatewayLauncher.main(args);
System.setProperty("config", testConfigFile.getAbsolutePath());
HaGatewayLauncher.main(new String[] {});
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public MockResponse dispatch(RecordedRequest request)

File testConfigFile = buildGatewayConfig(postgresql, routerPort, "test-config-template.yml");

String[] args = {testConfigFile.getAbsolutePath()};
HaGatewayLauncher.main(args);
System.setProperty("config", testConfigFile.getAbsolutePath());
HaGatewayLauncher.main(new String[] {});

setUpBackend("custom", "http://localhost:" + customBackendPort, "externalUrl", true, "adhoc", routerPort);
}
Expand Down
Loading