Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#8395] improvement(trino-connector): Support integration test run in a distributed environment (#8419)

qbhan3979119ff438
diff --git a/docs/how-to-test.md b/docs/how-to-test.md
index 027046c5dd..dfaf63fb62 100644
--- a/docs/how-to-test.md
+++ b/docs/how-to-test.md
@@ -65,6 +65,7 @@ To deploy the Gravitino server locally to run the integration tests, follow thes
integration tests in the `distribution` directory.
4. Use the `bash trino-connector/integration-test/trino-test-tools/trino_test.sh` command to run all the
Trino test sets in the `trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets` directory.
+ Specify the `--trino_worker_num` parameter to make the Trino test sets run in a distributed environment.
## Skip tests
diff --git a/integration-test-common/docker-script/docker-compose.yaml b/integration-test-common/docker-script/docker-compose.yaml
index dc480edb3a..875e67e320 100644
--- a/integration-test-common/docker-script/docker-compose.yaml
+++ b/integration-test-common/docker-script/docker-compose.yaml
@@ -87,6 +87,8 @@ services:
- GRAVITINO_HOST_PORT=${GRAVITINO_SERVER_PORT:-8090}
- GRAVITINO_METALAKE_NAME=test
- HIVE_HOST_IP=hive
+ - TRINO_WORKER_NUM=${TRINO_WORKER_NUM:-0}
+ - TRINO_ROLE=coordinator
entrypoint: /bin/bash /tmp/trino/init.sh
volumes:
- ./init/trino:/tmp/trino
@@ -105,7 +107,35 @@ services:
condition: service_healthy
mysql:
condition: service_healthy
+ trino-worker:
+ condition: service_healthy
+ trino-worker:
+ image: trinodb/trino:435
+ networks:
+ - trino-net
+ deploy:
+ replicas: ${TRINO_WORKER_NUM:-0}
+ environment:
+ - HADOOP_USER_NAME=anonymous
+ - GRAVITINO_HOST_IP=host.docker.internal
+ - GRAVITINO_HOST_PORT=${GRAVITINO_SERVER_PORT:-8090}
+ - GRAVITINO_METALAKE_NAME=test
+ - HIVE_HOST_IP=hive
+ - TRINO_ROLE=worker
+ entrypoint: /bin/bash /tmp/trino/init.sh
+ volumes:
+ - ./init/trino:/tmp/trino
+ - ../../trino-connector/trino-connector/build/libs:/usr/lib/trino/plugin/gravitino
+ extra_hosts:
+ - "host.docker.internal:host-gateway"
+ depends_on:
+ hive:
+ condition: service_healthy
+ postgresql:
+ condition: service_healthy
+ mysql:
+ condition: service_healthy
networks:
trino-net:
diff --git a/integration-test-common/docker-script/init/trino/config/config-worker.properties b/integration-test-common/docker-script/init/trino/config/config-worker.properties
new file mode 100644
index 0000000000..2e9fb7e1e0
--- /dev/null
+++ b/integration-test-common/docker-script/init/trino/config/config-worker.properties
@@ -0,0 +1,23 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#
+
+coordinator=false
+http-server.http.port=8080
+catalog.management=dynamic
+discovery.uri=http://trino:8080
diff --git a/integration-test-common/docker-script/init/trino/config/node.properties b/integration-test-common/docker-script/init/trino/config/node.properties
new file mode 100644
index 0000000000..f5b214321a
--- /dev/null
+++ b/integration-test-common/docker-script/init/trino/config/node.properties
@@ -0,0 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#
+
+node.environment=production
+node.id=NODE_ID
+node.data-dir=/tmp/data
\ No newline at end of file
diff --git a/integration-test-common/docker-script/init/trino/init.sh b/integration-test-common/docker-script/init/trino/init.sh
index 006a35f0e6..f266ae8c76 100644
--- a/integration-test-common/docker-script/init/trino/init.sh
+++ b/integration-test-common/docker-script/init/trino/init.sh
@@ -22,9 +22,9 @@ set -ex
trino_conf_dir="$(dirname "${BASH_SOURCE-$0}")"
trino_conf_dir="$(cd "${trino_conf_dir}">/dev/null; pwd)"
-cp "$trino_conf_dir/config/config.properties" /etc/trino/config.properties
cp "$trino_conf_dir/config/jvm.config" /etc/trino/jvm.config
cp "$trino_conf_dir/config/log4j2.properties" /etc/trino/log4j2.properties
+cp "$trino_conf_dir/config/node.properties" /etc/trino/node.properties
cp "$trino_conf_dir/config/catalog/gravitino.properties" /etc/trino/catalog/gravitino.properties
# Copy the MYSQL driver to iceberg connector
@@ -34,7 +34,22 @@ cp /usr/lib/trino/plugin/mysql/mysql-connector-j-8.2.0.jar /usr/lib/trino/plugin
sed -i "s/GRAVITINO_HOST_IP:GRAVITINO_HOST_PORT/${GRAVITINO_HOST_IP}:${GRAVITINO_HOST_PORT}/g" /etc/trino/catalog/gravitino.properties
# Update `gravitino.metalake = GRAVITINO_METALAKE_NAME` in the `conf/catalog/gravitino.properties`
sed -i "s/GRAVITINO_METALAKE_NAME/${GRAVITINO_METALAKE_NAME}/g" /etc/trino/catalog/gravitino.properties
+# Update `node.id=NODE_ID` in the `/conf/node.properties`
+sed -i "s/NODE_ID/${RANDOM}-${RANDOM}-${RANDOM}-${RANDOM}-${RANDOM}/g" /etc/trino/node.properties
+# Update `/conf/config.properties`
+if [[ "${TRINO_ROLE}" == "coordinator" ]]; then
+ cp "$trino_conf_dir/config/config.properties" /etc/trino/config.properties
+ if [[ "${TRINO_WORKER_NUM}" -gt 0 ]]; then
+ # Deploy a distributed cluster, so update `node-scheduler.include-coordinator` to `false` in the`/conf/config.properties`
+ sed -i "s/node-scheduler.include-coordinator=true/node-scheduler.include-coordinator=false/g" /etc/trino/config.properties
+ fi
+else
+ cp "$trino_conf_dir/config/config-worker.properties" /etc/trino/config.properties
+fi
+
+# mkdir `node.data-dir` in the `/conf/node.properties`
+mkdir -p /tmp/data
# Check the number of Gravitino connector plugins present in the Trino plugin directory
num_of_gravitino_connector=$(ls /usr/lib/trino/plugin/gravitino | grep gravitino-trino-connector-* | wc -l)
@@ -43,19 +58,24 @@ if [[ "${num_of_gravitino_connector}" -ne 1 ]]; then
exit 1
fi
-nohup /usr/lib/trino/bin/run-trino &
-
-counter=0
-while [ $counter -le 300 ]; do
- counter=$((counter + 1))
- trino_ready=$(trino --execute "SHOW CATALOGS LIKE 'gravitino'" | wc -l)
- if [ "$trino_ready" -eq 0 ];
- then
- echo "Wait for the initialization of services"
- sleep 1;
- else
- # persist the container
- tail -f /dev/null
- fi
-done
-exit 1
+# Container start up
+if [[ "${TRINO_ROLE}" == "coordinator" ]]; then
+ nohup /usr/lib/trino/bin/run-trino &
+
+ counter=0
+ while [ $counter -le 300 ]; do
+ counter=$((counter + 1))
+ trino_ready=$(trino --execute "SHOW CATALOGS LIKE 'gravitino'" | wc -l)
+ if [ "$trino_ready" -eq 0 ];
+ then
+ echo "Wait for the initialization of services"
+ sleep 1;
+ else
+ # persist the container
+ tail -f /dev/null
+ fi
+ done
+ exit 1
+else
+ /usr/lib/trino/bin/run-trino
+fi
diff --git a/integration-test-common/src/test/java/org/apache/gravitino/integration/test/container/TrinoITContainers.java b/integration-test-common/src/test/java/org/apache/gravitino/integration/test/container/TrinoITContainers.java
index 3dce2671cd..531d4308ad 100644
--- a/integration-test-common/src/test/java/org/apache/gravitino/integration/test/container/TrinoITContainers.java
+++ b/integration-test-common/src/test/java/org/apache/gravitino/integration/test/container/TrinoITContainers.java
@@ -49,9 +49,14 @@ public class TrinoITContainers implements AutoCloseable {
}
public void launch(int gravitinoServerPort) throws Exception {
+ launch(gravitinoServerPort, 0);
+ }
+
+ public void launch(int gravitinoServerPort, int trinoWokerNum) throws Exception {
shutdown();
Map<String, String> env = new HashMap<>();
+ env.put("TRINO_WORKER_NUM", String.valueOf(trinoWokerNum));
env.put("GRAVITINO_SERVER_PORT", String.valueOf(gravitinoServerPort));
if (System.getProperty("gravitino.log.path") != null) {
env.put("GRAVITINO_LOG_PATH", System.getProperty("gravitino.log.path"));
diff --git a/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryIT.java b/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryIT.java
index 64e49723a6..d4e6e2dad0 100644
--- a/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryIT.java
+++ b/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryIT.java
@@ -71,6 +71,8 @@ public class TrinoQueryIT extends TrinoQueryITBase {
static TrinoQueryITBase trinoQueryITBase;
+ static int trinoWorkerNum = 0;
+
static {
testsetsDir = TrinoQueryIT.class.getClassLoader().getResource("trino-ci-testset").getPath();
testsetsDir = ITUtils.joinPath(testsetsDir, "testsets");
@@ -78,7 +80,7 @@ public class TrinoQueryIT extends TrinoQueryITBase {
@BeforeAll
public void setup() throws Exception {
- trinoQueryITBase = new TrinoQueryITBase();
+ trinoQueryITBase = new TrinoQueryITBase(trinoWorkerNum);
trinoQueryITBase.setup();
cleanupTestEnv();
diff --git a/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryITBase.java b/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryITBase.java
index 6ea2a15705..6dfad3aad1 100644
--- a/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryITBase.java
+++ b/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryITBase.java
@@ -70,6 +70,14 @@ public class TrinoQueryITBase {
private static BaseIT baseIT;
+ protected int trinoWorkerNum = 0;
+
+ public TrinoQueryITBase() {}
+
+ public TrinoQueryITBase(int trinoWorkerNum) {
+ this.trinoWorkerNum = trinoWorkerNum;
+ }
+
private void setEnv() throws Exception {
baseIT = new BaseIT();
if (autoStart) {
@@ -78,7 +86,7 @@ public class TrinoQueryITBase {
gravitinoUri = String.format("http://127.0.0.1:%d", baseIT.getGravitinoServerPort());
trinoITContainers = ContainerSuite.getTrinoITContainers();
- trinoITContainers.launch(baseIT.getGravitinoServerPort());
+ trinoITContainers.launch(baseIT.getGravitinoServerPort(), trinoWorkerNum);
trinoUri = trinoITContainers.getTrinoUri();
hiveMetastoreUri = trinoITContainers.getHiveMetastoreUri();
diff --git a/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryTestTool.java b/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryTestTool.java
index eeb56c0d42..872b3e1373 100644
--- a/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryTestTool.java
+++ b/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryTestTool.java
@@ -85,6 +85,13 @@ public class TrinoQueryTestTool {
"Additional parameters that can replace the value of ${key} in the testers contents, "
+ "example: --params=key1,v1;key2,v2");
+ options.addOption(
+ "trino_worker_num",
+ true,
+ "Specify the number of Trino independent worker, the default value is 0."
+ + "Use a distributed cluster for integration testing when necessary (value > 0), "
+ + "otherwise fall back to a single-node setup with combined coordinator-worker roles.");
+
options.addOption("help", false, "Print this help message");
CommandLineParser parser = new PosixParser();
@@ -97,6 +104,8 @@ public class TrinoQueryTestTool {
"Examples:\n"
+ "Run all the testers in the 'testsets' directory:\n"
+ "TrinoTestTool --auto=all\n\n"
+ + "Run all the testers in the 'testsets' directory with a distributed cluster:\n"
+ + "TrinoTestTool --auto=all --trino_worker_num=3\n\n"
+ "Run all the tpch testset's testers in the 'testsets/tpch' directory:\n"
+ "TrinoTestTool --testset=tpch --auto=all\n\n"
+ "Run the tester 'testsets/tpch/00005.sql' in the tpch testset under hive catalog :\n"
@@ -212,6 +221,23 @@ public class TrinoQueryTestTool {
}
}
+ String trinoWorkerNumConfig = commandLine.getOptionValue("trino_worker_num", "0");
+ try {
+ int trinoWorkerNum = Integer.parseInt(trinoWorkerNumConfig);
+ if (trinoWorkerNum < 0) {
+ System.out.println(
+ "The value of trino_worker_num must be greater than zero, current value is: "
+ + trinoWorkerNumConfig);
+ System.exit(1);
+ }
+ TrinoQueryIT.trinoWorkerNum = trinoWorkerNum;
+ } catch (Exception e) {
+ System.out.println(
+ "The value of trino_worker_num must be an integer value, current value is: "
+ + trinoWorkerNumConfig);
+ System.exit(1);
+ }
+
checkEnv();
TrinoQueryITBase.autoStart = autoStart;
diff --git a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/CatalogConnectorManager.java b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/CatalogConnectorManager.java
index 3290cad867..3e80e83902 100644
--- a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/CatalogConnectorManager.java
+++ b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/CatalogConnectorManager.java
@@ -171,7 +171,6 @@ public class CatalogConnectorManager {
}
} catch (Exception e) {
LOG.error("Error when loading metalake", e);
- System.exit(-1);
}
}