@ThreadSafe public class FileSystemContext extends Object implements Closeable
FileSystem
operations.
Typically, a single JVM should only need one instance of a FileSystem
to connect to
Alluxio. The reference to that client object should be shared among threads.
A second FileSystemContext
object should only be created when a user needs to connect to
Alluxio with a different Subject
and/or AlluxioConfiguration
.
FileSystemContext
instances should be created sparingly because each instance creates
its own thread pools of FileSystemMasterClient
and BlockMasterClient
which can
lead to inefficient use of client machine resources.
A FileSystemContext
should be closed once the user is done performing operations with
Alluxio and no more connections need to be made. Once a FileSystemContext
is closed it
is preferred that the user of the class create a new instance with
create(alluxio.conf.AlluxioConfiguration, java.util.List<java.net.InetSocketAddress>)
to create a new context, rather than reinitializing using the
init(alluxio.ClientContext, alluxio.master.MasterInquireClient)
method.
NOTE: Each context maintains a pool of file system master clients that is already thread-safe.
Synchronizing FileSystemContext
methods could lead to deadlock: thread A attempts to
acquire a client when there are no clients left in the pool and blocks holding a lock on the
FileSystemContext
, when thread B attempts to release a client it owns it is unable to do
so, because thread A holds the lock on FileSystemContext
.Modifier and Type | Class and Description |
---|---|
protected static class |
FileSystemContext.ClientPoolKey
Key for block worker client pools.
|
static class |
FileSystemContext.FileSystemContextFactory
FileSystemContextFactory, it can be extended.
|
static class |
FileSystemContext.GetWorkerListType
This enum class is used for specifying the type of worker list to get.
|
Modifier and Type | Field and Description |
---|---|
static FileSystemContext.FileSystemContextFactory |
sFileSystemContextFactory |
Modifier | Constructor and Description |
---|---|
protected |
FileSystemContext(AlluxioConfiguration conf,
BlockWorker blockWorker,
List<InetSocketAddress> masterAddresses)
Initializes FileSystemContext ID.
|
Modifier and Type | Method and Description |
---|---|
CloseableResource<BlockMasterClient> |
acquireBlockMasterClientResource()
Acquires a block master client resource from the block master client pool.
|
CloseableResource<BlockWorkerClient> |
acquireBlockWorkerClient(WorkerNetAddress workerNetAddress)
Acquires a block worker client from the client pools.
|
CloseableResource<FileSystemMasterClient> |
acquireMasterClientResource()
Acquires a file system master client from the file system master client pool.
|
io.netty.channel.Channel |
acquireNettyChannel(WorkerNetAddress workerNetAddress)
Acquires a netty channel from the channel pools.
|
FileSystemContextReinitializer.ReinitBlockerResource |
blockReinit()
Acquires the resource to block reinitialization.
|
void |
close()
Closes all the resources associated with the context.
|
static FileSystemContext |
create()
Creates a
FileSystemContext with an empty subject, default config
and a null local block worker. |
static FileSystemContext |
create(AlluxioConfiguration conf)
Creates a
FileSystemContext with an empty subject
and a null local block worker. |
static FileSystemContext |
create(AlluxioConfiguration conf,
List<InetSocketAddress> masterAddresses)
Creates a
FileSystemContext with an empty subject
, a null local block worker, and the given master addresses. |
static FileSystemContext |
create(ClientContext clientContext) |
static FileSystemContext |
create(ClientContext ctx,
BlockWorker blockWorker) |
static FileSystemContext |
create(ClientContext ctx,
BlockWorker blockWorker,
List<InetSocketAddress> masterAddresses) |
static FileSystemContext |
create(Subject subject,
AlluxioConfiguration conf) |
static FileSystemContext |
create(Subject subject,
MasterInquireClient masterInquireClient,
AlluxioConfiguration alluxioConf)
This method is provided for testing, use the
create(alluxio.conf.AlluxioConfiguration, java.util.List<java.net.InetSocketAddress>) methods. |
List<BlockWorkerInfo> |
getAllWorkers()
Gets the worker information list.
|
protected ConcurrentHashMap<FileSystemContext.ClientPoolKey,BlockWorkerClientPool> |
getBlockWorkerClientPoolMap() |
List<BlockWorkerInfo> |
getCachedWorkers()
Gets the cached live worker information list.
|
List<BlockWorkerInfo> |
getCachedWorkers(FileSystemContext.GetWorkerListType type)
Gets the cached worker information list.
|
ClientContext |
getClientContext() |
AlluxioConfiguration |
getClusterConf() |
String |
getId() |
List<BlockWorkerInfo> |
getLiveWorkers()
Gets the live worker information list.
|
List<BlockWorkerInfo> |
getLostWorkers()
Gets the lost worker information list.
|
InetSocketAddress |
getMasterAddress() |
MasterClientContext |
getMasterClientContext() |
protected ConcurrentHashMap<SocketAddress,NettyChannelPool> |
getNettyChannelPools() |
WorkerNetAddress |
getNodeLocalWorker() |
Optional<BlockWorker> |
getProcessLocalWorker()
Acquires the internal block worker as a gateway for worker internal clients to communicate
with the local worker directly without going through external RPC frameworks.
|
boolean |
getUriValidationEnabled() |
boolean |
hasNodeLocalWorker() |
boolean |
hasProcessLocalWorker() |
protected void |
init(ClientContext clientContext,
MasterInquireClient masterInquireClient)
Initializes the context.
|
protected void |
initContext(ClientContext ctx,
MasterInquireClient masterInquireClient) |
protected void |
reCreateReinitialize(FileSystemContextReinitializer fileSystemContextReinitializer) |
void |
reinit(boolean updateClusterConf)
Closes the context, updates configuration from meta master, then re-initializes the context.
|
void |
releaseNettyChannel(WorkerNetAddress workerNetAddress,
io.netty.channel.Channel channel)
Releases a netty channel to the channel pools.
|
public static FileSystemContext.FileSystemContextFactory sFileSystemContextFactory
protected FileSystemContext(AlluxioConfiguration conf, @Nullable BlockWorker blockWorker, @Nullable List<InetSocketAddress> masterAddresses)
conf
- Alluxio configurationblockWorker
- block workerpublic static FileSystemContext create(AlluxioConfiguration conf, List<InetSocketAddress> masterAddresses)
FileSystemContext
with an empty subject
, a null local block worker, and the given master addresses.conf
- Alluxio configurationmasterAddresses
- the master addresses to use, this addresses will be
used across reinitializationpublic static FileSystemContext create()
FileSystemContext
with an empty subject, default config
and a null local block worker.public static FileSystemContext create(AlluxioConfiguration conf)
FileSystemContext
with an empty subject
and a null local block worker.conf
- Alluxio configurationpublic static FileSystemContext create(Subject subject, AlluxioConfiguration conf)
subject
- the parent subjectconf
- Alluxio configurationpublic static FileSystemContext create(ClientContext clientContext)
clientContext
- the ClientContext
containing the subject and configurationFileSystemContext
public static FileSystemContext create(ClientContext ctx, @Nullable BlockWorker blockWorker)
ctx
- client contextblockWorker
- block workerpublic static FileSystemContext create(ClientContext ctx, @Nullable BlockWorker blockWorker, @Nullable List<InetSocketAddress> masterAddresses)
ctx
- client contextblockWorker
- block workermasterAddresses
- is non-null then the addresses used to connect to the masterpublic static FileSystemContext create(Subject subject, MasterInquireClient masterInquireClient, AlluxioConfiguration alluxioConf)
create(alluxio.conf.AlluxioConfiguration, java.util.List<java.net.InetSocketAddress>)
methods. The
returned context object will not be cached automatically.subject
- the parent subjectmasterInquireClient
- the client to use for determining the master; note that if the
context is reset, this client will be replaced with a new masterInquireClient based on
the original configuration.alluxioConf
- Alluxio configurationprotected void init(ClientContext clientContext, MasterInquireClient masterInquireClient)
masterInquireClient
- the client to use for determining the masterprotected void reCreateReinitialize(@Nullable FileSystemContextReinitializer fileSystemContextReinitializer)
protected void initContext(ClientContext ctx, MasterInquireClient masterInquireClient)
public void close() throws IOException
FileSystem
associated with this FileSystemContext
.close
in interface Closeable
close
in interface AutoCloseable
IOException
public FileSystemContextReinitializer.ReinitBlockerResource blockReinit()
public void reinit(boolean updateClusterConf) throws UnavailableException, IOException
updateClusterConf
- whether cluster level configuration should be updatedUnavailableException
- when failed to load configuration from masterIOException
- when failed to close the contextpublic String getId()
public MasterClientContext getMasterClientContext()
MasterClientContext
backing this contextpublic ClientContext getClientContext()
ClientContext
backing this FileSystemContext
public AlluxioConfiguration getClusterConf()
FileSystemContext
public InetSocketAddress getMasterAddress() throws UnavailableException
UnavailableException
- if the master address cannot be determinedpublic boolean getUriValidationEnabled()
true
if URI validation is enabledpublic CloseableResource<FileSystemMasterClient> acquireMasterClientResource()
Closeable
.public CloseableResource<BlockMasterClient> acquireBlockMasterClientResource()
Closeable
.public io.netty.channel.Channel acquireNettyChannel(WorkerNetAddress workerNetAddress) throws IOException
workerNetAddress
- the network address of the channelIOException
protected ConcurrentHashMap<SocketAddress,NettyChannelPool> getNettyChannelPools()
public void releaseNettyChannel(WorkerNetAddress workerNetAddress, io.netty.channel.Channel channel)
workerNetAddress
- the address of the channelchannel
- the channel to releasepublic CloseableResource<BlockWorkerClient> acquireBlockWorkerClient(WorkerNetAddress workerNetAddress) throws IOException
workerNetAddress
- the network address of the channelIOException
public boolean hasProcessLocalWorker()
public Optional<BlockWorker> getProcessLocalWorker()
public boolean hasNodeLocalWorker() throws IOException
IOException
public WorkerNetAddress getNodeLocalWorker() throws IOException
IOException
public List<BlockWorkerInfo> getCachedWorkers() throws IOException
getLiveWorkers()
()} instead.IOException
public List<BlockWorkerInfo> getCachedWorkers(FileSystemContext.GetWorkerListType type) throws IOException
getAllWorkers()
, getLiveWorkers()
()}
or getLostWorkers()
()} instead.type
- get worker list typeIOException
public List<BlockWorkerInfo> getLiveWorkers() throws IOException
getCachedWorkers(GetWorkerListType)
.
Used when more up-to-date data is needed.IOException
public List<BlockWorkerInfo> getLostWorkers() throws IOException
getCachedWorkers(GetWorkerListType)
.
Used when more up-to-date data is needed.IOException
public List<BlockWorkerInfo> getAllWorkers() throws IOException
getCachedWorkers(GetWorkerListType)
.
Used when more up-to-date data is needed.IOException
protected ConcurrentHashMap<FileSystemContext.ClientPoolKey,BlockWorkerClientPool> getBlockWorkerClientPoolMap()
Copyright © 2023. All Rights Reserved.