@Override
  public void run() {
    logger.info("Start recovering WAL node in the directory {}", logDirectory);

    // recover version id and search index
    long[] indexInfo = readLastFileInfoAndRepairIt();
    long lastVersionId = indexInfo[0];
    long lastSearchIndex = indexInfo[1];

    try {
      recoverInfoFromCheckpoints();
      recoverTsFiles();
    } catch (Exception e) {
      for (UnsealedTsFileRecoverPerformer recoverPerformer : memTableId2RecoverPerformer.values()) {
        recoverPerformer.getRecoverListener().fail(e);
      }
    } finally {
      for (UnsealedTsFileRecoverPerformer recoverPerformer : memTableId2RecoverPerformer.values()) {
        try {
          if (!recoverPerformer.canWrite()) {
            recoverPerformer.close();
          }
        } catch (Exception e) {
          // continue
        }
      }
    }

    try {
      if (config.getDataRegionConsensusProtocolClass().equals(ConsensusFactory.IOT_CONSENSUS)) {
        // delete checkpoint info to avoid repeated recover
        File[] checkpointFiles = CheckpointFileUtils.listAllCheckpointFiles(logDirectory);
        for (File checkpointFile : checkpointFiles) {
          try {
            Files.delete(checkpointFile.toPath());
          } catch (IOException e) {
            logger.error("error when delete checkpoint file. {}", checkpointFile, e);
          }
        }
        // register wal node
        WALManager.getInstance()
            .registerWALNode(
                logDirectory.getName(),
                logDirectory.getAbsolutePath(),
                lastVersionId + 1,
                lastSearchIndex);
        logger.info(
            "Successfully recover WAL node in the directory {}, add this node to WALManger.",
            logDirectory);
      } else {
        // delete this wal node folder
        FileUtils.deleteFileOrDirectory(logDirectory);
        logger.info(
            "Successfully recover WAL node in the directory {}, so delete these wal files.",
            logDirectory);
      }

      // IoTConsensusV2 will not only delete WAL node folder, but also register WAL node.
      if (config.getDataRegionConsensusProtocolClass().equals(ConsensusFactory.IOT_CONSENSUS_V2)) {
        // register wal node
        WALManager.getInstance()
            .registerWALNode(
                logDirectory.getName(),
                logDirectory.getAbsolutePath(),
                lastVersionId + 1,
                lastSearchIndex);
        logger.info(
            "Successfully recover WAL node in the directory {}, add this node to WALManger.",
            logDirectory);
      }
    } finally {
      allNodesRecoveredLatch.countDown();
    }
  }
This task is responsible for the recovery of one wal node.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/recover/WALNodeRecoverTask.java