private synchronized boolean tryShare(
      ModificationFile sharedModFile, TsFileResource modFileHolder, TsFileResource toAllocate)
      throws IOException {
    Set<TsFileResource> references = modFileReferences.get(sharedModFile);
    if (references.isEmpty()) {
      // the mod file is to be deleted, cannot share
      return false;
    }

    long level = modFileHolder.getTsFileID().compactionVersion;
    TreeMap<Long, ModificationFile> idModificationMap = levelModFileIdMap.get(level);
    if (idModificationMap.size() > levelModFileNumThreshold) {
      // too many mod files already, must share
      references.add(toAllocate);
      return true;
    }
    if (sharedModFile.getFileLength() < singleModFileSizeThresholdByte) {
      // mod file is not large enough, can share
      references.add(toAllocate);
      return true;
    }
    // mod file is already too large, do not share
    return false;
  }
LevelModFileManager manages the shared mod files within one time partition.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/modification/PartitionLevelModFileManager.java