/** * Checks if a given block is less than needed size to meet our goal. * * @param blockSize - block len * @param item - Work item * @return true if this block meets our criteria, false otherwise. */ private boolean isLessThanNeeded(long blockSize, DiskBalancerWorkItem item) { long bytesToCopy = item.getBytesToCopy() - item.getBytesCopied(); bytesToCopy = bytesToCopy + ((bytesToCopy * getBlockTolerancePercentage(item)) / 100); return (blockSize <= bytesToCopy) ? true : false; }
/** * Inflates bytesCopied and returns true or false. This allows us to stop * copying if we have reached close enough. * * @param item DiskBalancerWorkItem * @return -- false if we need to copy more, true if we are done */ private boolean isCloseEnough(DiskBalancerWorkItem item) { long temp = item.getBytesCopied() + ((item.getBytesCopied() * getBlockTolerancePercentage(item)) / 100); return (item.getBytesToCopy() >= temp) ? false : true; }
/** * Insert work items to work map. * @param volumePair - VolumePair * @param step - Move Step */ private void createWorkPlan(final VolumePair volumePair, Step step) throws DiskBalancerException { if (volumePair.getSourceVolUuid().equals(volumePair.getDestVolUuid())) { final String errMsg = "Disk Balancer - Source and destination volumes " + "are same: " + volumePair.getSourceVolUuid(); LOG.warn(errMsg); throw new DiskBalancerException(errMsg, DiskBalancerException.Result.INVALID_MOVE); } long bytesToMove = step.getBytesToMove(); // In case we have a plan with more than // one line of same VolumePair // we compress that into one work order. if (workMap.containsKey(volumePair)) { bytesToMove += workMap.get(volumePair).getBytesToCopy(); } DiskBalancerWorkItem work = new DiskBalancerWorkItem(bytesToMove, 0); // all these values can be zero, if so we will use // values from configuration. work.setBandwidth(step.getBandwidth()); work.setTolerancePercent(step.getTolerancePercent()); work.setMaxDiskErrors(step.getMaxDiskErrors()); workMap.put(volumePair, work); }
if (dest.getAvailable() > item.getBytesToCopy()) { long begin = System.nanoTime(); this.dataset.moveBlockAcrossVolumes(block, dest);