{"record":{"id":"22b919bb2e7b3d92","repo":"apache/hadoop","slug":"read-unexpect-number-of-files","errorCode":null,"errorMessage":"Read unexpect number of files: {}","messagePattern":"Read unexpect number of files: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormat.java","lineNumber":512,"sourceCode":"   * @throws IOException\n   */  \n   private void loadLocalNameINodes(long numFiles, DataInput in, Counter counter)\n       throws IOException {\n     assert NameNodeLayoutVersion.supports(\n         LayoutVersion.Feature.FSIMAGE_NAME_OPTIMIZATION, getLayoutVersion());\n     assert numFiles > 0;\n\n     // load root\n     loadRoot(in, counter);\n     // have loaded the first file (the root)\n     numFiles--; \n\n     // load rest of the nodes directory by directory\n     while (numFiles > 0) {\n       numFiles -= loadDirectory(in, counter);\n     }\n     if (numFiles != 0) {\n       throw new IOException(\"Read unexpect number of files: \" + -numFiles);\n     }\n   }\n   \n    /**\n     * Load information about root, and use the information to update the root\n     * directory of NameSystem.\n     * @param in The {@link DataInput} instance to read.\n     * @param counter Counter to increment for namenode startup progress\n     */\n    private void loadRoot(DataInput in, Counter counter)\n        throws IOException {\n      // load root\n      if (in.readShort() != 0) {\n        throw new IOException(\"First node is not root\");\n      }\n      final INodeDirectory root = loadINode(null, false, in, counter)\n        .asDirectory();\n      // update the root's attributes","sourceCodeStart":494,"sourceCodeEnd":530,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormat.java#L494-L530","documentation":"Error \"Read unexpect number of files: {}\" thrown in apache/hadoop.","triggerScenarios":"Loading an old-format fsimage where the number of files/directories read differs from the count recorded in the image header.","commonSituations":"See trigger scenarios.","solutions":["The fsimage is inconsistent; load from another storage directory or restore from a valid checkpoint."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}