From 30e9cdbff7adb75c3553d5cbb8515761a7231e07 Mon Sep 17 00:00:00 2001 From: Ayush Saxena Date: Wed, 22 May 2024 12:05:11 +0530 Subject: [PATCH] TEZ-4566: NPE in TezChild while fetching attemptId when container is asked to shut down. (#358). (Ayush Saxena, reviewed by Laszlo Bodor) --- .../tez/runtime/task/ContainerReporter.java | 5 ++-- .../org/apache/tez/runtime/task/TezChild.java | 29 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tez-runtime-internals/src/main/java/org/apache/tez/runtime/task/ContainerReporter.java b/tez-runtime-internals/src/main/java/org/apache/tez/runtime/task/ContainerReporter.java index 0ece2271c5..8d73fd3e3b 100644 --- a/tez-runtime-internals/src/main/java/org/apache/tez/runtime/task/ContainerReporter.java +++ b/tez-runtime-internals/src/main/java/org/apache/tez/runtime/task/ContainerReporter.java @@ -69,8 +69,9 @@ protected ContainerTask callInternal() throws Exception { + " ms after starting to poll." + " TaskInfo: shouldDie: " + containerTask.shouldDie() - + (containerTask.shouldDie() == true ? "" : ", currentTaskAttemptId: " - + containerTask.getTaskSpec().getTaskAttemptID())); + + (containerTask.shouldDie() ? "" : ", currentTaskAttemptId: " + + (containerTask.getTaskSpec() == null ? "none" + : containerTask.getTaskSpec().getTaskAttemptID()))); return containerTask; } diff --git a/tez-runtime-internals/src/main/java/org/apache/tez/runtime/task/TezChild.java b/tez-runtime-internals/src/main/java/org/apache/tez/runtime/task/TezChild.java index 3145f21a58..98b07100a8 100644 --- a/tez-runtime-internals/src/main/java/org/apache/tez/runtime/task/TezChild.java +++ b/tez-runtime-internals/src/main/java/org/apache/tez/runtime/task/TezChild.java @@ -249,20 +249,6 @@ public ContainerExecutionResult run() throws IOException, InterruptedException, } } - TezTaskAttemptID attemptId = containerTask.getTaskSpec().getTaskAttemptID(); - Configuration taskConf; - if (containerTask.getTaskSpec().getTaskConf() != null) { - Configuration copy = new Configuration(defaultConf); - TezTaskRunner2.mergeTaskSpecConfToConf(containerTask.getTaskSpec(), copy); - taskConf = copy; - LoggingUtils.initLoggingContext(mdcContext, copy, - attemptId.getTaskID().getVertexID().getDAGID().toString(), attemptId.toString()); - } else { - taskConf = defaultConf; - LoggingUtils.initLoggingContext(mdcContext, defaultConf, - attemptId.getTaskID().getVertexID().getDAGID().toString(), attemptId.toString()); - } - TezCommonUtils.logCredentials(LOG, containerTask.getCredentials(), "containerTask"); if (containerTask.shouldDie()) { LOG.info("ContainerTask returned shouldDie=true for container {}, Exiting", containerIdString); @@ -270,7 +256,20 @@ public ContainerExecutionResult run() throws IOException, InterruptedException, return new ContainerExecutionResult(ContainerExecutionResult.ExitStatus.SUCCESS, null, "Asked to die by the AM"); } else { - String loggerAddend = containerTask.getTaskSpec().getTaskAttemptID().toString(); + TezTaskAttemptID attemptId = containerTask.getTaskSpec().getTaskAttemptID(); + Configuration taskConf; + if (containerTask.getTaskSpec().getTaskConf() != null) { + Configuration copy = new Configuration(defaultConf); + TezTaskRunner2.mergeTaskSpecConfToConf(containerTask.getTaskSpec(), copy); + taskConf = copy; + LoggingUtils.initLoggingContext(mdcContext, copy, attemptId.getTaskID().getVertexID().getDAGID().toString(), + attemptId.toString()); + } else { + taskConf = defaultConf; + LoggingUtils.initLoggingContext(mdcContext, defaultConf, + attemptId.getTaskID().getVertexID().getDAGID().toString(), attemptId.toString()); + } + String loggerAddend = attemptId.toString(); taskCount++; String timeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()); System.err.println(timeStamp + " Starting to run new task attempt: " +