use of alluxio.master.file.meta.MountTable in project alluxio by Alluxio.
the class UfsStatusCacheTest method spyUfs.
/**
* Recreates the mount table with the local UFS as a spy'd mockito object.
*/
private void spyUfs() {
mUfs = Mockito.spy(mUfs);
MountInfo rootMountInfo = new MountInfo(new AlluxioURI(MountTable.ROOT), new AlluxioURI(mUfsUri), IdUtils.ROOT_MOUNT_ID, MountPOptions.newBuilder().setReadOnly(false).setShared(false).build());
MasterUfsManager manager = new MasterUfsManager();
// add root mount
manager.getRoot();
manager.mUnderFileSystemMap.put(new AbstractUfsManager.Key(new AlluxioURI("/"), null), mUfs);
mMountTable = new MountTable(manager, rootMountInfo);
}
use of alluxio.master.file.meta.MountTable in project alluxio by Alluxio.
the class UfsStatusCache method fetchStatusIfAbsent.
/**
* Attempts to return a status from the cache. If it doesn't exist, reaches to the UFS for it.
*
* @param path the path the retrieve
* @param mountTable the Alluxio mount table
* @return The corresponding {@link UfsStatus} or {@code null} if there is none stored
*/
@Nullable
public UfsStatus fetchStatusIfAbsent(AlluxioURI path, MountTable mountTable) throws InvalidPathException, IOException {
UfsStatus status;
try {
status = getStatus(path);
} catch (FileNotFoundException e) {
return null;
}
if (status != null) {
return status;
}
MountTable.Resolution resolution = mountTable.resolve(path);
AlluxioURI ufsUri = resolution.getUri();
try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
UnderFileSystem ufs = ufsResource.get();
UfsStatus ufsStatus = ufs.getStatus(ufsUri.toString());
if (ufsStatus == null) {
mAbsentCache.addSinglePath(path);
return null;
}
ufsStatus.setName(path.getName());
addStatus(path, ufsStatus);
return ufsStatus;
} catch (FileNotFoundException e) {
// If the ufs can not find the file, we explicitly mark it absent so we do not recheck it
mAbsentCache.addSinglePath(path);
} catch (IllegalArgumentException | IOException e) {
LogUtils.warnWithException(LOG, "Failed to fetch status for {}", path, e);
}
return null;
}
use of alluxio.master.file.meta.MountTable in project alluxio by Alluxio.
the class UfsStatusCache method getChildrenIfAbsent.
/**
* Retrieves the child UFS statuses for a given path and stores them in the cache.
*
* This method first checks if the children have already been retrieved, and if not, then
* retrieves them.
*
* @param path the path to get the children for
* @param mountTable the Alluxio mount table
* @return the child statuses that were stored in the cache, or null if the UFS couldn't list the
* statuses
* @throws InvalidPathException when the table can't resolve the mount for the given URI
*/
@Nullable
Collection<UfsStatus> getChildrenIfAbsent(AlluxioURI path, MountTable mountTable) throws InvalidPathException {
Collection<UfsStatus> children = getChildren(path);
if (children != null) {
return children;
}
if (mAbsentCache.isAbsentSince(path, mCacheValidTime)) {
return null;
}
MountTable.Resolution resolution = mountTable.resolve(path);
AlluxioURI ufsUri = resolution.getUri();
try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
UnderFileSystem ufs = ufsResource.get();
UfsStatus[] statuses = ufs.listStatus(ufsUri.toString());
if (statuses == null) {
mAbsentCache.addSinglePath(path);
return null;
}
children = Arrays.asList(statuses);
addChildren(path, children);
} catch (IllegalArgumentException | IOException e) {
LOG.debug("Failed to add status to cache {}", path, e);
}
return children;
}
use of alluxio.master.file.meta.MountTable in project alluxio by Alluxio.
the class UfsConfigurationJournalTest method testOptionsPersisted.
@Test
public void testOptionsPersisted() throws Exception {
// Set ufs specific options and other mount flags
AlluxioURI mountPoint = new AlluxioURI("/mnt");
ImmutableMap<String, String> options = ImmutableMap.of("k1", "v1", "k2", "v2");
mFs.mount(mountPoint, new AlluxioURI(LOCAL_UFS_PATH), MountPOptions.newBuilder().putAllProperties(options).setReadOnly(true).setShared(true).build());
// Get mount id
MountTable mountTable = Whitebox.getInternalState(mLocalAlluxioClusterResource.get().getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class), "mMountTable");
long mountId = mountTable.resolve(mountPoint).getMountId();
// Restart masters
mLocalAlluxioClusterResource.get().restartMasters();
// Checks all options and flags are persisted after restart
UfsManager ufsManager = Whitebox.getInternalState(mLocalAlluxioClusterResource.get().getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class), "mUfsManager");
try (CloseableResource<UnderFileSystem> resource = ufsManager.get(mountId).acquireUfsResource()) {
UnderFileSystemConfiguration ufsConf = Whitebox.getInternalState(resource.get(), "mConf");
assertEquals(ufsConf.getMountSpecificConf().size(), options.size());
for (Map.Entry<String, String> entry : options.entrySet()) {
assertEquals(entry.getValue(), ufsConf.getMountSpecificConf().get(entry.getKey()));
}
assertTrue(ufsConf.isReadOnly());
assertTrue(ufsConf.isShared());
}
}
Aggregations