@@ -0,0 +1,2925 @@
+/*%0A * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0%0A * (the %22License%22). You may not use this work except in compliance with the License, which is%0A * available at www.apache.org/licenses/LICENSE-2.0%0A *%0A * This software is distributed on an %22AS IS%22 basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,%0A * either express or implied, as more fully set forth in the License.%0A *%0A * See the NOTICE file distributed with this work for information regarding copyright ownership.%0A */%0A%0Apackage alluxio.client.file.policy;%0A%0Aimport alluxio.client.block.BlockWorkerInfo;%0Aimport alluxio.util.network.NetworkAddressUtils;%0Aimport alluxio.wire.WorkerNetAddress;%0A%0Aimport com.google.common.base.Objects;%0Aimport com.google.common.collect.Lists;%0A%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0Aimport javax.annotation.concurrent.ThreadSafe;%0A/**%0A * A policy that returns local host first, and if the local worker doesn't have enough availability,%0A * it randomly picks a worker from the active workers list for each block write.%0A * If No worker meets the demands, return local host.%0A */%0A@ThreadSafe%0Apublic class LocalFirstWithoutEvictionPolicy implements FileWriteLocationPolicy %7B%0A  private String mLocalHostName;%0A  /**%0A   * Constructs a %7B@link LocalFirstWithoutEvictionPolicy%7D.%0A   */%0A  public LocalFirstWithoutEvictionPolicy() %7B%0A    mLocalHostName = NetworkAddressUtils.getLocalHostName();%0A  %7D%0A%0A  @Override%0A  public WorkerNetAddress getWorkerForNextBlock(Iterable%3CBlockWorkerInfo%3E workerInfoList,%0A      long blockSizeBytes) %7B%0A    // try the local host first%0A    WorkerNetAddress localWorkerNetAddress = null;%0A    for (BlockWorkerInfo workerInfo : workerInfoList) %7B%0A      if (workerInfo.getNetAddress().getHost().equals(mLocalHostName)) %7B%0A        localWorkerNetAddress = workerInfo.getNetAddress();%0A        if (workerInfo.getAvailableBytes() %3E= blockSizeBytes) %7B%0A          return localWorkerNetAddress;%0A        %7D%0A      %7D%0A    %7D%0A%0A    // otherwise randomly pick a worker that has enough availability%0A    List%3CBlockWorkerInfo%3E shuffledWorkers = Lists.newArrayList(workerInfoList);%0A    Collections.shuffle(shuffledWorkers);%0A    for (BlockWorkerInfo workerInfo : shuffledWorkers) %7B%0A      if (workerInfo.getAvailableBytes() %3E= blockSizeBytes) %7B%0A        return workerInfo.getNetAddress();%0A      %7D%0A    %7D%0A    return localWorkerNetAddress;%0A  %7D%0A%0A  @Override%0A  public boolean equals(Object o) %7B%0A    if (this == o) %7B%0A      return true;%0A    %7D%0A    if (!(o instanceof LocalFirstWithoutEvictionPolicy)) %7B%0A      return false;%0A    %7D%0A    LocalFirstWithoutEvictionPolicy that = (LocalFirstWithoutEvictionPolicy) o;%0A    return Objects.equal(mLocalHostName, that.mLocalHostName);%0A  %7D%0A%0A  @Override%0A  public int hashCode() %7B%0A    return Objects.hashCode(mLocalHostName);%0A  %7D%0A%0A  @Override%0A  public String toString() %7B%0A    return Objects.toStringHelper(this)%0A        .add(%22localHostName%22, mLocalHostName)%0A        .toString();%0A  %7D%0A%7D%0A

Add a LocalFirstPolicy that without evict action