/** * Given the DiskUsage for a node and the size of the shard, return the percentage of free disk if * the shard were to be allocated to the node. * * @param usage A DiskUsage for the node to have space computed for * @param shardSize Size in bytes of the shard * @return Percentage of free space after the shard is assigned to the node */ public double freeDiskPercentageAfterShardAssigned(DiskUsage usage, Long shardSize) { shardSize = (shardSize == null) ? 0 : shardSize; return 100.0 - (((double) (usage.getUsedBytes() + shardSize) / usage.getTotalBytes()) * 100.0); }