private long updateRewrite(Master master, File f, Location accessLoc, int rewriteCount) {
    MasterMeta fm = null;
    if (master.map.containsKey(f.getId())) {
      fm = master.map.get(f.getId());
    } else {
      fm = new MasterMeta(f);
      master.map.put(f.getId(), fm);
    }

    int cCount = master.clusters.size();
    int writes = 0;
    long maxDelay = -1;
    for (int i = 0; i < cCount && writes < rewriteCount; i++) {
      Cluster cluster = master.clusters.get(i);
      if (fm.instances.contains(cluster) || !cluster.isHealthy()) {
        continue;
      }
      FileWrite fw = cluster.write(f, NODE_PER_CLUSTER_WRITE_REDUNDANCY);
      double distance = accessLoc.distance(cluster.getLocation());
      if (fw.time > 0) { // Cluster had sufficient space.
        maxDelay = Math.max(maxDelay, fw.time + Util.networkTime(f.getSize(), distance));
        fm.instances.add(cluster);
        writes++;
      } else if (fw.time != Cluster.NO_SPACE_SENTINEL) {
        cluster.calibrateSpaceAvailability(NODE_PER_CLUSTER_WRITE_REDUNDANCY);
      }
    }
    if (writes < rewriteCount) {
      return -1;
    }
    return maxDelay;
  }