diff --git a/docs/services/emr.md b/docs/services/emr.md index 5c96bbbb1a..676699f6d0 100644 --- a/docs/services/emr.md +++ b/docs/services/emr.md @@ -853,18 +853,27 @@ holding the driver and its executors, or a command or a script. The cluster itse 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://.emr-trino.:`, as EMR's reach Trino's port on the primary node: Trino's CLI - with `--server=http://j-2AXXXXXXGAPLF.emr-trino.localhost:4566`, or + connector's do, after Floci's own AWS settings, which they may change. `trino-exchange-manager`, which on EMR + "internally creates a etc/exchange-manager.properties configuration file" for fault-tolerant execution, which a + `trino-config` `retry-policy` of `QUERY` or `TASK` turns on, makes Trino's exchange manager: with no properties, EMR's + default, as "By default, Amazon EMR releases 6.9.0 and later use HDFS as an exchange manager" and "spooling occurs in + the trino-exchange/ directory", the cluster's HDFS under the home of Trino's `trino` user; `exchange.base-directories` + with `exchange.use-local-hdfs` set names directories in that HDFS, and one in S3 spools in Floci's S3. The Trino + project's Trino takes neither EMR's `exchange.use-local-hdfs` nor an `hdfs://` directory in the `filesystem` exchange + manager EMR names, so Floci leaves the first out and gives HDFS directories Trino's own `hdfs` exchange manager, its + `hdfs.config.resources` a `core-site.xml` that names the cluster's NameNode, as EMR's "uses the paths to + core-site.xml, hdfs-site.xml files". 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://.emr-trino.:`, 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 @@ -1096,11 +1105,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-*`, `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:` 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`, `trino-env` and + `trino-exchange-manager` classifications apply; `trino-password-authenticator` does not yet. With `docker-network` set + to `host`, `container:` 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 diff --git a/src/main/java/io/floci/aws/services/emr/ClusterStorage.java b/src/main/java/io/floci/aws/services/emr/ClusterStorage.java index d6662bf261..e594cb24ac 100644 --- a/src/main/java/io/floci/aws/services/emr/ClusterStorage.java +++ b/src/main/java/io/floci/aws/services/emr/ClusterStorage.java @@ -127,11 +127,13 @@ public interface ClusterStorage { * {@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. + * the variables its {@code trino-env} exports, which its environment gets after Floci's own, and its + * {@code trino-exchange-manager} properties, null where it has none, which make its exchange manager (see + * {@link EmrTrino#exchangeManager}). It reaches S3 and Glue as the metastore does. */ record Trino(String image, int memoryMb, Map> connectors, Map config, - Map node, Map log, Map environment) { + Map node, Map log, Map environment, + Map exchangeManager) { } /** diff --git a/src/main/java/io/floci/aws/services/emr/EmrClusterStorage.java b/src/main/java/io/floci/aws/services/emr/EmrClusterStorage.java index 60fa253a2d..b99f6ed07b 100644 --- a/src/main/java/io/floci/aws/services/emr/EmrClusterStorage.java +++ b/src/main/java/io/floci/aws/services/emr/EmrClusterStorage.java @@ -1621,6 +1621,10 @@ public class EmrClusterStorage implements ClusterStorage, ContainerTeardown { .withLabels(labels(clusterId, accountId, region, EmrTrino.COMPONENT)); EmrTrino.catalogs(trino.connectors(), endpoint, region).forEach((catalog, properties) -> spec.withEnv(EmrTrino.CATALOG_PREFIX + catalog, EmrTrino.properties(properties))); + if (trino.exchangeManager() != null) { + spec.withEnv(EmrTrino.EXCHANGE_VARIABLE, EmrTrino.properties(EmrTrino.exchangeManager( + trino.exchangeManager(), endpoint, region))); + } lifecycleManager.createAndStart(spec.build()); } catch (RuntimeException e) { releaseSession(name); diff --git a/src/main/java/io/floci/aws/services/emr/EmrService.java b/src/main/java/io/floci/aws/services/emr/EmrService.java index 439f69e89b..254e6b1bd2 100644 --- a/src/main/java/io/floci/aws/services/emr/EmrService.java +++ b/src/main/java/io/floci/aws/services/emr/EmrService.java @@ -3144,7 +3144,8 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear EmrSparkSteps.trinoConfig(cluster.getConfigurations(), SNAPSHOT_MAPPER), EmrSparkSteps.trinoNode(cluster.getConfigurations(), SNAPSHOT_MAPPER), EmrSparkSteps.trinoLog(cluster.getConfigurations(), SNAPSHOT_MAPPER), - EmrSparkSteps.trinoEnvironment(cluster.getConfigurations(), SNAPSHOT_MAPPER)); + EmrSparkSteps.trinoEnvironment(cluster.getConfigurations(), SNAPSHOT_MAPPER), + EmrSparkSteps.trinoExchangeManager(cluster.getConfigurations(), SNAPSHOT_MAPPER)); ClusterStorage.HiveMetastore hiveMetastore = withHiveImage(cluster) ? new ClusterStorage.HiveMetastore(instanceProfileRole(cluster, accountId), EmrSparkSteps.hiveMetastoreSettings(cluster.getConfigurations(), SNAPSHOT_MAPPER), trino) diff --git a/src/main/java/io/floci/aws/services/emr/EmrSparkSteps.java b/src/main/java/io/floci/aws/services/emr/EmrSparkSteps.java index f19533b5a4..3e078290ad 100644 --- a/src/main/java/io/floci/aws/services/emr/EmrSparkSteps.java +++ b/src/main/java/io/floci/aws/services/emr/EmrSparkSteps.java @@ -311,6 +311,16 @@ final class EmrSparkSteps { return properties(configurations, objectMapper, EmrTrino.NODE_CLASSIFICATION); } + /** + * The properties of a cluster's {@code trino-exchange-manager}, which make its Trino's exchange manager, or null + * where it has none: one with no properties gives EMR's default, "To use the default settings, set the following + * configuration: { "Classification": "trino-exchange-manager" }". + */ + static Map trinoExchangeManager(String configurations, ObjectMapper objectMapper) { + return classified(configurations, objectMapper, EmrTrino.EXCHANGE_CLASSIFICATION).isEmpty() ? null + : properties(configurations, objectMapper, EmrTrino.EXCHANGE_CLASSIFICATION); + } + /** The properties of a cluster's {@code trino-log}, which make its Trino's {@code log.properties}. */ static Map trinoLog(String configurations, ObjectMapper objectMapper) { return properties(configurations, objectMapper, EmrTrino.LOG_CLASSIFICATION); diff --git a/src/main/java/io/floci/aws/services/emr/EmrTrino.java b/src/main/java/io/floci/aws/services/emr/EmrTrino.java index 0bf5d8f8e8..e3c2fc33f1 100644 --- a/src/main/java/io/floci/aws/services/emr/EmrTrino.java +++ b/src/main/java/io/floci/aws/services/emr/EmrTrino.java @@ -1,6 +1,7 @@ package io.floci.aws.services.emr; import java.net.URI; +import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; @@ -39,6 +40,8 @@ final class EmrTrino { /** 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 that makes Trino's {@code exchange-manager.properties}, for fault-tolerant execution. */ + static final String EXCHANGE_CLASSIFICATION = "trino-exchange-manager"; /** 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. */ @@ -83,6 +86,17 @@ final class EmrTrino { static final String CONFIG_VARIABLE = "FLOCI_TRINO_CONFIG"; static final String NODE_VARIABLE = "FLOCI_TRINO_NODE"; static final String LOG_VARIABLE = "FLOCI_TRINO_LOG"; + static final String EXCHANGE_VARIABLE = "FLOCI_TRINO_EXCHANGE"; + /** The cluster's NameNode, which Trino reaches on the primary node whose network it shares. */ + static final String NAMENODE = "hdfs://localhost:8020"; + /** + * The Hadoop configuration Trino's {@code hdfs} exchange manager reads, as EMR's {@code hdfs.config.resources} + * names "the paths to core-site.xml, hdfs-site.xml files": its default file system the cluster's NameNode, without + * which Trino takes an {@code hdfs://} directory for another file system's, "Wrong FS ... expected: file:///". + */ + static final String EXCHANGE_HDFS_CONFIG = "/etc/trino/exchange-core-site.xml"; + static final String EXCHANGE_CORE_SITE = "fs.defaultFS" + NAMENODE + + ""; /** 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_"; /** @@ -97,6 +111,9 @@ final class EmrTrino { + " >> /etc/trino/node.properties; }" + " && { [ -z \"$" + LOG_VARIABLE + "\" ] || printf '\\n%s\\n' \"$" + LOG_VARIABLE + "\"" + " >> /etc/trino/log.properties; }" + + " && { [ -z \"$" + EXCHANGE_VARIABLE + "\" ] || { printf '%s\\n' \"$" + EXCHANGE_VARIABLE + "\"" + + " > /etc/trino/exchange-manager.properties && printf '%s\\n' '" + EXCHANGE_CORE_SITE + "' > " + + EXCHANGE_HDFS_CONFIG + "; }; }" + " && 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" @@ -105,6 +122,13 @@ final class EmrTrino { + " && exec /usr/lib/trino/bin/run-trino"; private static final String GLUE = "glue"; + // EMR's exchange manager properties that Trino's own does not take, and the one Floci maps them onto. + private static final String USE_LOCAL_HDFS = "exchange.use-local-hdfs"; + private static final String BASE_DIRECTORIES = "exchange.base-directories"; + // "spooling occurs in the trino-exchange/ directory by default", relative, so in the HDFS home of the user Trino + // runs as, its image's trino, on the cluster's NameNode, which Trino reaches on the primary node it shares. + private static final String DEFAULT_EXCHANGE_DIRECTORY = "trino-exchange/"; + private static final String HDFS_HOME = "/user/trino/"; private static final String METASTORE_URI = "hive.metastore.uri"; // The catalogs of EMR's classifications whose connector Trino names otherwise; the others are named as theirs. private static final Map CONNECTORS = Map.of("delta", "delta_lake", "raptor", "raptor_legacy"); @@ -183,6 +207,47 @@ final class EmrTrino { return config; } + /** + * Trino's {@code exchange-manager.properties} for a cluster's {@code trino-exchange-manager}, which on EMR + * "internally creates a etc/exchange-manager.properties configuration file" and "sets exchange-manager.name ... to + * filesystem", HDFS by default ("By default, Amazon EMR releases 6.9.0 and later use HDFS as an exchange manager"), + * spooling "in the trino-exchange/ directory", or where {@code exchange.base-directories} says, which with + * {@code exchange.use-local-hdfs} names HDFS directories. The Trino project's Trino takes neither EMR's + * {@code exchange.use-local-hdfs} nor an {@code hdfs://} directory in a {@code filesystem} exchange manager, so a + * directory with no scheme is the cluster's HDFS in its own {@code hdfs} exchange manager; one in S3 is Floci's S3 + * at {@code endpoint} in {@code region}, by path; and the classification's other properties come after these. + */ + static Map exchangeManager(Map classification, String endpoint, String region) { + List directories = new ArrayList<>(); + for (String directory : classification.getOrDefault(BASE_DIRECTORIES, DEFAULT_EXCHANGE_DIRECTORY).split(",")) { + String trimmed = directory.trim(); + if (trimmed.isEmpty()) { + continue; + } + directories.add(trimmed.contains("://") ? trimmed + : NAMENODE + (trimmed.startsWith("/") ? trimmed : HDFS_HOME + trimmed)); + } + boolean hdfs = directories.stream().anyMatch(directory -> directory.startsWith("hdfs://")); + Map exchange = new LinkedHashMap<>(); + exchange.put("exchange-manager.name", hdfs ? "hdfs" : "filesystem"); + exchange.put(BASE_DIRECTORIES, String.join(",", directories)); + if (hdfs) { + exchange.put("hdfs.config.resources", EXCHANGE_HDFS_CONFIG); + } + if (directories.stream().anyMatch(directory -> directory.startsWith("s3://") + || directory.startsWith("s3a://"))) { + exchange.put("exchange.s3.endpoint", endpoint); + exchange.put("exchange.s3.region", region); + exchange.put("exchange.s3.path-style-access", "true"); + } + classification.forEach((key, value) -> { + if (!key.equals(USE_LOCAL_HDFS) && !key.equals(BASE_DIRECTORIES) && !key.equals("exchange-manager.name")) { + exchange.put(key, value); + } + }); + return exchange; + } + /** * Trino's catalogs, by name: {@code hive}, then each that {@code connectors}, the cluster's * {@code trino-connector-} classifications' properties by catalog, name (see {@link #catalog}). diff --git a/src/test/java/io/floci/aws/services/emr/EmrClusterStorageTest.java b/src/test/java/io/floci/aws/services/emr/EmrClusterStorageTest.java index 47c198f64f..107f03d16e 100644 --- a/src/test/java/io/floci/aws/services/emr/EmrClusterStorageTest.java +++ b/src/test/java/io/floci/aws/services/emr/EmrClusterStorageTest.java @@ -128,7 +128,7 @@ class EmrClusterStorageTest { 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(), Map.of(), Map.of(), - Map.of())); + Map.of(), null)); private final EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS); private final DockerClient docker = mock(DockerClient.class); @@ -2009,6 +2009,8 @@ class EmrClusterStorageTest { verify(trinoSpec).withEnv(EmrTrino.CONFIG_VARIABLE, EmrTrino.properties(EmrTrino.config(Map.of()))); verify(trinoSpec).withEnv(EmrTrino.NODE_VARIABLE, ""); verify(trinoSpec).withEnv(EmrTrino.LOG_VARIABLE, ""); + // No trino-exchange-manager, so no exchange manager, as on EMR. + verify(trinoSpec, never()).withEnv(eq(EmrTrino.EXCHANGE_VARIABLE), anyString()); 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)); @@ -2066,7 +2068,7 @@ class EmrClusterStorageTest { 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"))); + Map.of("DB_PASSWORD", "s3cret"), Map.of("exchange.base-directories", "s3://spool/exchange"))); ticking.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", metastore, null, NOT_STOPPED); @@ -2078,6 +2080,11 @@ class EmrClusterStorageTest { 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"); + // Its exchange manager's spool in Floci's S3. + verify(trinoSpec).withEnv(EmrTrino.EXCHANGE_VARIABLE, "exchange-manager.name=filesystem\n" + + "exchange.base-directories=s3://spool/exchange\n" + + "exchange.s3.endpoint=http://host.docker.internal:4566\n" + + "exchange.s3.region=us-east-1\nexchange.s3.path-style-access=true"); } @Test diff --git a/src/test/java/io/floci/aws/services/emr/EmrServiceContainerStepsTest.java b/src/test/java/io/floci/aws/services/emr/EmrServiceContainerStepsTest.java index c859714e29..ea5566b4de 100644 --- a/src/test/java/io/floci/aws/services/emr/EmrServiceContainerStepsTest.java +++ b/src/test/java/io/floci/aws/services/emr/EmrServiceContainerStepsTest.java @@ -1114,7 +1114,8 @@ class EmrServiceContainerStepsTest { + "{\"Classification\": \"trino-node\", \"Properties\": {\"node.environment\": \"production\"}}, " + "{\"Classification\": \"trino-log\", \"Properties\": {\"io.trino\": \"DEBUG\"}}, " + "{\"Classification\": \"trino-env\", \"Configurations\": [{\"Classification\": \"export\", " - + "\"Properties\": {\"DB_PASSWORD\": \"s3cret\"}}]}]"); + + "\"Properties\": {\"DB_PASSWORD\": \"s3cret\"}}]}, " + + "{\"Classification\": \"trino-exchange-manager\"}]"); withTrino.runJobFlow(requested, REGION); fixture.runStepThread(); @@ -1128,7 +1129,7 @@ class EmrServiceContainerStepsTest { 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"), Map.of("node.environment", "production"), Map.of("io.trino", "DEBUG"), - Map.of("DB_PASSWORD", "s3cret")), fixture.clusterStorage.metastores.get(0).trino()); + Map.of("DB_PASSWORD", "s3cret"), Map.of()), 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); @@ -1152,7 +1153,7 @@ class EmrServiceContainerStepsTest { fixture.runStepThread(); assertEquals(List.of("true"), runner.jobs.get(0).command()); assertEquals(new ClusterStorage.Trino("trinodb/trino:446", 2048, Map.of(), Map.of(), Map.of(), Map.of(), - Map.of()), fixture.clusterStorage.metastores.get(0).trino()); + Map.of(), null), fixture.clusterStorage.metastores.get(0).trino()); assertEquals(0, fixture.stepThreadsWaiting()); } diff --git a/src/test/java/io/floci/aws/services/emr/EmrSparkStepsTest.java b/src/test/java/io/floci/aws/services/emr/EmrSparkStepsTest.java index 638bd792c2..8e7dd96ddf 100644 --- a/src/test/java/io/floci/aws/services/emr/EmrSparkStepsTest.java +++ b/src/test/java/io/floci/aws/services/emr/EmrSparkStepsTest.java @@ -261,6 +261,10 @@ class EmrSparkStepsTest { // "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)); + // An exchange manager only where the cluster names one, one with no properties at EMR's defaults. + assertNull(EmrSparkSteps.trinoExchangeManager(configurations, objectMapper)); + assertEquals(Map.of(), EmrSparkSteps.trinoExchangeManager("[{\"Classification\": \"trino-exchange-manager\"}]", + objectMapper)); } @Test diff --git a/src/test/java/io/floci/aws/services/emr/EmrTrinoNightlyIntegrationTest.java b/src/test/java/io/floci/aws/services/emr/EmrTrinoNightlyIntegrationTest.java index 16011fa17c..ae5f3279ba 100644 --- a/src/test/java/io/floci/aws/services/emr/EmrTrinoNightlyIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/emr/EmrTrinoNightlyIntegrationTest.java @@ -63,7 +63,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * {@code trino-connector-hive} setting {@code hive.metastore} to {@code glue}, Floci's Glue Data Catalog. The * cluster's other {@code trino-connector-} classifications add catalogs, Iceberg's on Glue as the Release * 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 + * {@code trino-node}, {@code trino-log} and {@code trino-env} reach Trino's node, log and environment, and its + * {@code trino-exchange-manager} spools a fault-tolerant query in the cluster's HDFS. 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. * @@ -188,13 +189,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; and the node's - // environment, a logger, and a variable trino-env exports, which the Iceberg catalog's file format names. + // The Release Guide's Iceberg catalog on the Glue Data Catalog, a TPC-H one, and another port; the node's + // environment, a logger, and a variable trino-env exports, which the Iceberg catalog's file format names; and + // fault-tolerant execution, its exchange manager at EMR's defaults, spooling in the cluster's HDFS, without + // which Trino refuses a query under a TASK retry policy. startCluster(""" [{"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", "retry-policy": "TASK"}}, + {"Classification": "trino-exchange-manager"}, {"Classification": "trino-node", "Properties": {"node.environment": "production"}}, {"Classification": "trino-log", "Properties": {"io.trino": "INFO"}}, {"Classification": "trino-env", diff --git a/src/test/java/io/floci/aws/services/emr/EmrTrinoTest.java b/src/test/java/io/floci/aws/services/emr/EmrTrinoTest.java index 3f0aaf7ef5..e36f80014f 100644 --- a/src/test/java/io/floci/aws/services/emr/EmrTrinoTest.java +++ b/src/test/java/io/floci/aws/services/emr/EmrTrinoTest.java @@ -19,6 +19,7 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -148,6 +149,39 @@ class EmrTrinoTest { EmrTrino.readyQuery(8890)); } + @Test + void theExchangeManagerSpoolsInTheClustersHdfsByDefaultAsEmrsDoesInTrinoExchange() { + // "To use the default settings, set the following configuration: + // { "Classification": "trino-exchange-manager" }" + assertEquals(List.of("exchange-manager.name=hdfs", + "exchange.base-directories=hdfs://localhost:8020/user/trino/trino-exchange/", + "hdfs.config.resources=/etc/trino/exchange-core-site.xml"), + List.of(EmrTrino.properties(EmrTrino.exchangeManager(Map.of(), ENDPOINT, "us-east-1")).split("\n"))); + // "Set exchange.use-local-hdfs to true. Set exchange.base-directories to the custom directory location in + // HDFS", a property the Trino project's Trino does not take; the HDFS settings EMR lists go on. + Map custom = new LinkedHashMap<>(); + custom.put("exchange.use-local-hdfs", "true"); + custom.put("exchange.base-directories", "/exchange"); + custom.put("exchange.hdfs.block-size", "8MB"); + assertEquals(List.of("exchange-manager.name=hdfs", "exchange.base-directories=hdfs://localhost:8020/exchange", + "hdfs.config.resources=/etc/trino/exchange-core-site.xml", "exchange.hdfs.block-size=8MB"), + List.of(EmrTrino.properties(EmrTrino.exchangeManager(custom, ENDPOINT, "us-east-1")).split("\n"))); + } + + @Test + void anExchangeManagerInS3SpoolsInFlocisS3ItsOwnPropertiesWinning() { + Map s3 = new LinkedHashMap<>(); + s3.put("exchange.base-directories", "s3://spool-a/exchange, s3://spool-b/exchange"); + s3.put("exchange.s3.path-style-access", "false"); + s3.put("exchange.sink-buffers-per-partition", "4"); + + assertEquals(List.of("exchange-manager.name=filesystem", + "exchange.base-directories=s3://spool-a/exchange,s3://spool-b/exchange", + "exchange.s3.endpoint=" + ENDPOINT, "exchange.s3.region=eu-west-1", + "exchange.s3.path-style-access=false", "exchange.sink-buffers-per-partition=4"), + List.of(EmrTrino.properties(EmrTrino.exchangeManager(s3, ENDPOINT, "eu-west-1")).split("\n"))); + } + @Test void clientsOutsideTheClusterReachItsTrinoOnAHostOfTheClustersOwnUnderFlocis() { assertEquals("http://j-2axxxxxxgaplf.emr-trino.localhost:4566", @@ -192,6 +226,20 @@ class EmrTrinoTest { assertEquals("node.environment=docker\nnode.data-dir=/data/trino\n\nnode.id=coordinator-1\n", Files.readString(etc.resolve("node.properties"))); + // No trino-exchange-manager, no exchange manager. + assertFalse(Files.exists(etc.resolve("exchange-manager.properties"))); + } + + @Test + void theEntrypointWritesTheExchangeManagerTheClusterGives(@TempDir Path etc) throws Exception { + String exchange = EmrTrino.properties(EmrTrino.exchangeManager(Map.of(), ENDPOINT, "us-east-1")); + + runEntrypoint(etc, Map.of(EmrTrino.EXCHANGE_VARIABLE, exchange)); + + assertEquals(exchange + "\n", Files.readString(etc.resolve("exchange-manager.properties"))); + // The Hadoop configuration its hdfs.config.resources names, the cluster's NameNode its default file system. + assertEquals("fs.defaultFShdfs://localhost:8020" + + "\n", Files.readString(etc.resolve("exchange-core-site.xml"))); } @Test