private void addLocations(FileBlockInfo fileBlockInfo) { Set<String> locations = Sets.newHashSet(); // add tachyon locations for (BlockLocation location : fileBlockInfo.getBlockInfo().getLocations()) { locations.add(location.getWorkerAddress().getHost()); } // add underFS locations for (NetAddress address : fileBlockInfo.getUfsLocations()) { locations.add(address.getHost()); } mLocations.addAll(locations); }
/** * @return true if the block is in some worker's memory, false otherwise */ private boolean isInMemory(BlockInfo blockInfo) { for (BlockLocation location : blockInfo.getLocations()) { if (location.getTier() == StorageLevelAlias.MEM.getValue()) { return true; } } return false; }
/** * Creates a {@link BlockInfo} form a given {@link MasterBlockInfo}, by populating worker * locations. * * mWorkers should already be locked before calling this method. * * @param masterBlockInfo the {@link MasterBlockInfo} * @return a {@link BlockInfo} from a {@link MasterBlockInfo}. Populates worker locations */ private BlockInfo generateBlockInfo(MasterBlockInfo masterBlockInfo) { // "Join" to get all the addresses of the workers. List<BlockLocation> locations = new ArrayList<BlockLocation>(); for (MasterBlockLocation masterBlockLocation : masterBlockInfo.getBlockLocations()) { MasterWorkerInfo workerInfo = mWorkers.getFirstByField(mIdIndex, masterBlockLocation.getWorkerId()); if (workerInfo != null) { locations.add(new BlockLocation(masterBlockLocation.getWorkerId(), workerInfo.getAddress(), masterBlockLocation.getTier())); } } return new BlockInfo(masterBlockInfo.getBlockId(), masterBlockInfo.getLength(), locations); }
addrs.add(location.getWorkerAddress());
/** * @return true if the given block is in some worker's memory, false otherwise */ private boolean isInMemory(BlockInfo blockInfo) { for (BlockLocation location : blockInfo.getLocations()) { if (location.getTier() == StorageLevelAlias.MEM.getValue()) { return true; } } return false; }
NetAddress workerNetAddress = location.getWorkerAddress(); if (workerNetAddress.getHost().equals(localHostName)) { NetAddress workerNetAddress = blockInfo.locations.get(0).getWorkerAddress(); return new RemoteBlockInStream(blockId, blockInfo.getLength(), new InetSocketAddress(workerNetAddress.getHost(), workerNetAddress.getDataPort()));
/** * Displays a list of hosts that have the file specified in argv stored. * * @param path The TachyonURI path as the input of the command * @return 0 if command is successful, -1 if an error occurred * @throws IOException */ public int location(TachyonURI path) throws IOException { TachyonFile fd; FileInfo fInfo; try { fd = mTfs.open(path); fInfo = mTfs.getInfo(fd); } catch (TachyonException e) { throw new IOException(e.getMessage()); } System.out.println(path + " with file id " + fd.getFileId() + " is on nodes: "); for (long blockId : fInfo.getBlockIds()) { for (BlockLocation location : TachyonBlockStore.get().getInfo(blockId).getLocations()) { System.out.println(location.getWorkerAddress().getHost()); } } return 0; }
addrs.add(location.getWorkerAddress());
/** * Attempts to promote a block in Tachyon space. If the block is not present, this method will * return without an error. If the block is present in multiple workers, only one worker will * receive the promotion request. * * @param blockId the id of the block to promote * @throws IOException if the block does not exist */ public void promote(long blockId) throws IOException { BlockMasterClient blockMasterClient = mContext.acquireMasterClient(); try { BlockInfo info = blockMasterClient.getBlockInfo(blockId); if (info.getLocations().isEmpty()) { // Nothing to promote return; } // Get the first worker address for now, as this will likely be the location being read from // TODO: Get this location via a policy (possibly location is a parameter to promote) NetAddress workerAddr = info.getLocations().get(0).getWorkerAddress(); WorkerClient workerClient = mContext.acquireWorkerClient(workerAddr.getHost()); try { workerClient.promoteBlock(blockId); } finally { mContext.releaseWorkerClient(workerClient); } } finally { mContext.releaseMasterClient(blockMasterClient); } } }