apache/hadoop · error · RuntimeException

unexpected event type: ${wrapper.getType()}

Error message

unexpected event type: ${wrapper.getType()}

What it means

EventReader.getNextEvent maps each decoded Avro Event wrapper's EventType (JOB_SUBMITTED, TASK_FINISHED, AM_STARTED, ...) to a concrete HistoryEvent class via a switch. The default branch throws RuntimeException("unexpected event type") for a type with no mapping - reachable only when the history contains an EventType this build does not know (newer writer) or the decoded payload is garbage.

Source

Thrown at hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/jobhistory/EventReader.java:170

      result = new TaskAttemptStartedEvent(); break;
    case SETUP_ATTEMPT_FINISHED:
      result = new TaskAttemptFinishedEvent(); break;
    case SETUP_ATTEMPT_FAILED:
      result = new TaskAttemptUnsuccessfulCompletionEvent(); break;
    case SETUP_ATTEMPT_KILLED:
      result = new TaskAttemptUnsuccessfulCompletionEvent(); break;
    case CLEANUP_ATTEMPT_STARTED:
      result = new TaskAttemptStartedEvent(); break;
    case CLEANUP_ATTEMPT_FINISHED:
      result = new TaskAttemptFinishedEvent(); break;
    case CLEANUP_ATTEMPT_FAILED:
      result = new TaskAttemptUnsuccessfulCompletionEvent(); break;
    case CLEANUP_ATTEMPT_KILLED:
      result = new TaskAttemptUnsuccessfulCompletionEvent(); break;
    case AM_STARTED:
      result = new AMStartedEvent(); break;
    default:
      throw new RuntimeException("unexpected event type: " + wrapper.getType());
    }
    result.setDatum(wrapper.getEvent());
    return result;
  }

  /**
   * Close the Event reader
   * @throws IOException
   */
  @Override
  public void close() throws IOException {
    if (in != null) {
      in.close();
    }
    in = null;
  }

  static Counters fromAvro(JhCounters counters) {

View on GitHub (pinned to 2add963021)

Solutions

  1. Read the history with a Hadoop version equal to or newer than the one that wrote it.
  2. Skip the unreadable file and continue the scan (one bad file should not abort directory-level tooling).
  3. If you fork and add event types, add the mapping case in EventReader in the same change.
  4. Treat persistent occurrences as corruption: recover via HDFS replicas or re-run.

Example fix

// defensive directory scan pattern
try {
  HistoryEvent e = reader.getNextEvent();
} catch (RuntimeException re) {
  if (re.getMessage() != null && re.getMessage().startsWith("unexpected event type")) {
    LOG.warn("History from newer Hadoop? Skipping " + path);
    continue; // skip file, keep scanning
  }
  throw re;
}
Defensive patterns

Strategy: try-catch

Try / catch

catch (RuntimeException e) from getNextEvent(): if message starts with "unexpected event type", skip the remainder of that file (likely newer-format history) and continue the scan; otherwise propagate.

Prevention

When it happens

Trigger: Reading a .jhist written by a newer Hadoop build or fork that added EventType constants unknown to this reader; Avro decoding producing a corrupt type value from a damaged stream.

Common situations: Parsing history across Hadoop versions (downgrade direction); patched Hadoop with extra event types; history files damaged in storage.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/4d64e606eda39c79. Report an issue: GitHub.