apache/hadoop · error · MetricsException

${message}: ${currentFilePath}

Error message

${message}: ${currentFilePath}

What it means

checkForErrors() polls PrintStream.checkError() because PrintStream silently swallows IOExceptions on write. When the underlying stream to the current metrics file has entered an error state (disk full, HDFS datanode/lease trouble, file removed underneath the sink) and ignore-error is false, it throws MetricsException("<message>: <currentFilePath>"). In this sink the messages used are 'Unable to write to log file' and 'Unable to close log file'.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/sink/RollingFileSystemSink.java:908

      }
    }
  }

  /**
   * If the sink isn't set to ignore errors, throw a {@link MetricsException}
   * if the stream encountered an exception.  The message parameter will be used
   * as the new exception's message with the current file name
   * ({@link #currentFilePath}) appended to it.
   *
   * @param message the exception message. The message will have a colon and
   * the current file name ({@link #currentFilePath}) appended to it.
   * @throws MetricsException thrown if there was an error and the sink isn't
   * ignoring errors
   */
  private void checkForErrors(String message)
      throws MetricsException {
    if (!ignoreError && currentOutStream.checkError()) {
      throw new MetricsException(message + ": " + currentFilePath);
    }
  }

  /**
   * If the sink isn't set to ignore errors, wrap the Throwable in a
   * {@link MetricsException} and throw it.  The message parameter will be used
   * as the new exception's message with the current file name
   * ({@link #currentFilePath}) and the Throwable's string representation
   * appended to it.
   *
   * @param message the exception message. The message will have a colon, the
   * current file name ({@link #currentFilePath}), and the Throwable's string
   * representation (wrapped in square brackets) appended to it.
   * @param t the Throwable to wrap
   */
  private void throwMetricsException(String message, Throwable t) {
    if (!ignoreError) {
      throw new MetricsException(message + ": " + currentFilePath + " ["

View on GitHub (pinned to 2add963021)

Solutions

  1. Free disk space or move basepath off /tmp to a managed directory with quota headroom
  2. Check HDFS health — with allow-append=true the docs require ~2-3 live datanodes minimum
  3. Set <prefix>.sink.<instance>.ignore-error=true only if losing metrics is acceptable while you remediate
  4. Inspect logs for the companion messages ('Failed flushing the stream', 'Unable to flush log file') to find the real I/O cause
Defensive patterns

Strategy: fallback

Validate before calling

FileStatus st = fileSystem.getFileStatus(basePath);
// local FS: check usable space
if (fileSystem instanceof LocalFileSystem) {
  long usable = new java.io.File(basePath.toUri().getPath()).getUsableSpace();
  if (usable < 1L << 30) LOG.warn("basepath low on space: {} bytes", usable);
}

Try / catch

try {
  sink.putMetrics(record);
} catch (MetricsException e) {
  // '<message>: <currentFilePath>' — PrintStream.checkError() flagged a silent I/O failure
  // fallback: keep daemon running, note the file, alert ops on storage health
  LOG.error("Metrics file write failed for {} — check disk/HDFS health",
      currentFilePath, e);
}

Prevention

When it happens

Trigger: Local disk (often the default /tmp basepath) filling up; HDFS append failing with too few live datanodes; the current <hostname>.log being deleted or its lease stolen while the sink holds it open.

Common situations: Default basepath=/tmp on a small root partition; allow-append=true on an under-replicated cluster; aggressive log cleaners removing sink output files mid-interval.

Related errors


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