private synchronized ModificationFile allocateNew(TsFileResource tsFileResource) {
    long level = tsFileResource.getTsFileID().getInnerCompactionCount();
    TreeMap<Long, ModificationFile> idModificationMap =
        levelModFileIdMap.computeIfAbsent(level, l -> new TreeMap<>());
    long newId = idModificationMap.isEmpty() ? 1 : idModificationMap.lastEntry().getKey() + 1;
    ModificationFile newModFile =
        new ModificationFile(
            new File(
                tsFileResource.getTsFile().getParentFile(),
                ModificationFile.composeFileName(level, newId)),
            true);
    idModificationMap.put(newId, newModFile);

    Set<TsFileResource> references = new HashSet<>();
    references.add(tsFileResource);
    modFileReferences.put(newModFile, references);

    return newModFile;
  }
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