Search in sources :

Example 6 with GetWorkerOptions

use of alluxio.client.block.policy.options.GetWorkerOptions in project alluxio by Alluxio.

the class LocalFirstAvoidEvictionPolicyTest method chooseClosestTierAvoidEviction.

@Test
public void chooseClosestTierAvoidEviction() throws Exception {
    List<BlockWorkerInfo> workers = new ArrayList<>();
    workers.add(worker(Constants.GB, Constants.MB, "node2", "rack3"));
    workers.add(worker(Constants.GB, 0, "node3", "rack2"));
    workers.add(worker(Constants.GB, 0, "node4", "rack3"));
    BlockLocationPolicy policy;
    WorkerNetAddress chosen;
    // local rack with enough availability
    policy = new LocalFirstAvoidEvictionPolicy(mConf.getBytes(PropertyKey.USER_BLOCK_AVOID_EVICTION_POLICY_RESERVED_BYTES), TieredIdentityFactory.fromString("node=node2,rack=rack3", mConf), mConf);
    GetWorkerOptions options = GetWorkerOptions.defaults().setBlockWorkerInfos(workers).setBlockInfo(new BlockInfo().setLength(Constants.GB));
    chosen = policy.getWorker(options);
    assertEquals("node4", chosen.getTieredIdentity().getTier(0).getValue());
}
Also used : WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) ArrayList(java.util.ArrayList) GetWorkerOptions(alluxio.client.block.policy.options.GetWorkerOptions) Test(org.junit.Test)

Example 7 with GetWorkerOptions

use of alluxio.client.block.policy.options.GetWorkerOptions in project alluxio by Alluxio.

the class LocalFirstPolicyTest method tieredLocalityEnoughSpace.

@Test
public void tieredLocalityEnoughSpace() throws Exception {
    List<BlockWorkerInfo> workers = new ArrayList<>();
    // Local node doesn't have enough space
    workers.add(worker(Constants.MB, "node2", "rack3"));
    workers.add(worker(Constants.GB, "node3", "rack2"));
    // Local rack has enough space
    workers.add(worker(Constants.GB, "node4", "rack3"));
    LocalFirstPolicy policy = new LocalFirstPolicy(TieredIdentityFactory.fromString("node=node2,rack=rack3", sConf), sConf);
    GetWorkerOptions options = GetWorkerOptions.defaults().setBlockWorkerInfos(workers).setBlockInfo(new BlockInfo().setLength(Constants.GB));
    WorkerNetAddress chosen = policy.getWorker(options);
    assertEquals(workers.get(2).getNetAddress(), chosen);
}
Also used : BlockInfo(alluxio.wire.BlockInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) ArrayList(java.util.ArrayList) GetWorkerOptions(alluxio.client.block.policy.options.GetWorkerOptions) Test(org.junit.Test)

Example 8 with GetWorkerOptions

use of alluxio.client.block.policy.options.GetWorkerOptions in project alluxio by Alluxio.

the class LocalFirstPolicyTest method chooseClosestTier.

@Test
public void chooseClosestTier() throws Exception {
    List<BlockWorkerInfo> workers = new ArrayList<>();
    workers.add(worker(Constants.GB, "node2", "rack3"));
    workers.add(worker(Constants.GB, "node3", "rack2"));
    workers.add(worker(Constants.GB, "node4", "rack3"));
    LocalFirstPolicy policy;
    WorkerNetAddress chosen;
    // local rack
    policy = new LocalFirstPolicy(TieredIdentityFactory.fromString("node=node1,rack=rack2", sConf), sConf);
    GetWorkerOptions options = GetWorkerOptions.defaults().setBlockWorkerInfos(workers).setBlockInfo(new BlockInfo().setLength(Constants.GB));
    chosen = policy.getWorker(options);
    assertEquals("rack2", chosen.getTieredIdentity().getTier(1).getValue());
    // local node
    policy = new LocalFirstPolicy(TieredIdentityFactory.fromString("node=node4,rack=rack3", sConf), sConf);
    chosen = policy.getWorker(options);
    assertEquals("node4", chosen.getTieredIdentity().getTier(0).getValue());
}
Also used : WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) ArrayList(java.util.ArrayList) GetWorkerOptions(alluxio.client.block.policy.options.GetWorkerOptions) Test(org.junit.Test)

Example 9 with GetWorkerOptions

use of alluxio.client.block.policy.options.GetWorkerOptions in project alluxio by Alluxio.

the class LocalFirstPolicyTest method getLocalFirst.

/**
 * Tests that the local host is returned first.
 */
@Test
public void getLocalFirst() {
    String localhostName = NetworkAddressUtils.getLocalHostName(sResolutionTimeout);
    LocalFirstPolicy policy = new LocalFirstPolicy(sConf);
    List<BlockWorkerInfo> workers = new ArrayList<>();
    workers.add(worker(Constants.GB, "worker1", ""));
    workers.add(worker(Constants.GB, localhostName, ""));
    GetWorkerOptions options = GetWorkerOptions.defaults().setBlockWorkerInfos(workers).setBlockInfo(new BlockInfo().setLength(Constants.MB));
    assertEquals(localhostName, policy.getWorker(options).getHost());
}
Also used : BlockInfo(alluxio.wire.BlockInfo) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) ArrayList(java.util.ArrayList) GetWorkerOptions(alluxio.client.block.policy.options.GetWorkerOptions) Test(org.junit.Test)

Example 10 with GetWorkerOptions

use of alluxio.client.block.policy.options.GetWorkerOptions in project alluxio by Alluxio.

the class RoundRobinPolicyTest method getWorker.

/**
 * Tests that the correct workers are chosen when round robin is used.
 */
@Test
public void getWorker() {
    List<BlockWorkerInfo> workerInfoList = new ArrayList<>();
    workerInfoList.add(new BlockWorkerInfo(new WorkerNetAddress().setHost("worker1").setRpcPort(PORT).setDataPort(PORT).setWebPort(PORT), Constants.GB, 0));
    workerInfoList.add(new BlockWorkerInfo(new WorkerNetAddress().setHost("worker2").setRpcPort(PORT).setDataPort(PORT).setWebPort(PORT), 2 * (long) Constants.GB, 0));
    workerInfoList.add(new BlockWorkerInfo(new WorkerNetAddress().setHost("worker3").setRpcPort(PORT).setDataPort(PORT).setWebPort(PORT), 3 * (long) Constants.GB, 0));
    RoundRobinPolicy policy = new RoundRobinPolicy(ConfigurationTestUtils.defaults());
    GetWorkerOptions options = GetWorkerOptions.defaults().setBlockWorkerInfos(workerInfoList).setBlockInfo(new BlockInfo().setLength(2 * (long) Constants.GB));
    assertNotEquals(policy.getWorker(options).getHost(), policy.getWorker(options.setBlockInfo(options.getBlockInfo().setBlockId(123))).getHost());
    assertEquals(policy.getWorker(options.setBlockInfo(options.getBlockInfo().setBlockId(555))).getHost(), policy.getWorker(options.setBlockInfo(options.getBlockInfo().setBlockId(555))).getHost());
}
Also used : WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) ArrayList(java.util.ArrayList) GetWorkerOptions(alluxio.client.block.policy.options.GetWorkerOptions) Test(org.junit.Test)

Aggregations

GetWorkerOptions (alluxio.client.block.policy.options.GetWorkerOptions)18 BlockInfo (alluxio.wire.BlockInfo)16 ArrayList (java.util.ArrayList)16 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)15 Test (org.junit.Test)14 WorkerNetAddress (alluxio.wire.WorkerNetAddress)12 BlockLocationPolicy (alluxio.client.block.policy.BlockLocationPolicy)3 Lists (com.google.common.collect.Lists)3 HashMap (java.util.HashMap)3 List (java.util.List)3 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)2 UnavailableException (alluxio.exception.status.UnavailableException)2 TieredIdentity (alluxio.wire.TieredIdentity)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 MoreObjects (com.google.common.base.MoreObjects)2 Objects (com.google.common.base.Objects)2 Map (java.util.Map)2 Set (java.util.Set)2 WriteType (alluxio.client.WriteType)1 BlockInStream (alluxio.client.block.stream.BlockInStream)1