public void compact() {
    long originFileSize = getSize();
    if (originFileSize > COMPACT_THRESHOLD && !hasCompacted) {
      Map<String, List<Modification>> pathModificationMap =
          getModifications().stream().collect(Collectors.groupingBy(Modification::getPathString));
      String newModsFileName = filePath + COMPACT_SUFFIX;
      List<Modification> allSettledModifications = new ArrayList<>();
      try (ModificationFileV1 compactedModificationFile = new ModificationFileV1(newModsFileName)) {
        Set<Map.Entry<String, List<Modification>>> modificationsEntrySet =
            pathModificationMap.entrySet();
        for (Map.Entry<String, List<Modification>> modificationEntry : modificationsEntrySet) {
          List<Modification> settledModifications = sortAndMerge(modificationEntry.getValue());
          for (Modification settledModification : settledModifications) {
            compactedModificationFile.write(settledModification);
          }
          allSettledModifications.addAll(settledModifications);
        }
      } catch (IOException e) {
        logger.error("compact mods file exception of {}", filePath, e);
      }

      try {
        // remove origin mods file
        this.remove();
        // rename new mods file to origin name
        Files.move(new File(newModsFileName).toPath(), new File(filePath).toPath());
        logger.info("{} settle successful", filePath);

        if (getSize() > COMPACT_THRESHOLD) {
          logger.warn(
              "After the mod file is settled, the file size is still greater than 1M,the size of the file before settle is {},after settled the file size is {}",
              originFileSize,
              getSize());
        }
      } catch (IOException e) {
        logger.error("remove origin file or rename new mods file error.", e);
      }
      hasCompacted = true;
    }
  }
Create a hardlink for the modification file. The hardlink with have a suffix like
".{sysTime}_{randomLong}"

@return a new ModificationFile with its path changed to the hardlink, or null if the origin
    file does not exist or the hardlink cannot be created.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/modification/v1/ModificationFileV1.java