@Test public void getOthersWhenNotEnoughAvailabilityOnLocal() { String localhostName = NetworkAddressUtils.getLocalHostName(1000); BlockLocationPolicy policy = new LocalFirstAvoidEvictionPolicy(mConf); List<BlockWorkerInfo> workers = new ArrayList<>(); workers.add(worker(Constants.GB, 0, "worker1", "")); workers.add(worker(Constants.MB, Constants.MB, localhostName, "")); GetWorkerOptions options = GetWorkerOptions.defaults() .setBlockWorkerInfos(workers).setBlockInfo(new BlockInfo().setLength(Constants.MB)); assertEquals("worker1", policy.getWorker(options).getHost()); }
@Override public WorkerNetAddress getWorker(GetWorkerOptions options) { List<BlockWorkerInfo> allWorkers = Lists.newArrayList(options.getBlockWorkerInfos()); List<BlockWorkerInfo> workers = allWorkers.stream() .filter(worker -> getAvailableBytes(worker) >= options.getBlockInfo().getLength()) .collect(Collectors.toList()); if (workers.isEmpty()) { workers = allWorkers; } GetWorkerOptions filteredWorkers = GetWorkerOptions.defaults() .setBlockInfo(options.getBlockInfo()) .setBlockWorkerInfos(workers); return mPolicy.getWorker(filteredWorkers); }
LocalFirstAvoidEvictionPolicy implements BlockLocationPolicy { @Override public WorkerNetAddress getWorker(GetWorkerOptions options) { List<BlockWorkerInfo> allWorkers = Lists.newArrayList(options.getBlockWorkerInfos()); List<BlockWorkerInfo> workers = allWorkers.stream() .filter(worker -> getAvailableBytes(worker) >= options.getBlockInfo().getLength()) .collect(Collectors.toList()); if (workers.isEmpty()) { workers = allWorkers; } GetWorkerOptions filteredWorkers = GetWorkerOptions.defaults() .setBlockInfo(options.getBlockInfo()) .setBlockWorkerInfos(workers); return mPolicy.getWorker(filteredWorkers); } }
LocalFirstAvoidEvictionPolicy implements BlockLocationPolicy { @Override public WorkerNetAddress getWorker(GetWorkerOptions options) { List<BlockWorkerInfo> allWorkers = Lists.newArrayList(options.getBlockWorkerInfos()); List<BlockWorkerInfo> workers = allWorkers.stream() .filter(worker -> getAvailableBytes(worker) >= options.getBlockInfo().getLength()) .collect(Collectors.toList()); if (workers.isEmpty()) { workers = allWorkers; } GetWorkerOptions filteredWorkers = GetWorkerOptions.defaults() .setBlockInfo(options.getBlockInfo()) .setBlockWorkerInfos(workers); return mPolicy.getWorker(filteredWorkers); } LocalFirstAvoidEvictionPolicy(AlluxioConfiguration conf);   LocalFirstAvoidEvictionPolicy(long blockCapacityReserved,
      AlluxioConfiguration conf); @VisibleForTesting  LocalFirstAvoidEvictionPolicy(long blockCapacityReserved, TieredIdentity identity,
      AlluxioConfiguration conf); }
LocalFirstAvoidEvictionPolicy implements BlockLocationPolicy { @Override public WorkerNetAddress getWorker(GetWorkerOptions options) { List<BlockWorkerInfo> allWorkers = Lists.newArrayList(options.getBlockWorkerInfos()); List<BlockWorkerInfo> workers = allWorkers.stream() .filter(worker -> getAvailableBytes(worker) >= options.getBlockInfo().getLength()) .collect(Collectors.toList()); if (workers.isEmpty()) { workers = allWorkers; } GetWorkerOptions filteredWorkers = GetWorkerOptions.defaults() .setBlockInfo(options.getBlockInfo()) .setBlockWorkerInfos(workers); return mPolicy.getWorker(filteredWorkers); } LocalFirstAvoidEvictionPolicy(AlluxioConfiguration conf);   LocalFirstAvoidEvictionPolicy(long blockCapacityReserved,
      AlluxioConfiguration conf); @VisibleForTesting  LocalFirstAvoidEvictionPolicy(long blockCapacityReserved, TieredIdentity identity,
      AlluxioConfiguration conf); @Override WorkerNetAddress getWorker(GetWorkerOptions options); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
LocalFirstAvoidEvictionPolicy implements BlockLocationPolicy { @Override public WorkerNetAddress getWorker(GetWorkerOptions options) { List<BlockWorkerInfo> allWorkers = Lists.newArrayList(options.getBlockWorkerInfos()); List<BlockWorkerInfo> workers = allWorkers.stream() .filter(worker -> getAvailableBytes(worker) >= options.getBlockInfo().getLength()) .collect(Collectors.toList()); if (workers.isEmpty()) { workers = allWorkers; } GetWorkerOptions filteredWorkers = GetWorkerOptions.defaults() .setBlockInfo(options.getBlockInfo()) .setBlockWorkerInfos(workers); return mPolicy.getWorker(filteredWorkers); } LocalFirstAvoidEvictionPolicy(AlluxioConfiguration conf);   LocalFirstAvoidEvictionPolicy(long blockCapacityReserved,
      AlluxioConfiguration conf); @VisibleForTesting  LocalFirstAvoidEvictionPolicy(long blockCapacityReserved, TieredIdentity identity,
      AlluxioConfiguration conf); @Override WorkerNetAddress getWorker(GetWorkerOptions options); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }