{"record":{"id":"a5b6ea5fd4bbbdc9","repo":"apache/hadoop","slug":"invalid-operation-read","errorCode":null,"errorMessage":"Invalid operation read {}","messagePattern":"Invalid operation read (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"critical","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java","lineNumber":1056,"sourceCode":"    case OP_DISABLE_ERASURE_CODING_POLICY:\n      DisableErasureCodingPolicyOp disableOp =\n          (DisableErasureCodingPolicyOp) op;\n      fsNamesys.getErasureCodingPolicyManager().disablePolicy(\n          disableOp.getEcPolicy());\n      if (toAddRetryCache) {\n        fsNamesys.addCacheEntry(op.rpcClientId, op.rpcCallId);\n      }\n      break;\n    case OP_REMOVE_ERASURE_CODING_POLICY:\n      RemoveErasureCodingPolicyOp removeOp = (RemoveErasureCodingPolicyOp) op;\n      fsNamesys.getErasureCodingPolicyManager().removePolicy(\n          removeOp.getEcPolicy());\n      if (toAddRetryCache) {\n        fsNamesys.addCacheEntry(op.rpcClientId, op.rpcCallId);\n      }\n      break;\n    default:\n      throw new IOException(\"Invalid operation read \" + op.opCode);\n    }\n    return inodeId;\n  }\n  \n  private static String formatEditLogReplayError(EditLogInputStream in,\n      long recentOpcodeOffsets[], long txid) {\n    StringBuilder sb = new StringBuilder();\n    sb.append(\"Error replaying edit log at offset \" + in.getPosition())\n        .append(\".  Expected transaction ID was \").append(txid);\n    if (recentOpcodeOffsets[0] != -1) {\n      Arrays.sort(recentOpcodeOffsets);\n      sb.append(\"\\nRecent opcode offsets:\");\n      for (long offset : recentOpcodeOffsets) {\n        if (offset != -1) {\n          sb.append(' ').append(offset);\n        }\n      }\n    }","sourceCodeStart":1038,"sourceCodeEnd":1074,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java#L1038-L1074","documentation":"applyEditLogOp hit an opcode with no case in its replay switch and throws IOException('Invalid operation read <opCode>'). Either the decoded opcode is garbage from a corrupt stream, or the log was written by a newer Hadoop whose opcodes this NameNode does not understand: the classic downgrade failure.","triggerScenarios":"Starting an older NameNode binary against edit logs containing opcodes introduced later (downgrade after an upgrade); corrupted opcode bytes; replaying segments copied from a cluster on a newer release.","commonSituations":"Downgrade done by swapping JARs without the documented rollback procedure; edit segments copied between clusters running different versions; media corruption.","solutions":["Run the NameNode binary that matches or is newer than the version that wrote the logs; never downgrade across layout-version changes","If a downgrade is required, follow the documented rollback procedure and restore the pre-upgrade name directory snapshot instead of replaying new edits with old code","Inspect the segment with 'hdfs oev' to identify the offending opcode and txid","Restore a consistent fsimage plus edits from backup if the segment is corrupt"],"exampleFix":"# before: old binaries replaying newer logs\nexport HADOOP_PREFIX=/opt/hadoop-2.7 && hdfs --daemon start namenode   # fails\n\n# after: replay with binaries at or above the writer's version, or roll back properly\nexport HADOOP_PREFIX=/opt/hadoop-3.1 && hdfs --daemon start namenode\n# or: restore pre-upgrade name dirs from the rollback snapshot","handlingStrategy":"validation","validationCode":"// refuse to replay logs newer than this binary understands\n// (layout versions grow more negative over time)\nint logLayout = /* read from the segment header via hdfs oev or EditLogFileInputStream */;\nif (logLayout < HdfsServerConstants.NAMENODE_LAYOUT_VERSION) {\n  throw new IllegalStateException(\"Edit log layout \" + logLayout\n      + \" is newer than this NameNode understands; replay it with newer binaries\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  loader.loadFSEdits(storage, 0);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Invalid operation read\")) {\n    // unknown opcode: this binary is older than the log writer.\n    // stop the downgrade; restore the pre-upgrade name dirs instead\n  }\n  throw e;\n}","preventionTips":["Never downgrade a NameNode across layout-version changes; use the documented rollback procedure","Keep pre-upgrade name directory backups until the upgrade is finalized","Check 'hdfs version' on both clusters before copying edit segments"],"tags":["hdfs","namenode","edit-log","opcode","downgrade","version-mismatch","corruption"],"backgroundTag":"edit-log-version-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}