protected void recoverWithWriter() throws DataRegionException, IOException {
    File tsFile = tsFileResource.getTsFile();
    File chunkMetadataTempFile =
        new File(tsFile.getAbsolutePath() + TsFileIOWriter.CHUNK_METADATA_TEMP_FILE_SUFFIX);
    if (chunkMetadataTempFile.exists()) {
      // delete chunk metadata temp file
      FileUtils.delete(chunkMetadataTempFile);
    }

    if (tsFileResource.resourceFileExists()) {
      // .resource file exists, just deserialize it into memory
      loadResourceFile();
      return;
    }

    if (!tsFile.exists()) {
      logger.error("TsFile {} is missing, will skip its recovery.", tsFile);
      return;
    }

    writer = new RestorableTsFileIOWriter(tsFile);
    if (writer.hasCrashed()) {
      byte versionNumber;
      try (TsFileSequenceReader sequenceReader =
          new TsFileSequenceReader(tsFile.getAbsolutePath())) {
        versionNumber = sequenceReader.readVersionNumber();
      } catch (NotCompatibleTsFileException e) {
        versionNumber = -1;
      }

      if (versionNumber != TSFileConfig.VERSION_NUMBER) {
        // cannot rewrite a file with V3 header, delete it first
        writer.close();
        tsFile.delete();
        writer = new RestorableTsFileIOWriter(tsFile);
      }
    } else {
      reconstructResourceFile();
    }
  }
Recover TsFile with RestorableTsFileIOWriter, including load .resource file (reconstruct when
necessary) and truncate the file to remaining corrected data. <br>
Notice: this method may open a {@link RestorableTsFileIOWriter}, remember to close it.

@throws DataRegionException when failing to new RestorableTsFileIOWriter.
@throws IOException when failing to read .resource file.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/recover/file/AbstractTsFileRecoverPerformer.java