feat(emr): run a MapReduce JobHistory server on a cluster's primary node (#8662)

EMR's primary node runs one (a release's mapred-site classification
"Restarts Hadoop MapReduce-HistoryServer"); Floci's did not, so a
client asking about a MapReduce job whose application master had ended,
for its counters or task reports, waited about 30 seconds a call on
0.0.0.0:10020 and got nothing. Pig asks after each of its MapReduce
jobs, so #8636 turned its task reports off and gave its client one try.

A cluster that runs YARN now starts `mapred historyserver` beside the
ResourceManager, on Hadoop's own ports and where HDFS listens, from the
jobs' history in the cluster's HDFS, and its primary node is ready once
the server answers. A step's MapReduce settings name it, and so do a
Hive step's, for a query run on MapReduce; an emr-spark-* node runs it
from the Hadoop it keeps apart. The node scripts' readiness waits share
one helper. Pig's
workaround goes: its MapReduce jobs' counters come from the server, as
on EMR.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-16 18:09:21 -04:00
1 parent 5ea7186549
commit 6e30baf46c
9 files changed
+127 -81

No files matched your search

@@ -376,6 +376,11 @@ class EmrClusterStorageTest {
assertEquals("0.0.0.0", Files.readString(bind).strip());
}
// A node script's wait until condition holds, which ends the node if one of its daemons exits meanwhile.
private static String waitUntil(String condition) {
return "until " + condition + "; do [ \"$(jobs -rp | wc -l)\" = $n ] || exit 1; sleep 0.2; done; ";
}
// bash running script with FLOCI_HDFS_BIND at 0.0.0.0, and FLOCI_HDFS_SUBNET at subnet unless it is null.
private static ProcessBuilder shell(String script, String subnet) {
ProcessBuilder shell = new ProcessBuilder("bash", "-c", script);
@@ -1335,16 +1340,28 @@ class EmrClusterStorageTest {
+ " yarn resourcemanager & n=\\$\\(\\(n \\+ 1\\)\\); if \\[ -z \"\\$FLOCI_NODE_WORKERS\" \\]; then "
+ "JDK_JAVA_OPTIONS=\"--add-opens=java\\.base/java\\.lang=ALL-UNNAMED[^\"]*\""
+ " yarn nodemanager &").matcher(entrypoint.get(2)).find()));
// Started with the NameNode, as neither needs the HDFS to start; ready once the NodeManager has registered,
// and the node gone if either daemon exits while starting.
verify(spec).withEntrypoint(argThat(entrypoint -> entrypoint.get(2).contains(
"yarn nodemanager & n=$((n + 1)); fi; fi; "
+ "until curl -sf -m 5 \"http://$(cat /tmp/floci-hdfs-bind):9870/jmx?qry=Hadoop:service=NameNode,name=NameNodeInfo\"")
// The MapReduce JobHistory server EMR's primary node runs too, a client asking it about a job whose application
// master has ended, on Hadoop's own ports and listening where HDFS does.
verify(spec).withEntrypoint(argThat(entrypoint -> entrypoint.get(2).contains(String.join(" ",
"\"<property><name>mapreduce.jobhistory.address</name><value>$FLOCI_HDFS_HOST:10020</value></property>\"",
"\"<property><name>mapreduce.jobhistory.webapp.address</name>"
+ "<value>$FLOCI_HDFS_HOST:19888</value></property>\"",
"\"<property><name>mapreduce.jobhistory.admin.address</name>"
+ "<value>$FLOCI_HDFS_HOST:10033</value></property>\"",
"\"<property><name>mapreduce.jobhistory.bind-host</name><value>$FLOCI_HDFS_BIND</value></property>\"",
"'</configuration>' > /tmp/floci-hdfs-conf/mapred-site.xml || exit"))));
// Started with the NameNode, as none needs the HDFS to start; ready once the NodeManager has registered and the
// JobHistory server answers, and the node gone if any daemon exits while starting.
verify(spec).withEntrypoint(argThat(entrypoint -> Pattern.compile("yarn nodemanager & n=\\$\\(\\(n \\+ 1\\)\\); fi; "
+ "JDK_JAVA_OPTIONS=\"--add-opens=java\\.base/java\\.lang=ALL-UNNAMED[^\"]*\" mapred historyserver & "
+ "n=\\$\\(\\(n \\+ 1\\)\\); fi; until curl -sf -m 5 \"http://\\$\\(cat /tmp/floci-hdfs-bind\\):9870/jmx")
.matcher(entrypoint.get(2)).find()
&& entrypoint.get(2).contains("if [ -n \"$FLOCI_YARN_MEMORY_MB\" ]; then "
+ "until curl -sf -m 5 http://$(cat /tmp/floci-hdfs-bind):8088/ws/v1/cluster/metrics"
+ " | grep -q \"\\\"activeNodes\\\":[1-9]\"; do "
+ "[ \"$(jobs -rp | wc -l)\" = $n ] || exit 1; sleep 0.2; done; fi;"
+ " touch /tmp/floci-hdfs-ready")));
+ waitUntil("curl -sf -m 5 http://$(cat /tmp/floci-hdfs-bind):8088/ws/v1/cluster/metrics"
+ " | grep -q \"\\\"activeNodes\\\":[1-9]\"")
+ waitUntil("curl -sf -m 5 http://$(cat /tmp/floci-hdfs-bind):19888/ws/v1/history/info"
+ " | grep -q historyInfo")
+ "fi; touch /tmp/floci-hdfs-ready")));
}
@Test
@@ -1366,7 +1383,7 @@ class EmrClusterStorageTest {
int export = script.indexOf("export HADOOP_HOME=$h/hadoop HADOOP_COMMON_HOME=$h/hadoop"
+ " HADOOP_LIBEXEC_DIR=$h/hadoop/libexec HADOOP_HDFS_HOME=$h/hadoop-hdfs"
+ " HADOOP_MAPRED_HOME=$h/hadoop-mapreduce HADOOP_YARN_HOME=$h/hadoop-yarn"
+ " PATH=$h/hadoop-hdfs/bin:$h/hadoop-yarn/bin:$h/hadoop/bin:$PATH");
+ " PATH=$h/hadoop-hdfs/bin:$h/hadoop-yarn/bin:$h/hadoop-mapreduce/bin:$h/hadoop/bin:$PATH");
return script.contains(" h=$FLOCI_HADOOP_FOLDER") && export > 0 && export < script.indexOf("exec setpriv");
}));
}
@@ -118,6 +118,9 @@ class EmrPigStepsNightlyIntegrationTest {
assertEquals("COMPLETED", state(mapReduce), () -> logs(mapReduce));
assertEquals(SUMS, objects("out/mapreduce/"));
assertTrue(logs(mapReduce).contains("MapReduceLauncher"), () -> logs(mapReduce));
// Its counters, which Pig's client gets from the cluster's JobHistory server once each job's application master
// has ended.
assertTrue(logs(mapReduce).contains("Successfully read 4 records"), () -> logs(mapReduce));
}
private void startCluster() {
@@ -1068,8 +1068,7 @@ class EmrServiceContainerStepsTest {
SparkJobRunner.Job job = runner.jobs.get(0);
assertEquals(args, job.command());
assertEquals(EmrServiceFixture.RecordingReleaseImages.IMAGE, job.imageTemplate());
assertEquals("exectype = tez\nmapreduce.job.working.dir = /user/${user.name}\npig.stats.notaskreport = true\n"
+ "yarn.app.mapreduce.client.max-retries = 1\npig.exec.reducers.max = 8",
assertEquals("exectype = tez\nmapreduce.job.working.dir = /user/${user.name}\npig.exec.reducers.max = 8",
job.environment().get("FLOCI_PIG_PROPERTIES"));
}
@@ -26,8 +26,7 @@ class EmrSparkStepsTest {
private static final String HIVE_AND_SPARK = "[{\"Name\": \"Spark\"}, {\"Name\": \"hive\"}]";
private static final String RELEASE = "emr-7.5.0";
// The pig.properties lines Floci gives every Pig after its exectype, ahead of the cluster's.
private static final String FLOCIS_PIG_LINES = "mapreduce.job.working.dir = /user/${user.name}\n"
+ "pig.stats.notaskreport = true\nyarn.app.mapreduce.client.max-retries = 1";
private static final String FLOCIS_PIG_LINES = "mapreduce.job.working.dir = /user/${user.name}";
private final ObjectMapper objectMapper = new ObjectMapper();
@@ -199,7 +198,6 @@ class EmrSparkStepsTest {
// Tez, as EMR's Pig 0.16.0 and later, from a working directory S3A takes as HDFS does, then tez-site's, then
// pig-properties', a later line winning.
assertEquals(String.join("\n", "exectype = tez", "mapreduce.job.working.dir = /user/${user.name}",
"pig.stats.notaskreport = true", "yarn.app.mapreduce.client.max-retries = 1",
"tez.grouping.max-size = 268435456",
"tez.am.resource.memory.mb = 1536", "pig.exec.reducers.max = 8"),
variables.get("FLOCI_PIG_PROPERTIES"));
@@ -1104,6 +1104,11 @@ class EmrServerlessSparkRunnerTest {
assertTrue(site.contains("<name>yarn.app.mapreduce.am.resource.mb</name><value>1024</value>"), site);
assertTrue(site.contains("<name>mapreduce.map.memory.mb</name><value>768</value>"), site);
assertTrue(site.contains("<name>mapreduce.reduce.memory.mb</name><value>768</value>"), site);
// The cluster's JobHistory server, which the job's client asks about it once its application master has ended.
assertTrue(site.contains("<name>mapreduce.jobhistory.address</name>"
+ "<value>ip-10-0-0-1.ec2.internal:10020</value>"), site);
assertTrue(site.contains("<name>mapreduce.jobhistory.webapp.address</name>"
+ "<value>ip-10-0-0-1.ec2.internal:19888</value>"), site);
}
@Test
@@ -1265,7 +1270,10 @@ class EmrServerlessSparkRunnerTest {
// A task's two would never match the one YARN's default scheduler grants.
"hive.tez.cpu.vcores=1",
"tez.runtime.intermediate-output.should-compress=false",
"tez.runtime.intermediate-input.is-compressed=false")) {
"tez.runtime.intermediate-input.is-compressed=false",
// The cluster's JobHistory server, for a query whose hive.execution.engine is mr.
"mapreduce.jobhistory.address=ip-10-0-0-1.ec2.internal:10020",
"mapreduce.jobhistory.webapp.address=ip-10-0-0-1.ec2.internal:19888")) {
assertTrue(arguments.contains(setting), setting + " in " + arguments);
}
assertTrue(arguments.contains("tez.cluster.additional.classpath.prefix=$PWD/*:/usr/lib/hive/lib/hive-exec.jar:"