/** * @param other a tiered identity to compare to * @return whether the top tier of this tiered identity matches the top tier of other */ public boolean topTiersMatch(TieredIdentity other) { return mTiers.get(0).equals(other.getTier(0)); }
String value = null; if (scriptIdentity != null) { LocalityTier scriptTier = scriptIdentity.getTier(i); Preconditions.checkState(scriptTier.getTierName().equals(tierName)); value = scriptTier.getValue();
dataSource = locations.stream().map(BlockLocation::getWorkerAddress) .filter(addr -> addr.getTieredIdentity().equals(nearest.get())).findFirst().get(); if (mTieredIdentity.getTier(0).getTierName().equals(Constants.LOCALITY_NODE) && mTieredIdentity.topTiersMatch(nearest.get())) { dataSourceType = BlockInStreamSource.LOCAL;
@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")); FileWriteLocationPolicy policy; WorkerNetAddress chosen; // local rack with enough availability policy = new LocalFirstAvoidEvictionPolicy( TieredIdentityFactory.fromString("node=node2,rack=rack3", mConf), mConf); chosen = policy.getWorkerForNextBlock(workers, Constants.GB); assertEquals("node4", chosen.getTieredIdentity().getTier(0).getValue()); }
@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 = LocalFirstPolicy.create(TieredIdentityFactory.fromString("node=node1,rack=rack2", sConf), sConf.getBoolean(PropertyKey.LOCALITY_COMPARE_NODE_IP)); chosen = policy.getWorkerForNextBlock(workers, Constants.GB); assertEquals("rack2", chosen.getTieredIdentity().getTier(1).getValue()); // local node policy = LocalFirstPolicy.create(TieredIdentityFactory.fromString("node=node4,rack=rack3", sConf), sConf.getBoolean(PropertyKey.LOCALITY_COMPARE_NODE_IP)); chosen = policy.getWorkerForNextBlock(workers, Constants.GB); assertEquals("node4", chosen.getTieredIdentity().getTier(0).getValue()); }
/** * @param other a tiered identity to compare to * @return whether the top tier of this tiered identity matches the top tier of other */ public boolean topTiersMatch(TieredIdentity other) { return mTiers.get(0).equals(other.getTier(0)); }
String value = null; if (scriptIdentity != null) { LocalityTier scriptTier = scriptIdentity.getTier(i); Preconditions.checkState(scriptTier.getTierName().equals(tierName)); value = scriptTier.getValue();