protected void checkTimeAndMayFlushChunkToCurrentFile(long timestamp, int subTaskId)
      throws IOException {
    checkPreviousTimestamp(timestamp, subTaskId);

    int fileIndex = seqFileIndexArray[subTaskId];
    boolean hasFlushedCurrentChunk = false;
    // If timestamp is later than the current source seq tsfile, then flush chunk writer and move to
    // next file
    while ((timestamp > currentDeviceEndTime[fileIndex]
            || !isCurrentDeviceExistedInSourceSeqFiles[fileIndex])
        && fileIndex != seqTsFileResources.size() - 1) {
      if (!hasFlushedCurrentChunk) {
        // Flush chunk to current file before moving target file index
        sealChunk(targetFileWriters.get(fileIndex), chunkWriters[subTaskId], subTaskId);
        hasFlushedCurrentChunk = true;
      }
      seqFileIndexArray[subTaskId] = ++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