@Override
  public ModificationFile allocateFor(TsFileResource tsFileResource) throws IOException {
    TsFileResource prev = tsFileResource.getPrev();
    TsFileResource next = tsFileResource.getNext();
    while (prev != null || next != null) {
      if (prev != null) {
        ModificationFile sharedModFile = prev.getSharedModFile();
        if (sharedModFile != null) {
          if (tryShare(sharedModFile, prev, tsFileResource)) {
            return sharedModFile;
          } else {
            // do not prove further if a TsFile with mod is already found
            prev = null;
          }
        } else {
          prev = prev.getPrev();
        }
      }

      if (next != null) {
        ModificationFile sharedModFile = next.getSharedModFile();
        if (sharedModFile != null) {
          if (tryShare(sharedModFile, next, tsFileResource)) {
            return sharedModFile;
          } else {
            // do not prove further if a TsFile with mod is already found
            next = null;
          }
        } else {
          next = next.getNext();
        }
      }
    }

    return allocateNew(tsFileResource);
  }
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