feat(emr): apply a cluster's trino-node, trino-log and trino-env to its Trino (#9563)

trino-node's and trino-log's properties now go into the image's own
node.properties and log.properties, after its lines, so an image of
trino.image's keeps its settings; Floci names the node only where neither
gives it an id; and trino-env's nested export
properties ("If any classification ends in env, use the export
sub-classification") become the Trino container's environment, which a
catalog reads as ${ENV:NAME} where its connector takes Trino's
configuration, as Iceberg's does. The exports come after Floci's
AWS settings, which they may change as a trino-env.sh would, and before
the variables Floci writes Trino's files from, which they may not.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-26 18:14:10 -04:00
1 parent 9d45e5d949
commit 34153a29f0
11 files changed
+208 -59

No files matched your search

+23 -17
View File
@@ -847,18 +847,24 @@ holding the driver and its executors, or a command or a script. The cluster itse
cluster's metastore at `thrift://localhost:9083`, as the Release Guide's Delta Lake and Iceberg tutorials have them,
or on Floci's Glue with `hive.metastore` set to `glue`, Iceberg's `iceberg.catalog.type` for Iceberg, and on Floci's
S3, as `hive` is. A classification's properties go into its catalog after Floci's, a later configuration's winning.
The image's own catalogs go, as EMR's Trino has those the cluster configures. Trino reaches S3 and Glue as the
cluster's EC2 instance profile's role, with a session of its own, as the metastore does. A step runs `trino-cli`, as
the Release Guide's "Start the Trino CLI by running trino-cli" does on the primary node, through `command-runner.jar`:
the CLI of the same Trino, which Floci copies into the cluster's image from Trino's image as it makes it, on the
image's Java 17, connects to the coordinator unless the step names a `--server` of its own. As the cluster becomes
ready, its bootstrap done, Floci starts its primary node, with its HDFS and Trino, in the background, steps or none,
as an application UI link does, the cluster `WAITING` or `RUNNING` meanwhile; Trino is ready once it has answered a
query for ten seconds, within three minutes, as Trino runs a query that reads a catalog once it has learnt that its
node serves the catalog. A step that comes first starts them itself and waits for Trino, a Trino that does not answer
failing the step; the cluster's next steps have it at once. Clients outside the cluster reach it through Floci, on a
host of the cluster's own, `http://<cluster-id>.emr-trino.<floci-host>:<port>`, as EMR's reach Trino's port on the
primary node: Trino's CLI with `--server=http://j-2AXXXXXXGAPLF.emr-trino.localhost:4566`, or
The image's own catalogs go, as EMR's Trino has those the cluster configures. `trino-node`'s and `trino-log`'s
properties go into the image's own `node.properties` and `log.properties`, after its lines, a property given twice
taking the later, so an image of `trino.image`'s keeps its settings where the cluster gives none, and Floci names the
node, with hyphens for the host name's dots, only where neither gives it an id; and the variables `trino-env`'s nested
`export` gives, as "If any classification ends in env, use the export sub-classification", are Trino's environment,
which a catalog reads as `${ENV:NAME}` where its connector takes Trino's configuration, as Iceberg's and the memory
connector's do, after Floci's own AWS settings, which they may change. Trino reaches S3 and Glue as the cluster's EC2
instance profile's role, with a session of its own, as the metastore does. A step runs `trino-cli`, as the Release
Guide's "Start the Trino CLI by running trino-cli" does on the primary node, through `command-runner.jar`: the CLI of
the same Trino, which Floci copies into the cluster's image from Trino's image as it makes it, on the image's Java 17,
connects to the coordinator unless the step names a `--server` of its own. As the cluster becomes ready, its bootstrap
done, Floci starts its primary node, with its HDFS and Trino, in the background, steps or none, as an application UI
link does, the cluster `WAITING` or `RUNNING` meanwhile; Trino is ready once it has answered a query for ten seconds,
within three minutes, as Trino runs a query that reads a catalog once it has learnt that its node serves the catalog.
A step that comes first starts them itself and waits for Trino, a Trino that does not answer failing the step; the
cluster's next steps have it at once. Clients outside the cluster reach it through Floci, on a host of the cluster's
own, `http://<cluster-id>.emr-trino.<floci-host>:<port>`, as EMR's reach Trino's port on the primary node: Trino's CLI
with `--server=http://j-2AXXXXXXGAPLF.emr-trino.localhost:4566`, or
`jdbc:trino://j-2AXXXXXXGAPLF.emr-trino.localhost:4566/hive`. Floci's host must resolve its subdomains, as for
application UIs: `localhost` and `localhost.floci.io` do, and Floci's TLS certificate names `*.emr-trino.localhost`
and `*.emr-trino.localhost.floci.io`. The host takes no credentials, as Floci's Trino has no authentication, so
@@ -1090,11 +1096,11 @@ holding the driver and its executors, or a command or a script. The cluster itse
own `-amzn` builds; Floci runs the Trino project's image of the same version (see **Trino**), so a connector that
image has no plugin for stops Trino, with what it logged, and the step. Floci starts it in the background as the
cluster becomes ready, so the cluster is `WAITING` before Trino answers, where EMR's runs once the cluster is up, and
a client meanwhile gets a `503`. Its `trino-connector-*` classifications and `trino-config` apply; `trino-node`,
`trino-log`, `trino-env`, `trino-password-authenticator` and `trino-exchange-manager` do not yet. With
`docker-network` set to `host`, `container:<id>` or `none` it does not run, as the metastore service does not. From
`emr-7.14.0` on, "When you select Trino as the only application at launch, Amazon EMR no longer starts YARN and HDFS";
Floci's primary node still runs the HDFS, beside the metastore.
a client meanwhile gets a `503`. Its `trino-connector-*`, `trino-config`, `trino-node`, `trino-log` and `trino-env`
classifications apply; `trino-password-authenticator` and `trino-exchange-manager` do not yet. With `docker-network`
set to `host`, `container:<id>` or `none` it does not run, as the metastore service does not. From `emr-7.14.0` on,
"When you select Trino as the only application at launch, Amazon EMR no longer starts YARN and HDFS"; Floci's primary
node still runs the HDFS, beside the metastore.
- **Tez's intermediate data is not compressed on YARN.** The images name the LZO codec for it, whose native library they
lack, so Floci turns that compression off, which a `tez-site` classification can turn back on with a codec they have.
- **No Hive metastore service in a network namespace the steps share.** With `docker-network` set to `host` or
@@ -124,10 +124,14 @@ public interface ClusterStorage {
/**
* Trino's coordinator on a cluster's primary node: the {@code image} it runs from, the memory its container gets,
* the cluster's {@code trino-connector-<catalog>} properties by catalog, which its catalogs get after Floci's (see
* {@link EmrTrino#catalogs}), and its {@code trino-config} properties, which its {@code config.properties} gets
* after Floci's (see {@link EmrTrino#config}). It reaches S3 and Glue as the metastore does.
* {@link EmrTrino#catalogs}), its {@code trino-config} properties, which its {@code config.properties} gets after
* Floci's (see {@link EmrTrino#config}), its {@code trino-node} and {@code trino-log} properties, which its
* {@code node.properties} and {@code log.properties} get after its image's own (see {@link EmrTrino#ENTRYPOINT}),
* and the variables its {@code trino-env} exports, which its environment gets after Floci's own. It reaches S3 and
* Glue as the metastore does.
*/
record Trino(String image, int memoryMb, Map<String, Map<String, String>> connectors, Map<String, String> config) {
record Trino(String image, int memoryMb, Map<String, Map<String, String>> connectors, Map<String, String> config,
Map<String, String> node, Map<String, String> log, Map<String, String> environment) {
}
/**
@@ -1609,7 +1609,13 @@ public class EmrClusterStorage implements ClusterStorage, ContainerTeardown {
.withMemoryMb(trino.memoryMb())
.withEntrypoint(List.of("/bin/bash", "-c", EmrTrino.ENTRYPOINT))
.withEnv(awsEnv.sdkBaselineEnv(region, Optional.empty(), endpoint, credentials, accountId))
// After Floci's AWS settings, which an export may change as its trino-env.sh would, and before
// the files Floci writes, which it may not: Docker keeps the last of a variable given twice.
.withEnv(trino.environment().entrySet().stream()
.map(variable -> variable.getKey() + "=" + variable.getValue()).toList())
.withEnv(EmrTrino.CONFIG_VARIABLE, EmrTrino.properties(EmrTrino.config(trino.config())))
.withEnv(EmrTrino.NODE_VARIABLE, EmrTrino.properties(trino.node()))
.withEnv(EmrTrino.LOG_VARIABLE, EmrTrino.properties(trino.log()))
.withJavaTrustStore()
.withLogRotation()
.withLabels(labels(clusterId, accountId, region, EmrTrino.COMPONENT));
@@ -3141,7 +3141,10 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
String trinoImage = trinoImage(cluster);
ClusterStorage.Trino trino = trinoImage == null ? null : new ClusterStorage.Trino(trinoImage, trinoMemoryMb,
EmrSparkSteps.trinoConnectors(cluster.getConfigurations(), SNAPSHOT_MAPPER),
EmrSparkSteps.trinoConfig(cluster.getConfigurations(), SNAPSHOT_MAPPER));
EmrSparkSteps.trinoConfig(cluster.getConfigurations(), SNAPSHOT_MAPPER),
EmrSparkSteps.trinoNode(cluster.getConfigurations(), SNAPSHOT_MAPPER),
EmrSparkSteps.trinoLog(cluster.getConfigurations(), SNAPSHOT_MAPPER),
EmrSparkSteps.trinoEnvironment(cluster.getConfigurations(), SNAPSHOT_MAPPER));
ClusterStorage.HiveMetastore hiveMetastore = withHiveImage(cluster)
? new ClusterStorage.HiveMetastore(instanceProfileRole(cluster, accountId),
EmrSparkSteps.hiveMetastoreSettings(cluster.getConfigurations(), SNAPSHOT_MAPPER), trino)
@@ -306,6 +306,24 @@ final class EmrSparkSteps {
return properties(configurations, objectMapper, EmrTrino.CONFIG_CLASSIFICATION);
}
/** The properties of a cluster's {@code trino-node}, which its Trino's {@code node.properties} gets. */
static Map<String, String> trinoNode(String configurations, ObjectMapper objectMapper) {
return properties(configurations, objectMapper, EmrTrino.NODE_CLASSIFICATION);
}
/** The properties of a cluster's {@code trino-log}, which make its Trino's {@code log.properties}. */
static Map<String, String> trinoLog(String configurations, ObjectMapper objectMapper) {
return properties(configurations, objectMapper, EmrTrino.LOG_CLASSIFICATION);
}
/**
* The variables a cluster's {@code trino-env} exports, its nested {@code export} classification's properties, as
* "If any classification ends in env, use the export sub-classification", which its Trino's environment gets.
*/
static Map<String, String> trinoEnvironment(String configurations, ObjectMapper objectMapper) {
return exports(configurations, objectMapper, EmrTrino.ENV_CLASSIFICATION);
}
// Whether a cluster's Applications name any of names, in any case, unless its release is of the AWS runtime for
// Apache Spark, which installs none of Hive, HCatalog, Pig and Trino.
private static boolean installs(String releaseLabel, String applications, ObjectMapper objectMapper,
@@ -36,6 +36,11 @@ final class EmrTrino {
static final String CONNECTOR_PREFIX = "trino-connector-";
/** The classification that changes Trino's {@code config.properties}. */
static final String CONFIG_CLASSIFICATION = "trino-config";
/** The classifications that change Trino's {@code node.properties} and {@code log.properties}. */
static final String NODE_CLASSIFICATION = "trino-node";
static final String LOG_CLASSIFICATION = "trino-log";
/** The classification whose nested {@code export} gives Trino's environment, Trino's {@code trino-env.sh}. */
static final String ENV_CLASSIFICATION = "trino-env";
/** The catalog every Trino cluster has. */
static final String HIVE = "hive";
/**
@@ -74,20 +79,29 @@ final class EmrTrino {
done
exec "$java" -jar %1$s --server "${%2$s:-localhost:%3$d}" "$@"
""".formatted(CLI, SERVER_VARIABLE, PORT);
/** The variable the Trino container's entrypoint writes its {@code config.properties} from. */
/** The variables the Trino container's entrypoint writes its configuration, node and log properties from. */
static final String CONFIG_VARIABLE = "FLOCI_TRINO_CONFIG";
static final String NODE_VARIABLE = "FLOCI_TRINO_NODE";
static final String LOG_VARIABLE = "FLOCI_TRINO_LOG";
/** The prefix of the variables it writes its catalogs from, one each, the rest of whose name names it. */
static final String CATALOG_PREFIX = "FLOCI_TRINO_CATALOG_";
/**
* The Trino container's entrypoint: its configuration, and the catalogs Floci gives it alone, as EMR's Trino has
* the catalogs the cluster configures, then Trino, as its image starts it. Its image names the node after its host,
* which is the primary node's, whose dots Trino refuses in a node's id, so the node is named with hyphens instead.
* The Trino container's entrypoint: its configuration; the cluster's node and log properties after those of its
* image's own files, which a property given twice takes the later of, so an image of the cluster's own keeps its
* settings; and the catalogs Floci gives it alone, as EMR's Trino has the catalogs the cluster configures; then
* Trino, as its image starts it. Where {@code node.properties} gives the node no id, its image names it after its
* host, the primary node's, whose dots Trino refuses in a node's id, so Floci names it with hyphens instead.
*/
static final String ENTRYPOINT = "printf '%s\\n' \"$" + CONFIG_VARIABLE + "\" > /etc/trino/config.properties"
+ " && { [ -z \"$" + NODE_VARIABLE + "\" ] || printf '\\n%s\\n' \"$" + NODE_VARIABLE + "\""
+ " >> /etc/trino/node.properties; }"
+ " && { [ -z \"$" + LOG_VARIABLE + "\" ] || printf '\\n%s\\n' \"$" + LOG_VARIABLE + "\""
+ " >> /etc/trino/log.properties; }"
+ " && rm -f /etc/trino/catalog/*.properties"
+ " && for catalog in ${!" + CATALOG_PREFIX + "@}; do printf '%s\\n' \"${!catalog}\""
+ " > \"/etc/trino/catalog/${catalog#" + CATALOG_PREFIX + "}.properties\" || exit; done"
+ " && printf 'node.id=%s\\n' \"${HOSTNAME//./-}\" >> /etc/trino/node.properties"
+ " && { grep -q '^node\\.id=' /etc/trino/node.properties"
+ " || printf '\\nnode.id=%s\\n' \"${HOSTNAME//./-}\" >> /etc/trino/node.properties; }"
+ " && exec /usr/lib/trino/bin/run-trino";
private static final String GLUE = "glue";
@@ -127,7 +127,8 @@ class EmrClusterStorageTest {
// The same with Trino beside it, from the image of emr-7.5.0's Trino.
private static final ClusterStorage.HiveMetastore TRINO_METASTORE =
new ClusterStorage.HiveMetastore("arn:aws:iam::123456789012:role/r", Map.of(),
new ClusterStorage.Trino("trinodb/trino:446", 2048, Map.of(), Map.of()));
new ClusterStorage.Trino("trinodb/trino:446", 2048, Map.of(), Map.of(), Map.of(), Map.of(),
Map.of()));
private final EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
private final DockerClient docker = mock(DockerClient.class);
@@ -2006,6 +2007,8 @@ class EmrClusterStorageTest {
verify(trinoSpec).withMemoryMb(2048);
verify(trinoSpec).withEnv(List.of("AWS_ACCESS_KEY_ID=ASIATRINO"));
verify(trinoSpec).withEnv(EmrTrino.CONFIG_VARIABLE, EmrTrino.properties(EmrTrino.config(Map.of())));
verify(trinoSpec).withEnv(EmrTrino.NODE_VARIABLE, "");
verify(trinoSpec).withEnv(EmrTrino.LOG_VARIABLE, "");
verify(trinoSpec).withEnv(EmrTrino.CATALOG_PREFIX + "hive", EmrTrino.properties(EmrTrino.catalog("hive",
Map.of(), "http://host.docker.internal:4566", "us-east-1")));
verify(trinoSpec).withEntrypoint(List.of("/bin/bash", "-c", EmrTrino.ENTRYPOINT));
@@ -2054,6 +2057,29 @@ class EmrClusterStorageTest {
assertTrue(ticking.trinoInterface("j-1", 8889).isEmpty());
}
@Test
void trinosEnvironmentIsTheClustersTrinoEnvExportsAfterFlocisAwsSettingsAndBeforeItsOwnFiles() {
String trinoName = ContainerStorageHelper.dockerName(config, "emr-j-1-trino");
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("c-6", Map.of()),
new ContainerLifecycleManager.ContainerInfo("t-1", Map.of()));
ContainerBuilder.Builder trinoSpec = trinoStarts(trinoName).spec();
ClusterStorage.HiveMetastore metastore = new ClusterStorage.HiveMetastore("arn:aws:iam::123456789012:role/r",
Map.of(), new ClusterStorage.Trino("trinodb/trino:446", 2048, Map.of(), Map.of(),
Map.of("node.environment", "production"), Map.of("io.trino", "DEBUG"),
Map.of("DB_PASSWORD", "s3cret")));
ticking.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", metastore, null, NOT_STOPPED);
// Docker keeps the last of a variable given twice: an export may change Floci's AWS settings, as its
// trino-env.sh would, but not the files Floci writes.
InOrder order = inOrder(trinoSpec);
order.verify(trinoSpec).withEnv(List.of("AWS_ACCESS_KEY_ID=ASIATRINO"));
order.verify(trinoSpec).withEnv(List.of("DB_PASSWORD=s3cret"));
order.verify(trinoSpec).withEnv(EmrTrino.CONFIG_VARIABLE, EmrTrino.properties(EmrTrino.config(Map.of())));
order.verify(trinoSpec).withEnv(EmrTrino.NODE_VARIABLE, "node.environment=production");
order.verify(trinoSpec).withEnv(EmrTrino.LOG_VARIABLE, "io.trino=DEBUG");
}
@Test
void trinoIsReadyOnceItHasRunAQueryForTenSecondsAFailureBetweenStartingThemAgain() {
String trinoName = ContainerStorageHelper.dockerName(config, "emr-j-1-trino");
@@ -1110,7 +1110,11 @@ class EmrServiceContainerStepsTest {
requested.setApplications(TRINO);
requested.setConfigurations("[{\"Classification\": \"trino-connector-hive\", \"Properties\": "
+ "{\"hive.metastore\": \"glue\"}}, {\"Classification\": \"trino-connector-tpch\"}, "
+ "{\"Classification\": \"trino-config\", \"Properties\": {\"http-server.http.port\": \"8890\"}}]");
+ "{\"Classification\": \"trino-config\", \"Properties\": {\"http-server.http.port\": \"8890\"}}, "
+ "{\"Classification\": \"trino-node\", \"Properties\": {\"node.environment\": \"production\"}}, "
+ "{\"Classification\": \"trino-log\", \"Properties\": {\"io.trino\": \"DEBUG\"}}, "
+ "{\"Classification\": \"trino-env\", \"Configurations\": [{\"Classification\": \"export\", "
+ "\"Properties\": {\"DB_PASSWORD\": \"s3cret\"}}]}]");
withTrino.runJobFlow(requested, REGION);
fixture.runStepThread();
@@ -1122,8 +1126,9 @@ class EmrServiceContainerStepsTest {
fixture.releaseImages.asked);
assertEquals(List.of("trinodb/trino:446"), fixture.releaseImages.trinoImages);
assertEquals(new ClusterStorage.Trino("trinodb/trino:446", 2048, Map.of("hive", Map.of("hive.metastore",
"glue"), "tpch", Map.of()), Map.of("http-server.http.port", "8890")),
fixture.clusterStorage.metastores.get(0).trino());
"glue"), "tpch", Map.of()), Map.of("http-server.http.port", "8890"),
Map.of("node.environment", "production"), Map.of("io.trino", "DEBUG"),
Map.of("DB_PASSWORD", "s3cret")), fixture.clusterStorage.metastores.get(0).trino());
SparkJobRunner.Job job = runner.jobs.get(0);
assertEquals(args, job.command());
String host = fixture.clusterStorage.hdfs.get(0).get(1);
@@ -1146,8 +1151,8 @@ class EmrServiceContainerStepsTest {
fixture.runStepThread();
fixture.runStepThread();
assertEquals(List.of("true"), runner.jobs.get(0).command());
assertEquals(new ClusterStorage.Trino("trinodb/trino:446", 2048, Map.of(), Map.of()),
fixture.clusterStorage.metastores.get(0).trino());
assertEquals(new ClusterStorage.Trino("trinodb/trino:446", 2048, Map.of(), Map.of(), Map.of(), Map.of(),
Map.of()), fixture.clusterStorage.metastores.get(0).trino());
assertEquals(0, fixture.stepThreadsWaiting());
}
@@ -245,6 +245,24 @@ class EmrSparkStepsTest {
assertFalse(EmrSparkSteps.installsTrino("emr-spark-8.1.0", "[{\"Name\": \"Trino\"}]", objectMapper));
}
@Test
void trinosNodeLogAndEnvironmentAreTheClustersTrinoNodeLogAndEnvExports() {
String configurations = """
[{"Classification": "trino-node", "Properties": {"node.environment": "production"}},
{"Classification": "trino-log", "Properties": {"io.trino": "DEBUG"}},
{"Classification": "trino-env", "Properties": {},
"Configurations": [{"Classification": "export", "Properties": {"DB_PASSWORD": "s3cret"}}]},
{"Classification": "hadoop-env",
"Configurations": [{"Classification": "export", "Properties": {"HADOOP_HEAPSIZE": "2048"}}]}]
""";
assertEquals(Map.of("node.environment", "production"), EmrSparkSteps.trinoNode(configurations, objectMapper));
assertEquals(Map.of("io.trino", "DEBUG"), EmrSparkSteps.trinoLog(configurations, objectMapper));
// "If any classification ends in env, use the export sub-classification."
assertEquals(Map.of("DB_PASSWORD", "s3cret"), EmrSparkSteps.trinoEnvironment(configurations, objectMapper));
assertEquals(Map.of(), EmrSparkSteps.trinoEnvironment(null, objectMapper));
}
@Test
void trinosCatalogsAreTheClustersTrinoConnectorsALaterConfigurationWinning() {
String configurations = """
@@ -62,7 +62,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* queries" does, over a CSV in Floci's S3. Its {@code hive} catalog is the cluster's Hive metastore, or, with
* {@code trino-connector-hive} setting {@code hive.metastore} to {@code glue}, Floci's Glue Data Catalog. The
* cluster's other {@code trino-connector-<catalog>} classifications add catalogs, Iceberg's on Glue as the Release
* Guide's "Use an Iceberg cluster with Trino" has it, and its {@code trino-config} moves Trino to another port. A
* Guide's "Use an Iceberg cluster with Trino" has it, its {@code trino-config} moves Trino to another port, and its
* {@code trino-node}, {@code trino-log} and {@code trino-env} reach Trino's node, log and environment. A
* cluster with no step starts its Trino as it becomes ready, and a client outside the cluster queries it through Floci
* on the cluster's own host.
*
@@ -187,12 +188,17 @@ class EmrTrinoNightlyIntegrationTest {
}
glue.deleteDatabase(request -> request.name(schema));
});
// The Release Guide's Iceberg catalog on the Glue Data Catalog, a TPC-H one, and another port.
// The Release Guide's Iceberg catalog on the Glue Data Catalog, a TPC-H one, and another port; and the node's
// environment, a logger, and a variable trino-env exports, which the Iceberg catalog's file format names.
startCluster("""
[{"Classification": "trino-connector-iceberg",
"Properties": {"connector.name": "iceberg", "iceberg.catalog.type": "glue"}},
[{"Classification": "trino-connector-iceberg", "Properties": {"connector.name": "iceberg",
"iceberg.catalog.type": "glue", "iceberg.file-format": "${ENV:ICEBERG_FORMAT}"}},
{"Classification": "trino-connector-tpch", "Properties": {}},
{"Classification": "trino-config", "Properties": {"http-server.http.port": "8890"}}]""");
{"Classification": "trino-config", "Properties": {"http-server.http.port": "8890"}},
{"Classification": "trino-node", "Properties": {"node.environment": "production"}},
{"Classification": "trino-log", "Properties": {"io.trino": "INFO"}},
{"Classification": "trino-env",
"Configurations": [{"Classification": "export", "Properties": {"ICEBERG_FORMAT": "ORC"}}]}]""");
String step = trinoStep("SHOW CATALOGS; CREATE SCHEMA iceberg." + schema + " WITH (location = '"
+ s3Uri("iceberg/") + "'); CREATE TABLE iceberg." + schema + ".nation AS SELECT nationkey, name FROM "
@@ -206,6 +212,9 @@ class EmrTrinoNightlyIntegrationTest {
assertEquals("ICEBERG", glue.getTable(request -> request.databaseName(schema).name("nation")).table()
.parameters().get("table_type").toUpperCase(Locale.ROOT));
assertFalse(s3.listObjectsV2(request -> request.bucket(bucket).prefix("iceberg/")).contents().isEmpty());
// In the file format trino-env's variable gave the catalog.
assertTrue(s3.listObjectsV2(request -> request.bucket(bucket).prefix("iceberg/")).contents().stream()
.anyMatch(object -> object.key().endsWith(".orc")));
}
// No step: Trino starts with the cluster, and a client outside the cluster's network queries it through Floci on
@@ -157,27 +157,17 @@ class EmrTrinoTest {
}
@Test
void theEntrypointWritesTheConfigurationTheCatalogsFlociGivesAloneAndANodeIdTrinoTakes(@TempDir Path etc)
void theEntrypointWritesTheConfigurationNodeLogAndCatalogsFlociGivesAloneAndANodeIdTrinoTakes(@TempDir Path etc)
throws Exception {
Files.createDirectories(etc.resolve("catalog"));
Files.writeString(etc.resolve("catalog/tpcds.properties"), "connector.name=tpcds\n");
Files.writeString(etc.resolve("node.properties"), "node.environment=docker\n");
// The image's /etc/trino here, and its Trino left out.
String entrypoint = EmrTrino.ENTRYPOINT.replace("/etc/trino", etc.toString())
.replace("exec /usr/lib/trino/bin/run-trino", "true");
assertTrue(EmrTrino.ENTRYPOINT.endsWith("exec /usr/lib/trino/bin/run-trino"));
ProcessBuilder builder = new ProcessBuilder("bash", "-c", entrypoint).redirectErrorStream(true);
String config = EmrTrino.properties(EmrTrino.config(Map.of()));
builder.environment().put(EmrTrino.CONFIG_VARIABLE, config);
builder.environment().put(EmrTrino.CATALOG_PREFIX + "hive", "connector.name=hive");
builder.environment().put(EmrTrino.CATALOG_PREFIX + "iceberg",
"connector.name=iceberg\niceberg.catalog.type=glue");
// The primary node's host name, which the container shares.
builder.environment().put("HOSTNAME", "ip-10-0-0-1.ec2.internal");
Process process = builder.start();
String output = new String(process.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
assertTrue(process.waitFor(30, TimeUnit.SECONDS));
assertEquals(0, process.exitValue(), output);
Map<String, String> environment = new LinkedHashMap<>();
environment.put(EmrTrino.CONFIG_VARIABLE, config);
environment.put(EmrTrino.NODE_VARIABLE, "node.environment=production");
environment.put(EmrTrino.LOG_VARIABLE, "io.trino=DEBUG");
environment.put(EmrTrino.CATALOG_PREFIX + "hive", "connector.name=hive");
environment.put(EmrTrino.CATALOG_PREFIX + "iceberg", "connector.name=iceberg\niceberg.catalog.type=glue");
runEntrypoint(etc, environment);
assertEquals(config + "\n", Files.readString(etc.resolve("config.properties")));
try (Stream<Path> catalogs = Files.list(etc.resolve("catalog"))) {
@@ -187,12 +177,62 @@ class EmrTrinoTest {
assertEquals("connector.name=hive\n", Files.readString(etc.resolve("catalog/hive.properties")));
assertEquals("connector.name=iceberg\niceberg.catalog.type=glue\n",
Files.readString(etc.resolve("catalog/iceberg.properties")));
// Trino takes letters, digits, hyphens and underscores in a node's id, and the image's run-trino names none
// once node.properties does.
assertEquals("node.environment=docker\nnode.id=ip-10-0-0-1-ec2-internal\n",
// The image's node and log properties, the classification's after them, which Trino takes the later of,
// and an id Trino takes: letters, digits, hyphens and underscores, as the image's run-trino names none once
// node.properties does.
assertEquals("node.environment=docker\nnode.data-dir=/data/trino\n\nnode.environment=production\n"
+ "\nnode.id=ip-10-0-0-1-ec2-internal\n", Files.readString(etc.resolve("node.properties")));
assertEquals("# Enable verbose logging from Trino\n#io.trino=DEBUG\n\nio.trino=DEBUG\n",
Files.readString(etc.resolve("log.properties")));
}
@Test
void aNodeIdTheClusterGivesIsTrinosOwn(@TempDir Path etc) throws Exception {
runEntrypoint(etc, Map.of(EmrTrino.NODE_VARIABLE, "node.id=coordinator-1"));
assertEquals("node.environment=docker\nnode.data-dir=/data/trino\n\nnode.id=coordinator-1\n",
Files.readString(etc.resolve("node.properties")));
}
@Test
void anImageOfTheClustersOwnKeepsItsNodeAndLogSettingsWhereTheClusterGivesNone(@TempDir Path etc)
throws Exception {
// trino.image may name an image whose files differ from the Trino project's.
Files.writeString(etc.resolve("node.properties"), "node.environment=staging\nnode.data-dir=/var/lib/trino");
Files.writeString(etc.resolve("log.properties"), "io.trino=WARN\n");
runEntrypoint(etc, Map.of(EmrTrino.NODE_VARIABLE, "", EmrTrino.LOG_VARIABLE, ""));
// Its last line had no newline of its own.
assertEquals("node.environment=staging\nnode.data-dir=/var/lib/trino\nnode.id=ip-10-0-0-1-ec2-internal\n",
Files.readString(etc.resolve("node.properties")));
assertEquals("io.trino=WARN\n", Files.readString(etc.resolve("log.properties")));
}
// Runs the Trino container's entrypoint with environment, over an /etc/trino here as the Trino project's image
// ships it, unless the test wrote its own files, its Trino left out, on the primary node's host name, which the
// container shares.
private static void runEntrypoint(Path etc, Map<String, String> environment) throws Exception {
Files.createDirectories(etc.resolve("catalog"));
Files.writeString(etc.resolve("catalog/tpcds.properties"), "connector.name=tpcds\n");
if (!Files.exists(etc.resolve("node.properties"))) {
Files.writeString(etc.resolve("node.properties"), "node.environment=docker\nnode.data-dir=/data/trino\n");
}
if (!Files.exists(etc.resolve("log.properties"))) {
Files.writeString(etc.resolve("log.properties"), "# Enable verbose logging from Trino\n#io.trino=DEBUG\n");
}
String entrypoint = EmrTrino.ENTRYPOINT.replace("/etc/trino", etc.toString())
.replace("exec /usr/lib/trino/bin/run-trino", "true");
assertTrue(EmrTrino.ENTRYPOINT.endsWith("exec /usr/lib/trino/bin/run-trino"));
ProcessBuilder builder = new ProcessBuilder("bash", "-c", entrypoint).redirectErrorStream(true);
builder.environment().putAll(environment);
builder.environment().put("HOSTNAME", "ip-10-0-0-1.ec2.internal");
Process process = builder.start();
String output = new String(process.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
assertTrue(process.waitFor(30, TimeUnit.SECONDS));
assertEquals(0, process.exitValue(), output);
}
@Test
void trinoCliReachesTheClustersCoordinatorUnlessTheStepNamesAServer(@TempDir Path folder) throws Exception {
// A java that prints its arguments, one to a line, in place of the image's Java 17.