public void loadNewTsFile(
      final TsFileResource newTsFileResource,
      final boolean deleteOriginFile,
      final boolean isGeneratedByPipe,
      final boolean isFromConsensus)
      throws LoadFileException {
    final File tsfileToBeInserted = newTsFileResource.getTsFile();
    final long newFilePartitionId = newTsFileResource.getTimePartitionWithCheck();

    if (!TsFileValidator.getInstance().validateTsFile(newTsFileResource)) {
      throw new LoadFileException(
          "tsfile validate failed, " + newTsFileResource.getTsFile().getName());
    }

    TsFileLastReader lastReader = null;
    LastCacheLoadStrategy lastCacheLoadStrategy = config.getLastCacheLoadStrategy();
    if ((lastCacheLoadStrategy == LastCacheLoadStrategy.UPDATE
            || lastCacheLoadStrategy == LastCacheLoadStrategy.UPDATE_NO_BLOB)
        && newTsFileResource.getLastValues() == null) {
      try {
        // init reader outside of lock to boost performance
        lastReader =
            new TsFileLastReader(
                newTsFileResource.getTsFilePath(),
                true,
                lastCacheLoadStrategy == LastCacheLoadStrategy.UPDATE_NO_BLOB);
      } catch (IOException e) {
        throw new LoadFileException(e);
      }
    }

    writeLock("loadNewTsFile");
    try {
      if (deleted) {
        logger.info(
            "Won't load TsFile {}, because region is deleted",
            tsfileToBeInserted.getAbsolutePath());
        return;
      }
      newTsFileResource.setSeq(false);
      final String newFileName =
          getNewTsFileName(
              System.currentTimeMillis(),
              getAndSetNewVersion(newFilePartitionId, newTsFileResource),
              0,
              0);

      if (!newFileName.equals(tsfileToBeInserted.getName())) {
        logger.info(
            "TsFile {} must be renamed to {} for loading into the unsequence list.",
            tsfileToBeInserted.getName(),
            newFileName);
        newTsFileResource.setFile(
            fsFactory.getFile(tsfileToBeInserted.getParentFile(), newFileName));
      }
      loadTsFileToUnSequence(
          tsfileToBeInserted,
          newTsFileResource,
          newFilePartitionId,
          deleteOriginFile,
          isGeneratedByPipe);

      FileMetrics.getInstance()
          .addTsFile(
              newTsFileResource.getDatabaseName(),
              newTsFileResource.getDataRegionId(),
              newTsFileResource.getTsFile().length(),
              false,
              newTsFileResource.getTsFile().getName());

      if (config.isEnableSeparateData()) {
        final DataRegionId dataRegionId = new DataRegionId(Integer.parseInt(this.dataRegionId));
        final long timePartitionId = newTsFileResource.getTimePartition();
        if (!lastFlushTimeMap.checkAndCreateFlushedTimePartition(timePartitionId, true)) {
          TimePartitionManager.getInstance()
              .registerTimePartitionInfo(
                  new TimePartitionInfo(
                      dataRegionId,
                      timePartitionId,
                      false,
                      Long.MAX_VALUE,
                      lastFlushTimeMap.getMemSize(timePartitionId)));
        }
        updateDeviceLastFlushTime(newTsFileResource);
        TimePartitionManager.getInstance()
            .updateAfterFlushing(
                dataRegionId,
                timePartitionId,
                System.currentTimeMillis(),
                lastFlushTimeMap.getMemSize(timePartitionId),
                false);
      }

      onTsFileLoaded(newTsFileResource, isFromConsensus, lastReader);
      logger.info("TsFile {} is successfully loaded in unsequence list.", newFileName);
    } catch (final DiskSpaceInsufficientException e) {
      logger.error(
          "Failed to append the tsfile {} to database processor {} because the disk space is insufficient.",
          tsfileToBeInserted.getAbsolutePath(),
          tsfileToBeInserted.getParentFile().getName());
      throw new LoadFileException(e);
    } catch (Exception e) {
      throw new LoadFileException(e);
    } finally {
      writeUnlock();
      if (lastReader != null) {
        try {
          lastReader.close();
        } catch (Exception e) {
          logger.warn("Cannot close last reader after loading TsFile {}", newTsFileResource, e);
        }
      }
    }
  }
Load a new tsfile to unsequence dir.

<p>Then, update the latestTimeForEachDevice and partitionLatestFlushedTimeForEachDevice.

@param newTsFileResource tsfile resource @UsedBy load external tsfile module
@param deleteOriginFile whether to delete origin tsfile
@param isGeneratedByPipe whether the load tsfile request is generated by pipe
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java