private void checkIsDeviceExistAndGetDeviceEndTime() throws IOException {
    int fileIndex = 0;
    while (fileIndex < seqTsFileResources.size()) {
      ITimeIndex timeIndex = seqTsFileResources.get(fileIndex).getTimeIndex();
      if (timeIndex.getTimeIndexType() != ITimeIndex.FILE_TIME_INDEX_TYPE) {
        // the timeIndexType of resource is deviceTimeIndex
        Optional<Long> endTime = timeIndex.getEndTime(deviceId);
        currentDeviceEndTime[fileIndex] = endTime.orElse(Long.MIN_VALUE);
        isCurrentDeviceExistedInSourceSeqFiles[fileIndex] = endTime.isPresent();
      } else {
        long endTime = Long.MIN_VALUE;
        boolean isDeviceExist = false;
        // Fast compaction get reader from cache map, while read point compaction get reader from
        // FileReaderManager
        Map<String, TimeseriesMetadata> deviceMetadataMap =
            getFileReader(seqTsFileResources.get(fileIndex)).readDeviceMetadata(deviceId);
        for (Map.Entry<String, TimeseriesMetadata> entry : deviceMetadataMap.entrySet()) {
          long tmpStartTime = entry.getValue().getStatistics().getStartTime();
          long tmpEndTime = entry.getValue().getStatistics().getEndTime();
          if (tmpEndTime >= tmpStartTime && endTime <= tmpEndTime) {
            endTime = tmpEndTime;
            isDeviceExist = true;
          }
        }
        currentDeviceEndTime[fileIndex] = isDeviceExist ? endTime : Long.MIN_VALUE;
        isCurrentDeviceExistedInSourceSeqFiles[fileIndex] = isDeviceExist;
      }

      fileIndex++;
    }
  }
Find the index of the target file to be inserted according to the data time. Notice: unsealed
chunk should be flushed to current file before moving target file index.<br>
If the seq file is deleted for various reasons, the following two situations may occur when
selecting the source files: (1) unseq files may have some devices or measurements which are not
exist in seq files. (2) timestamp of one timeseries in unseq files may later than any seq
files. Then write these data into the last target file.

@throws IOException if io errors occurred
@throws RuntimeException if timeStamp is sooner than the last time
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/writer/AbstractCrossCompactionWriter.java