public void reformat(String diskMountPath, File scratch) throws Exception {
    if (!scratch.exists()) {
      throw new IllegalArgumentException("Scratch space " + scratch + " does not exist");
    }
    List<ReplicaId> replicasOnDisk = new ArrayList<>();
    // populate the replicas on disk
    List<? extends ReplicaId> replicaIds = clusterMap.getReplicaIds(dataNodeId);
    for (ReplicaId replicaId : replicaIds) {
      if (replicaId.getDiskId().getMountPath().equals(diskMountPath)) {
        replicasOnDisk.add(replicaId);
      }
    }
    if (replicasOnDisk.size() == 0) {
      throw new IllegalArgumentException("There are no replicas on " + diskMountPath + " of " + dataNodeId);
    }
    replicasOnDisk.sort(Comparator.comparingLong(ReplicaId::getCapacityInBytes));
    logger.info("Found {} on {}", replicasOnDisk, diskMountPath);

    // move the last replica id (the largest one) to scratch space
    ReplicaId toMove = replicasOnDisk.get(replicasOnDisk.size() - 1);
    String partIdString = toMove.getPartitionId().toString();
    File scratchSrc = new File(toMove.getReplicaPath());
    File scratchTmp = new File(scratch, partIdString + RELOCATION_IN_PROGRESS_SUFFIX);
    File scratchTgt = new File(scratch, partIdString + RELOCATED_DIR_NAME_SUFFIX);
    if (scratchTmp.exists()) {
      throw new IllegalStateException(scratchTmp + " already exists");
    }
    if (scratchTgt.exists()) {
      throw new IllegalStateException(scratchTgt + " already exists");
    }
    ensureNotInUse(scratchSrc, toMove.getCapacityInBytes());
    logger.info("Moving {} to {}", scratchSrc, scratchTgt);
    FileUtils.moveDirectory(scratchSrc, scratchTmp);
    if (!scratchTmp.renameTo(scratchTgt)) {
      throw new IllegalStateException("Could not rename " + scratchTmp + " to " + scratchTgt);
    }

    // reformat each store, except the one moved, one by one
    for (int i = 0; i < replicasOnDisk.size() - 1; i++) {
      ReplicaId replicaId = replicasOnDisk.get(i);
      partIdString = replicaId.getPartitionId().toString();
      File src = new File(replicaId.getReplicaPath());
      File tgt = new File(replicaId.getMountPath(), partIdString + UNDER_REFORMAT_DIR_NAME_SUFFIX);
      logger.info("Copying {} to {}", src, tgt);
      copy(partIdString, src, tgt, replicaId.getCapacityInBytes());
      logger.info("Deleting {}", src);
      Utils.deleteFileOrDirectory(src);
      logger.info("Renaming {} to {}", tgt, src);
      if (!tgt.renameTo(src)) {
        throw new IllegalStateException("Could not rename " + tgt + " to " + src);
      }
      logger.info("Done reformatting {}", replicaId);
    }

    // reformat the moved store
    logger.info("Copying {} to {}", scratchTgt, scratchSrc);
    copy(toMove.getPartitionId().toString(), scratchTgt, scratchSrc, toMove.getCapacityInBytes());
    logger.info("Deleting {}", scratchTgt);
    Utils.deleteFileOrDirectory(scratchTgt);
    logger.info("Done reformatting {}", toMove);
    logger.info("Done reformatting disk {}", diskMountPath);
  }
Uses {@link StoreCopier} to convert all the partitions on the given disk (D).
1. Copies one partition on D to a scratch space
2. Using {@link StoreCopier}, performs copies of all other partitions on D using D as a staging area. When a
partition is completely copied and verified, the original is replaced by the copy.
3. Copies the partition in the scratch space back onto D.
4. Deletes the folder in the scratch space
@param diskMountPath the mount path of the disk to reformat
@param scratch the scratch space to use
@throws Exception
ambry-tools/src/main/java/com/github/ambry/store/DiskReformatter.java