private void deleteExtraSegments(Map<String, Map<Long, Long>> overallRequirements) throws IOException {
    // delete extra store segments
    Iterator<Map.Entry<String, ReserveFileMap>> iter = storeReserveFiles.entrySet().iterator();
    while (iter.hasNext()) {
      Map.Entry<String, ReserveFileMap> entry = iter.next();
      String storeId = entry.getKey();
      File storeReserveDir = new File(reserveDir, STORE_DIR_PREFIX + storeId);
      if (!overallRequirements.containsKey(storeId)) {
        // remove store id from in-mem store reserve map
        iter.remove();
        Utils.deleteFileOrDirectory(storeReserveDir);
      } else {
        ReserveFileMap sizeToFilesMap = storeReserveFiles.get(storeId);
        Map<Long, Long> storeRequirement = overallRequirements.get(storeId);
        for (Long sizeInBytes : sizeToFilesMap.getFileSizeSet()) {
          Long segmentsNeeded = storeRequirement.get(sizeInBytes);
          if (segmentsNeeded == null || segmentsNeeded == 0) {
            // 1. empty file queue to update in-mem store reserve map
            while (sizeToFilesMap.getCount(sizeInBytes) > 0) {
              sizeToFilesMap.remove(sizeInBytes);
            }
            // 2. delete directory of store segments with certain size
            File dirToDelete = new File(storeReserveDir, generateFileSizeDirName(sizeInBytes));
            Utils.deleteFileOrDirectory(dirToDelete);
          } else {
            while (sizeToFilesMap.getCount(sizeInBytes) > segmentsNeeded) {
              File fileToDelete = sizeToFilesMap.remove(sizeInBytes);
              if (fileToDelete != null && !fileToDelete.delete()) {
                throw new IOException("Could not delete the following reserve file: " + fileToDelete.getAbsolutePath());
              }
            }
          }
        }
      }
    }
    // delete extra swap segments
    Map<Long, Long> requiredSwapSegments = overallRequirements.get(SWAP_DIR_NAME);
    for (long sizeInBytes : swapReserveFiles.getFileSizeSet()) {
      Long segmentsNeeded = requiredSwapSegments.get(sizeInBytes);
      if (segmentsNeeded == null || segmentsNeeded == 0) {
        // 1. empty file queue to update in-mem swap reserve map
        while (swapReserveFiles.getCount(sizeInBytes) > 0) {
          swapReserveFiles.remove(sizeInBytes);
        }
        // 2. delete directory of swap segments with certain size
        File dirToDelete = new File(swapReserveDir, generateFileSizeDirName(sizeInBytes));
        Utils.deleteFileOrDirectory(dirToDelete);
      } else {
        while (swapReserveFiles.getCount(sizeInBytes) > segmentsNeeded) {
          File fileToDelete = swapReserveFiles.remove(sizeInBytes);
          if (!fileToDelete.delete()) {
            throw new IOException("Could not delete the following reserve file: " + fileToDelete.getAbsolutePath());
          }
        }
      }
    }
  }
Delete the currently-present reserve files that are not required by {@code overallRequirements}.
@param overallRequirements a map between segment sizes in bytes and the number of segments needed for that size.
@throws IOException
ambry-store/src/main/java/com/github/ambry/store/DiskSpaceAllocator.java