/** * Returns a sequence of Alluxio paths for a specified path, starting from the path component at * a specific index, to the specified path. * * @param alluxioUri the Alluxio path to get the nested paths for * @param startComponentIndex the index to the starting path component, * root directory has index 0 * @return a list of nested paths from the starting component to the given path */ private List<AlluxioURI> getNestedPaths(AlluxioURI alluxioUri, int startComponentIndex) { try { String[] fullComponents = PathUtils.getPathComponents(alluxioUri.getPath()); String[] baseComponents = Arrays.copyOfRange(fullComponents, 0, startComponentIndex); AlluxioURI uri = new AlluxioURI( PathUtils.concatPath(AlluxioURI.SEPARATOR, baseComponents)); List<AlluxioURI> components = new ArrayList<>(fullComponents.length - startComponentIndex); for (int i = startComponentIndex; i < fullComponents.length; i++) { uri = uri.joinUnsafe(fullComponents[i]); components.add(uri); } return components; } catch (InvalidPathException e) { return Collections.emptyList(); } }
private AlluxioURI reverseResolve(AlluxioURI mountPoint, AlluxioURI ufsUriMountPoint, AlluxioURI ufsUri) throws InvalidPathException { String relativePath = PathUtils.subtractPaths( PathUtils.normalizePath(ufsUri.getPath(), AlluxioURI.SEPARATOR), PathUtils.normalizePath(ufsUriMountPoint.getPath(), AlluxioURI.SEPARATOR)); if (relativePath.isEmpty()) { return mountPoint; } else { return mountPoint.joinUnsafe(relativePath); } }
/** * Efficient version of {@link #lockChild(Inode, LockPattern)} for when the child path * components are already known. * * @param child the child inode * @param lockPattern the lock pattern * @param childComponentsHint path components for the new path * @return the new locked path */ public LockedInodePath lockChild(Inode child, LockPattern lockPattern, String[] childComponentsHint) throws InvalidPathException { LockedInodePath path = new LockedInodePath(mUri.joinUnsafe(child.getName()), this, childComponentsHint, lockPattern); path.traverseOrClose(); return path; }
private Map<AlluxioURI, UfsStatus> populateStatusCache(AlluxioURI path, DescendantType syncDescendantType) { Map<AlluxioURI, UfsStatus> statusCache = new HashMap<>(); try { MountTable.Resolution resolution = mMountTable.resolve(path); AlluxioURI ufsUri = resolution.getUri(); try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) { UnderFileSystem ufs = ufsResource.get(); ListOptions listOptions = ListOptions.defaults(); // statusCache stores uri to ufsstatus mapping that is used to construct fingerprint listOptions.setRecursive(syncDescendantType == DescendantType.ALL); try { UfsStatus[] children = ufs.listStatus(ufsUri.toString(), listOptions); if (children != null) { for (UfsStatus childStatus : children) { statusCache.put(path.joinUnsafe(childStatus.getName()), childStatus); } } } catch (Exception e) { LOG.debug("ListStatus failed as an preparation step for syncMetadata {}", path, e); } return statusCache; } } catch (InvalidPathException e) { return statusCache; } }
dstPath = dstPath.joinUnsafe(srcPath.getName()); } else { LOG.warn("rename failed: {}", e.getMessage());
@Test public void joinUnsafe() { assertEquals(new AlluxioURI("/a"), new AlluxioURI("/").joinUnsafe("a")); assertEquals(new AlluxioURI("/a/b"), new AlluxioURI("/a").joinUnsafe("b")); assertEquals(new AlluxioURI("a/b"), new AlluxioURI("a").joinUnsafe("b")); assertEquals(new AlluxioURI("a/b.txt"), new AlluxioURI("a").joinUnsafe("/b.txt")); assertEquals(new AlluxioURI("alluxio:/a/b.txt"), new AlluxioURI("alluxio:/a").joinUnsafe("/b.txt")); assertEquals(new AlluxioURI("C:\\\\a\\b"), new AlluxioURI("C:\\\\a").joinUnsafe("\\b")); assertEquals(new AlluxioURI("/a/b"), new AlluxioURI("/a").joinUnsafe("///b///")); final String pathWithSpecialChar = "����,��b����$o����[| =B����"; assertEquals(new AlluxioURI("/" + pathWithSpecialChar), new AlluxioURI("/").joinUnsafe(pathWithSpecialChar)); final String pathWithSpecialCharAndColon = "����,��b����$o����[| =B��:��"; assertEquals(new AlluxioURI("/" + pathWithSpecialCharAndColon), new AlluxioURI("/").joinUnsafe(pathWithSpecialCharAndColon)); // The following joins are not "safe", because the new path component requires normalization. assertNotEquals(new AlluxioURI("/a/c"), new AlluxioURI("/a").joinUnsafe("b/../c")); assertNotEquals(new AlluxioURI("a/b.txt"), new AlluxioURI("a").joinUnsafe("/c/../b.txt")); assertNotEquals(new AlluxioURI("alluxio:/a/b.txt"), new AlluxioURI("alluxio:/a/c.txt").joinUnsafe("/../b.txt")); }
inodePath.getUri().joinUnsafe(inodeEntry.getKey()), LockPattern.WRITE_EDGE)) {
inodePath.getUri().joinUnsafe(childStatus.getName()), LockPattern.READ)) { LoadMetadataContext loadMetadataContext = LoadMetadataContext .defaults(LoadMetadataPOptions.newBuilder()
/** * Tests the {@link AlluxioURI#join(String)} and {@link AlluxioURI#join(AlluxioURI)} methods. */ @Test public void joinTests() { assertEquals(new AlluxioURI("/a"), new AlluxioURI("/").join("a")); assertEquals(new AlluxioURI("/a"), new AlluxioURI("/").join(new AlluxioURI("a"))); assertEquals(new AlluxioURI("/a/b"), new AlluxioURI("/a").join(new AlluxioURI("b"))); assertEquals(new AlluxioURI("a/b"), new AlluxioURI("a").join(new AlluxioURI("b"))); assertEquals(new AlluxioURI("/a/c"), new AlluxioURI("/a").join(new AlluxioURI("b/../c"))); assertEquals(new AlluxioURI("a/b.txt"), new AlluxioURI("a").join(new AlluxioURI("/b.txt"))); assertEquals(new AlluxioURI("a/b.txt"), new AlluxioURI("a").join(new AlluxioURI("/c/../b.txt"))); assertEquals(new AlluxioURI("alluxio:/a/b.txt"), new AlluxioURI("alluxio:/a").join("/b.txt")); assertEquals(new AlluxioURI("alluxio:/a/b.txt"), new AlluxioURI("alluxio:/a/c.txt").join(new AlluxioURI("/../b.txt"))); assertEquals(new AlluxioURI("C:\\\\a\\b"), new AlluxioURI("C:\\\\a").join(new AlluxioURI("\\b"))); assertEquals(new AlluxioURI("/a/b"), new AlluxioURI("/a").joinUnsafe("///b///")); final String pathWithSpecialChar = "����,��b����$o����[| =B����"; assertEquals(new AlluxioURI("/" + pathWithSpecialChar), new AlluxioURI("/").join(pathWithSpecialChar)); final String pathWithSpecialCharAndColon = "����,��b����$o����[| =B��:��"; assertEquals(new AlluxioURI("/" + pathWithSpecialCharAndColon), new AlluxioURI("/").join(pathWithSpecialCharAndColon)); }