/** * Releases the {@link BlockWorkerClient} back to the client pool, or destroys it if it was a * remote client. * * @param blockWorkerClient the worker client to release, the client should not be accessed after * this method is called */ public void releaseWorkerClient(BlockWorkerClient blockWorkerClient) { // If the client is local and the pool exists, release the client to the pool, otherwise just // close the client. if (blockWorkerClient.isLocal()) { // Return local worker client to its resource pool. WorkerNetAddress address = blockWorkerClient.getWorkerNetAddress(); if (!mLocalBlockWorkerClientPoolMap.containsKey(address)) { LOG.error( "The client to worker at {} to release is no longer registered in the context.", address); blockWorkerClient.close(); } else { mLocalBlockWorkerClientPoolMap.get(address).release(blockWorkerClient); } } else { // Destroy remote worker client. blockWorkerClient.close(); } }
/** * Attempts to promote a block in Alluxio 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 { BlockInfo info; try (CloseableResource<BlockMasterClient> blockMasterClientResource = mContext.acquireMasterClientResource()) { info = blockMasterClientResource.get().getBlockInfo(blockId); } catch (AlluxioException e) { throw new IOException(e); } 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(calvin): Get this location via a policy (possibly location is a parameter to promote) WorkerNetAddress workerAddr = info.getLocations().get(0).getWorkerAddress(); BlockWorkerClient blockWorkerClient = mContext.acquireWorkerClient(workerAddr.getHost()); try { blockWorkerClient.promoteBlock(blockId); } catch (AlluxioException e) { throw new IOException(e); } finally { mContext.releaseWorkerClient(blockWorkerClient); } }