private void dealWithPageUnAlignedFileSize(Path storagePath,
                                             long fileSize,
                                             MMappedFileStorage.RegionAllocationAtomicityLock regionAllocationLock) throws IOException {
    // It is generally an error to have file un-aligned with page size.
    //    One exception is if next-page-expansion wasn't finished because of app crash -> check for it.
    //    Another exception: we're explicitly asked to ignore that and just expand the file to page-aligned size
    //    Otherwise: fail

    //Maybe there was a file expansion interrupted by app crash/kill?
    long startOfSuspiciousRegion = (fileSize / pageSize) * pageSize;
    MMappedFileStorage.RegionAllocationAtomicityLock.Region region = regionAllocationLock.region(startOfSuspiciousRegion, pageSize);
    if (region.isUnfinished()) {
      //There is an 'unfinished' region -- i.e. file expansion and zeroing started, but was interrupted by app crash/kill.
      // MMappedFileStorage will deal with it, no need to do anything here
      return;
    }

    switch (ifFileNotPageAligned) {
      case THROW_EXCEPTION -> {
        throw new IOException("[" + storagePath + "]: fileSize(=" + fileSize + " b) is not page(=" + pageSize + " b)-aligned");
      }

      case EXPAND_FILE -> {
        LOG.warn("[" + storagePath + "]: fileSize(=" + fileSize + " b) is not page(=" + pageSize + " b)-aligned -> expand until aligned");
        //expand (zeroes) file up to the next page:
        long fileSizeRoundedUpToPageSize = ((fileSize / pageSize) + 1) * pageSize;
        try (FileChannel channel = FileChannel.open(storagePath, WRITE)) {
          IOUtil.allocateFileRegion(channel, fileSizeRoundedUpToPageSize);
        }
      }
      case CLEAN -> {
        LOG.warn("[" + storagePath + "]: fileSize(=" + fileSize + " b) is not page(=" + pageSize + " b)-aligned -> delete & re-create");
        FileUtil.delete(storagePath);
      }
    }
  }
private void dealWithPageUnAlignedFileSize(Path storagePath,
                                             long fileSize,
                                             MMappedFileStorage.RegionAllocationAtomicityLock regionAllocationLock)