@ThreadSafe public final 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) 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 | Method and Description |
|---|---|
alluxio.resource.CloseableResource<BlockMasterClient> |
acquireBlockMasterClientResource()
Acquires a block master client resource from the block master client pool.
|
BlockWorkerClient |
acquireBlockWorkerClient(alluxio.wire.WorkerNetAddress workerNetAddress)
Acquires a block worker client from the client pools.
|
alluxio.resource.CloseableResource<FileSystemMasterClient> |
acquireMasterClientResource()
Acquires a file system master client from the file system master client pool.
|
FileSystemContextReinitializer.ReinitBlockerResource |
blockReinit()
Acquires the resource to block reinitialization.
|
void |
close()
Closes all the resources associated with the context.
|
static FileSystemContext |
create(alluxio.conf.AlluxioConfiguration conf)
Creates a
FileSystemContext with a null subject. |
static FileSystemContext |
create(alluxio.ClientContext clientContext) |
static FileSystemContext |
create(Subject subject,
alluxio.conf.AlluxioConfiguration conf) |
static FileSystemContext |
create(Subject subject,
alluxio.master.MasterInquireClient masterInquireClient,
alluxio.conf.AlluxioConfiguration alluxioConf)
This method is provided for testing, use the
create(alluxio.conf.AlluxioConfiguration) methods. |
alluxio.ClientContext |
getClientContext() |
alluxio.conf.AlluxioConfiguration |
getClusterConf() |
String |
getId() |
alluxio.wire.WorkerNetAddress |
getLocalWorker() |
InetSocketAddress |
getMasterAddress() |
alluxio.master.MasterClientContext |
getMasterClientContext() |
alluxio.conf.AlluxioConfiguration |
getPathConf(alluxio.AlluxioURI path)
The path level configuration is a
SpecificPathConfiguration. |
boolean |
hasLocalWorker() |
void |
reinit(boolean updateClusterConf,
boolean updatePathConf)
Closes the context, updates configuration from meta master, then re-initializes the context.
|
void |
releaseBlockWorkerClient(alluxio.wire.WorkerNetAddress workerNetAddress,
BlockWorkerClient client)
Releases a block worker client to the client pools.
|
public static FileSystemContext create(alluxio.conf.AlluxioConfiguration conf)
FileSystemContext with a null subject.conf - Alluxio configurationpublic static FileSystemContext create(@Nullable Subject subject, @Nullable alluxio.conf.AlluxioConfiguration conf)
subject - the parent subject, set to null if not presentconf - Alluxio configurationpublic static FileSystemContext create(alluxio.ClientContext clientContext)
clientContext - the ClientContext containing the subject and configurationFileSystemContextpublic static FileSystemContext create(Subject subject, alluxio.master.MasterInquireClient masterInquireClient, alluxio.conf.AlluxioConfiguration alluxioConf)
create(alluxio.conf.AlluxioConfiguration) methods. The
returned context object will not be cached automatically.subject - the parent subject, set to null if not presentmasterInquireClient - 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 configurationpublic void close()
throws IOException
FileSystem associated with this FileSystemContext.close in interface Closeableclose in interface AutoCloseableIOExceptionpublic FileSystemContextReinitializer.ReinitBlockerResource blockReinit()
public void reinit(boolean updateClusterConf,
boolean updatePathConf)
throws alluxio.exception.status.UnavailableException,
IOException
updateClusterConf - whether cluster level configuration should be updatedupdatePathConf - whether path level configuration should be updatedalluxio.exception.status.UnavailableException - when failed to load configuration from masterIOException - when failed to close the contextpublic String getId()
public alluxio.master.MasterClientContext getMasterClientContext()
MasterClientContext backing this contextpublic alluxio.ClientContext getClientContext()
ClientContext backing this FileSystemContextpublic alluxio.conf.AlluxioConfiguration getClusterConf()
FileSystemContextpublic alluxio.conf.AlluxioConfiguration getPathConf(alluxio.AlluxioURI path)
SpecificPathConfiguration.
If path level configuration has never been loaded from meta master yet, it will be loaded.path - the path to get the configuration forpublic InetSocketAddress getMasterAddress() throws alluxio.exception.status.UnavailableException
alluxio.exception.status.UnavailableException - if the master address cannot be determinedpublic alluxio.resource.CloseableResource<FileSystemMasterClient> acquireMasterClientResource()
Closeable.public alluxio.resource.CloseableResource<BlockMasterClient> acquireBlockMasterClientResource()
Closeable.public BlockWorkerClient acquireBlockWorkerClient(alluxio.wire.WorkerNetAddress workerNetAddress) throws IOException
workerNetAddress - the network address of the channelIOExceptionpublic void releaseBlockWorkerClient(alluxio.wire.WorkerNetAddress workerNetAddress,
BlockWorkerClient client)
workerNetAddress - the address of the channelclient - the client to releasepublic boolean hasLocalWorker()
throws IOException
IOExceptionpublic alluxio.wire.WorkerNetAddress getLocalWorker()
throws IOException
IOExceptionCopyright © 2024. All Rights Reserved.