use of alluxio.client.block.stream.BlockWorkerClientPool in project alluxio by Alluxio.
the class FileSystemContext method closeContext.
private synchronized void closeContext() throws IOException {
if (!mClosed.get()) {
// Setting closed should be the first thing we do because if any of the close operations
// fail we'll only have a half-closed object and performing any more operations or closing
// again on a half-closed object can possibly result in more errors (i.e. NPE). Setting
// closed first is also recommended by the JDK that in implementations of #close() that
// developers should first mark their resources as closed prior to any exceptions being
// thrown.
mClosed.set(true);
MetricsSystem.removeMetrics(TOTAL_RPC_CLIENTS_METRICS_NAME);
LOG.debug("Closing fs master client pool with current size: {} for id: {}", mFileSystemMasterClientPool.size(), mId);
mFileSystemMasterClientPool.close();
mFileSystemMasterClientPool = null;
LOG.debug("Closing block master client pool with size: {} for id: {}", mBlockMasterClientPool.size(), mId);
mBlockMasterClientPool.close();
mBlockMasterClientPool = null;
for (BlockWorkerClientPool pool : mBlockWorkerClientPoolMap.values()) {
LOG.debug("Closing block worker client pool with size: {} for id: {}", pool.size(), mId);
pool.close();
}
// Close worker group after block master clients in order to allow
// clean termination for open streams.
mBlockWorkerClientPoolMap.clear();
mBlockWorkerClientPoolMap = null;
mLocalWorkerInitialized = false;
mLocalWorker = null;
if (mMetricsEnabled) {
MetricsHeartbeatContext.removeHeartbeat(getClientContext());
}
} else {
LOG.warn("Attempted to close FileSystemContext which has already been closed or not " + "initialized.");
}
}
use of alluxio.client.block.stream.BlockWorkerClientPool in project alluxio by Alluxio.
the class FileSystemContext method acquireBlockWorkerClientInternal.
private CloseableResource<BlockWorkerClient> acquireBlockWorkerClientInternal(final WorkerNetAddress workerNetAddress, final ClientContext context, UserState userState) throws IOException {
SocketAddress address = NetworkAddressUtils.getDataPortSocketAddress(workerNetAddress, context.getClusterConf());
GrpcServerAddress serverAddress = GrpcServerAddress.create(workerNetAddress.getHost(), address);
ClientPoolKey key = new ClientPoolKey(address, AuthenticationUserUtils.getImpersonationUser(userState.getSubject(), context.getClusterConf()));
final ConcurrentHashMap<ClientPoolKey, BlockWorkerClientPool> poolMap = mBlockWorkerClientPoolMap;
return new CloseableResource<BlockWorkerClient>(poolMap.computeIfAbsent(key, k -> new BlockWorkerClientPool(userState, serverAddress, context.getClusterConf().getInt(PropertyKey.USER_BLOCK_WORKER_CLIENT_POOL_MIN), context.getClusterConf().getInt(PropertyKey.USER_BLOCK_WORKER_CLIENT_POOL_MAX), context.getClusterConf())).acquire()) {
// Save the reference to the original pool map.
@Override
public void closeResource() {
releaseBlockWorkerClient(workerNetAddress, get(), context, poolMap);
}
};
}
Aggregations