private void copy(String storeId, File src, File tgt, long capacityInBytes) throws Exception {
    boolean sourceHasProblems;
    // NOTE: Ideally, we would have liked one MetricRegistry instance to record metrics across all these stores
    // However, due to the fact that PersistentIndex and HardDeleter initialize gauges inside StoreMetrics, the
    // MetricRegistry retains references to the PersistentIndex causing a memory leak. If the same instance is to be
    // used, these gauges have to be removed from the registry on store shutdown. This is being deferred to future work.
    StoreMetrics metrics = new StoreMetrics(new MetricRegistry());
    try (
        StoreCopier copier = new StoreCopier(storeId, src, tgt, capacityInBytes, fetchSizeInBytes, storeConfig, metrics,
            storeKeyFactory, diskIOScheduler, diskSpaceAllocator, transformers, time)) {
      sourceHasProblems = copier.copy(new StoreFindTokenFactory(storeKeyFactory).getNewFindToken()).getSecond();
    }
    if (!sourceHasProblems) {
      // verify that the stores are equivalent
      File[] replicas = {src, tgt};
      Pair<Boolean, Map<File, DumpIndexTool.IndexProcessingResults>> consistencyCheckResult =
          consistencyChecker.checkConsistency(replicas);
      if (!consistencyCheckResult.getFirst()) {
        // there was a problem with the consistency check
        if (consistencyCheckResult.getSecond().get(src).isIndexSane()) {
          // the src index was sane which means either the tgt was not or that they are not consistent. Problem !
          throw new IllegalStateException("Data in " + src + " and " + tgt + " is not equivalent");
        } else {
          // the src itself was bad - nothing we can do. move on.
          logger.warn("{} was not sane. Consistency check was skipped", src);
        }
      }
    } else {
      logger.warn("{} had problems so did not run consistency checker", src);
    }
  }
Copy the partition at {@code src} to {@code tgt} using a {@link StoreCopier}.
@param storeId the name/id of the {@link Store}.
@param src the location of the partition to be copied
@param tgt the location where the partition has to be copied to
@param capacityInBytes the capacity of the partition.
@throws Exception
ambry-tools/src/main/java/com/github/ambry/store/DiskReformatter.java