@Override protected BlockMasterClient createNewResource() { return new BlockMasterClient(mMasterAddress, ClientContext.getConf()); } }
/** * @return all the works' info * @throws IOException if the underlying master RPC fails */ public synchronized List<WorkerInfo> getWorkersInfo() throws IOException { return mBlockMasterClient.getWorkerInfoList(); }
/** * Gets the block info of a block, if it exists. * * @param blockId the blockId to obtain information about * @return a FileBlockInfo containing the metadata of the block * @throws IOException if the block does not exist */ public BlockInfo getInfo(long blockId) throws IOException { BlockMasterClient masterClient = mContext.acquireMasterClient(); try { return masterClient.getBlockInfo(blockId); } finally { mContext.releaseMasterClient(masterClient); } }
/** * Gets the info of a list of workers. * * @return A list of worker info returned by master * @throws IOException if an I/O error occurs */ public synchronized List<WorkerInfo> getWorkerInfoList() throws IOException { int retry = 0; while (!mClosed && (retry ++) <= RPC_MAX_NUM_RETRY) { connect(); try { return mClient.getWorkerInfoList(); } catch (TException e) { LOG.error(e.getMessage(), e); mConnected = false; } } throw new IOException("Failed after " + retry + " retries."); }
/** * Gets the used bytes of Tachyon's BlockStore. * * @throws IOException */ public long getUsedBytes() throws IOException { BlockMasterClient blockMasterClient = mContext.acquireMasterClient(); try { return blockMasterClient.getUsedBytes(); } finally { mContext.releaseMasterClient(blockMasterClient); } }
/** * Gets the total capacity of Tachyon's BlockStore. * * @return the capacity in bytes * @throws IOException */ public long getCapacityBytes() throws IOException { BlockMasterClient blockMasterClient = mContext.acquireMasterClient(); try { return blockMasterClient.getCapacityBytes(); } finally { mContext.releaseMasterClient(blockMasterClient); } }
try { BlockInfo blockInfo = masterClient.getBlockInfo(blockId); if (blockInfo.locations.isEmpty()) { throw new IOException("Block " + blockId + " is not available in Tachyon");
/** * Gets the total Tachyon capacity in bytes, on all the tiers of all the workers. * * @return total capacity in bytes * @throws IOException if an I/O error occurs */ public synchronized long getCapacityBytes() throws IOException { int retry = 0; while (!mClosed && (retry ++) <= RPC_MAX_NUM_RETRY) { connect(); try { return mClient.getCapacityBytes(); } catch (TException e) { LOG.error(e.getMessage(), e); mConnected = false; } } throw new IOException("Failed after " + retry + " retries."); }
/** * 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); } } }
/** * Returns the BlockInfo for a block id. * * @param blockId the block id to get the BlockInfo for * @return the BlockInfo * @throws IOException if an I/O error occurs */ public synchronized BlockInfo getBlockInfo(long blockId) throws IOException { int retry = 0; while (!mClosed && (retry ++) <= RPC_MAX_NUM_RETRY) { connect(); try { return mClient.getBlockInfo(blockId); } catch (TException e) { LOG.error(e.getMessage(), e); mConnected = false; } } throw new IOException("Failed after " + retry + " retries."); }
/** * Gets the worker address based on its hostname by querying the master. * * @param hostname hostname of the worker to query, empty string denotes any worker * @return NetAddress of hostname, or null if no worker found */ private synchronized NetAddress getWorkerAddress(String hostname) { BlockMasterClient masterClient = acquireMasterClient(); try { List<WorkerInfo> workers = masterClient.getWorkerInfoList(); if (hostname.isEmpty() && !workers.isEmpty()) { // TODO(calvin): Do this in a more defined way. return workers.get(0).getAddress(); } for (WorkerInfo worker : workers) { if (worker.getAddress().getHost().equals(hostname)) { return worker.getAddress(); } } } catch (IOException ioe) { Throwables.propagate(ioe); } finally { releaseMasterClient(masterClient); } return null; }
BlockMasterClient blockMasterClient = mContext.acquireMasterClient(); try { blockSize = blockMasterClient.getBlockInfo(blockId).getLength(); } finally { mContext.releaseMasterClient(blockMasterClient);
/** * Gets the total amount of used space in bytes, on all the tiers of all the workers. * * @return amount of used space in bytes * @throws IOException if an I/O error occurs */ public synchronized long getUsedBytes() throws IOException { int retry = 0; while (!mClosed && (retry ++) <= RPC_MAX_NUM_RETRY) { connect(); try { return mClient.getUsedBytes(); } catch (TException e) { LOG.error(e.getMessage(), e); mConnected = false; } } throw new IOException("Failed after " + retry + " retries."); } }