apache/hadoop · error · IOException

Namenode metrics is not initialized

Error message

Namenode metrics is not initialized

What it means

Router.getNamenodeMetrics() returns the NamenodeBeanMetrics that mimics a NameNode's JMX beans for the federation. It throws IOException when this.metrics (the Router metrics service) is null or has not bound the namenode metrics bean yet, i.e. the Router is not fully initialized. Callers are typically RPC/JMX facades expecting a NameNodeMXBean.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/Router.java:738

   *
   * @return Federation metrics.
   */
  public RBFMetrics getMetrics() {
    if (this.metrics != null) {
      return this.metrics.getRBFMetrics();
    }
    return null;
  }

  /**
   * Get the namenode metrics.
   *
   * @return the namenode metrics.
   * @throws IOException if the namenode metrics are not initialized.
   */
  public NamenodeBeanMetrics getNamenodeMetrics() throws IOException {
    if (this.metrics == null) {
      throw new IOException("Namenode metrics is not initialized");
    }
    return this.metrics.getNamenodeMetrics();
  }

  /**
   * Get the subcluster resolver for files.
   *
   * @return Subcluster resolver for files.
   */
  public FileSubclusterResolver getSubclusterResolver() {
    return this.subclusterResolver;
  }

  /**
   * Get the namenode resolver for a subcluster.
   *
   * @return The namenode resolver for a subcluster.
   */

View on GitHub (pinned to 2add963021)

Solutions

  1. Ensure the Router is fully started (wait for 'STARTED' state) before issuing requests that need namenode beans
  2. Check Router health/state store connectivity in the log if metrics never initialize
  3. In tests, start the Router service lifecycle (router.start()) or mock getNamenodeMetrics()
  4. Retry with backoff for the startup window
Defensive patterns

Strategy: validation

Validate before calling

if (router.getMetrics() == null) {
  // Router metrics service not started; defer bean queries
  return;
}
NamenodeBeanMetrics nnm = router.getNamenodeMetrics();

Try / catch

try {
  NamenodeBeanMetrics m = router.getNamenodeMetrics();
} catch (IOException e) {
  if ("Namenode metrics is not initialized".equals(e.getMessage())) {
    // retry during startup window; if persistent, Router init failed - inspect logs
  } else { throw e; }
}

Prevention

When it happens

Trigger: A RouterRpcServer/admin or JMX request reaching getNamenodeMetrics() before serviceInit/serviceStart of the metrics service completes or after shutdown; Router built with state store disabled and metrics service absent; tests constructing Router with conf but not starting services.

Common situations: Monitoring scraping during Router restart windows; ordered-service startup races; unit tests calling Router methods on a partially constructed Router.

Related errors


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