{"record":{"id":"9475a69a487f6a23","repo":"apache/hadoop","slug":"namenode-metrics-is-not-initialized","errorCode":null,"errorMessage":"Namenode metrics is not initialized","messagePattern":"Namenode metrics is not initialized","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/Router.java","lineNumber":738,"sourceCode":"   *\n   * @return Federation metrics.\n   */\n  public RBFMetrics getMetrics() {\n    if (this.metrics != null) {\n      return this.metrics.getRBFMetrics();\n    }\n    return null;\n  }\n\n  /**\n   * Get the namenode metrics.\n   *\n   * @return the namenode metrics.\n   * @throws IOException if the namenode metrics are not initialized.\n   */\n  public NamenodeBeanMetrics getNamenodeMetrics() throws IOException {\n    if (this.metrics == null) {\n      throw new IOException(\"Namenode metrics is not initialized\");\n    }\n    return this.metrics.getNamenodeMetrics();\n  }\n\n  /**\n   * Get the subcluster resolver for files.\n   *\n   * @return Subcluster resolver for files.\n   */\n  public FileSubclusterResolver getSubclusterResolver() {\n    return this.subclusterResolver;\n  }\n\n  /**\n   * Get the namenode resolver for a subcluster.\n   *\n   * @return The namenode resolver for a subcluster.\n   */","sourceCodeStart":720,"sourceCodeEnd":756,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/Router.java#L720-L756","documentation":"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.","triggerScenarios":"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.","commonSituations":"Monitoring scraping during Router restart windows; ordered-service startup races; unit tests calling Router methods on a partially constructed Router.","solutions":["Ensure the Router is fully started (wait for 'STARTED' state) before issuing requests that need namenode beans","Check Router health/state store connectivity in the log if metrics never initialize","In tests, start the Router service lifecycle (router.start()) or mock getNamenodeMetrics()","Retry with backoff for the startup window"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (router.getMetrics() == null) {\n  // Router metrics service not started; defer bean queries\n  return;\n}\nNamenodeBeanMetrics nnm = router.getNamenodeMetrics();","typeGuard":null,"tryCatchPattern":"try {\n  NamenodeBeanMetrics m = router.getNamenodeMetrics();\n} catch (IOException e) {\n  if (\"Namenode metrics is not initialized\".equals(e.getMessage())) {\n    // retry during startup window; if persistent, Router init failed - inspect logs\n  } else { throw e; }\n}","preventionTips":["Wait for Router STARTED state before serving requests that touch metrics","Alert on Router service init failures so metrics never silently stay null","In tests, run the full Router lifecycle or mock getNamenodeMetrics"],"tags":["hdfs","router-based-federation","metrics","startup-race","jmx"],"backgroundTag":"service-not-initialized","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}