public boolean keepOrderInsert(TsFileResource newNode) throws IOException {
    if (newNode.prev != null || newNode.next != null || (count == 1 && header == newNode)) {
      // this node already in a list
      return false;
    }
    if (tail == null) {
      // empty list
      header = newNode;
      tail = newNode;
      count++;
    } else {
      TsFileNameGenerator.TsFileName newTsFileName =
          TsFileNameGenerator.getTsFileName(newNode.getTsFile().getName());
      long timestampOfNewNode = newTsFileName.getTime();
      long versionOfNewNode = newTsFileName.getVersion();

      // find the position to insert, the list should be ordered by file timestamp. If timestamp is
      // equal to each other, then list should be ordered by file version.
      boolean isNewNodeAtTail = true;
      TsFileResource currNode = header;
      while (currNode != null) {
        TsFileNameGenerator.TsFileName currTsFileName =
            TsFileNameGenerator.getTsFileName(currNode.getTsFile().getName());
        if (timestampOfNewNode == currTsFileName.getTime()
            && versionOfNewNode < currTsFileName.getVersion()) {
          // the timestamp of new node is equal to the current node and the version of new node is
          // less than current node, then insert new node before the current node
          isNewNodeAtTail = false;
          break;
        } else if (timestampOfNewNode < currTsFileName.getTime()) {
          // the timestamp of new node is less than the current node, insert new node before then
          // current node
          isNewNodeAtTail = false;
          break;
        }
        currNode = currNode.next;
      }

      // insert new node
      if (isNewNodeAtTail) {
        insertAfter(tail, newNode);
      } else {
        insertBefore(currNode, newNode);
      }
    }
    return true;
  }
Insert a tsfile resource to the list, the tsfile will be inserted before the first tsfile whose
timestamp is greater than its. If there is no tsfile whose timestamp is greater than the new
node's, the new node will be inserted to the tail of the list.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResourceList.java