-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HDFS-16791. Add getEnclosingRoot() API to filesystem interface and implementations #6198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1370,6 +1370,20 @@ public boolean hasPathCapability(Path path, String capability) | |
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Path getEnclosingRoot(Path path) throws IOException { | ||
| InodeTree.ResolveResult<FileSystem> res; | ||
| try { | ||
| res = fsState.resolve(getUriPath(path), true); | ||
| } catch (FileNotFoundException ex) { | ||
| throw new NotInMountpointException(path, String.format("getEnclosingRoot - %s", ex.getMessage())); | ||
| } | ||
| Path mountPath = new Path(res.resolvedPath); | ||
| Path enclosingPath = res.targetFileSystem.getEnclosingRoot(new Path(getUriPath(path))); | ||
| return fixRelativePart(this.makeQualified(enclosingPath.depth() > mountPath.depth() | ||
| ? enclosingPath : mountPath)); | ||
| } | ||
|
|
||
| /** | ||
| * An instance of this class represents an internal dir of the viewFs | ||
| * that is internal dir of the mount table. | ||
|
|
@@ -1919,6 +1933,21 @@ public Collection<? extends BlockStoragePolicySpi> getAllStoragePolicies() | |
| } | ||
| return allPolicies; | ||
| } | ||
|
|
||
| @Override | ||
| public Path getEnclosingRoot(Path path) throws IOException { | ||
| InodeTree.ResolveResult<FileSystem> res; | ||
| try { | ||
| res = fsState.resolve((path.toString()), true); | ||
| } catch (FileNotFoundException ex) { | ||
| throw new NotInMountpointException(path, String.format("getEnclosingRoot - %s", ex.getMessage())); | ||
|
||
| } | ||
| Path fullPath = new Path(res.resolvedPath); | ||
| Path enclosingPath = res.targetFileSystem.getEnclosingRoot(path); | ||
| return enclosingPath.depth() > fullPath.depth() | ||
| ? enclosingPath | ||
| : fullPath; | ||
| } | ||
| } | ||
|
|
||
| enum RenameStrategy { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -601,7 +601,32 @@ on the filesystem. | |
|
|
||
| 1. The outcome of this operation MUST be identical to the value of | ||
| `getFileStatus(P).getBlockSize()`. | ||
| 1. By inference, it MUST be > 0 for any file of length > 0. | ||
| 2. By inference, it MUST be > 0 for any file of length > 0. | ||
|
|
||
| ### `Path getEnclosingRoot(Path p)` | ||
|
|
||
| This method is used to find a root directory for a path given. This is useful for creating | ||
| staging and temp directories in the same enclosing root directory. There are constraints around how | ||
| renames are allowed to atomically occur (ex. across hdfs volumes or across encryption zones). | ||
|
|
||
| For any two paths p1 and p2 that do not have the same enclosing root, `rename(p1, p2)` is expected to fail or will not | ||
mccormickt12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| be atomic. | ||
|
|
||
| The following statement is always true: | ||
| `getEnclosingRoot(p) == getEnclosingRoot(getEnclosingRoot(p))` | ||
|
|
||
| #### Preconditions | ||
|
|
||
| The path does not have to exist, but the path does need to be valid and reconcilable by the filesystem | ||
| * if a linkfallback is used all paths are reconcilable | ||
| * if a linkfallback is not used there must be a mount point covering the path | ||
|
|
||
|
|
||
| #### Postconditions | ||
|
|
||
| * The path returned will not be null, if there is no deeper enclosing root, the root path ("/") will be returned. | ||
| * The path returned is a directory | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add in the python-ish spec path in ancestors(FS, p) or path == p
isDir(FS, p)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added, but tbh, don't totally understand the intent here, so i didn't correctly label it, i just copied it in as is.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the python is trying to define the rules, the english is a wrapper around it. So think about how you'd convert those bullet points in terms of assertions you'd have before and after an implementation |
||
|
|
||
|
|
||
| ## <a name="state_changing_operations"></a> State Changing Operations | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.hadoop.fs; | ||
|
|
||
| import java.io.IOException; | ||
| import java.security.PrivilegedExceptionAction; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.security.UserGroupInformation; | ||
| import org.apache.hadoop.test.HadoopTestBase; | ||
| import org.junit.Test; | ||
|
|
||
| public class TestGetEnclosingRoot extends HadoopTestBase { | ||
| @Test | ||
| public void testEnclosingRootEquivalence() throws IOException { | ||
| FileSystem fs = getFileSystem(); | ||
| Path root = path("/"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following up with the comments here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I definitely could be wrong, but my current understanding is these are generic tests, in which case, I don't think there are more interesting tests. The functionality is for filesystems with mount points (ViewFileSystem and RBF) and encryption zones. There are fancier tests in |
||
| Path foobar = path("/foo/bar"); | ||
|
|
||
| assertEquals(root, fs.getEnclosingRoot(root)); | ||
| assertEquals(root, fs.getEnclosingRoot(foobar)); | ||
| assertEquals(root, fs.getEnclosingRoot(fs.getEnclosingRoot(foobar))); | ||
| assertEquals(fs.getEnclosingRoot(root), fs.getEnclosingRoot(foobar)); | ||
|
|
||
| assertEquals(root, fs.getEnclosingRoot(path(foobar.toString()))); | ||
| assertEquals(root, fs.getEnclosingRoot(fs.getEnclosingRoot(path(foobar.toString())))); | ||
| assertEquals(fs.getEnclosingRoot(root), fs.getEnclosingRoot(path(foobar.toString()))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEnclosingRootPathExists() throws Exception { | ||
| FileSystem fs = getFileSystem(); | ||
| Path root = path("/"); | ||
| Path foobar = path("/foo/bar"); | ||
| fs.mkdirs(foobar); | ||
|
|
||
| assertEquals(root, fs.getEnclosingRoot(foobar)); | ||
| assertEquals(root, fs.getEnclosingRoot(path(foobar.toString()))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEnclosingRootPathDNE() throws Exception { | ||
| FileSystem fs = getFileSystem(); | ||
| Path foobar = path("/foo/bar"); | ||
| Path root = path("/"); | ||
|
|
||
| assertEquals(root, fs.getEnclosingRoot(foobar)); | ||
| assertEquals(root, fs.getEnclosingRoot(path(foobar.toString()))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEnclosingRootWrapped() throws Exception { | ||
| FileSystem fs = getFileSystem(); | ||
| Path root = path("/"); | ||
|
|
||
| assertEquals(root, fs.getEnclosingRoot(new Path("/foo/bar"))); | ||
|
|
||
| UserGroupInformation ugi = UserGroupInformation.createRemoteUser("foo"); | ||
| Path p = ugi.doAs((PrivilegedExceptionAction<Path>) () -> { | ||
| FileSystem wFs = getFileSystem(); | ||
| return wFs.getEnclosingRoot(new Path("/foo/bar")); | ||
| }); | ||
| assertEquals(root, p); | ||
| } | ||
|
|
||
| private FileSystem getFileSystem() throws IOException { | ||
| return FileSystem.get(new Configuration()); | ||
| } | ||
|
|
||
| /** | ||
| * Create a path under the test path provided by | ||
| * the FS contract. | ||
| * @param filepath path string in | ||
| * @return a path qualified by the test filesystem | ||
| * @throws IOException IO problems | ||
| */ | ||
| private Path path(String filepath) throws IOException { | ||
| return getFileSystem().makeQualified( | ||
| new Path(filepath)); | ||
| }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.hadoop.fs.contract; | ||
|
|
||
| import java.io.IOException; | ||
| import java.security.PrivilegedExceptionAction; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.security.UserGroupInformation; | ||
| import org.junit.Test; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
|
|
||
| public abstract class AbstractContractGetEnclosingRoot extends AbstractFSContractTestBase { | ||
| private static final Logger LOG = LoggerFactory.getLogger(AbstractContractGetEnclosingRoot.class); | ||
|
|
||
| @Test | ||
| public void testEnclosingRootEquivalence() throws IOException { | ||
| FileSystem fs = getFileSystem(); | ||
| Path root = path("/"); | ||
| Path foobar = path("/foo/bar"); | ||
mccormickt12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| assertEquals(root, fs.getEnclosingRoot(foobar)); | ||
mccormickt12 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assertEquals(root, fs.getEnclosingRoot(fs.getEnclosingRoot(foobar))); | ||
| assertEquals(fs.getEnclosingRoot(root), fs.getEnclosingRoot(foobar)); | ||
|
|
||
| assertEquals(root, fs.getEnclosingRoot(path(foobar.toString()))); | ||
| assertEquals(root, fs.getEnclosingRoot(fs.getEnclosingRoot(path(foobar.toString())))); | ||
| assertEquals(fs.getEnclosingRoot(root), fs.getEnclosingRoot(path(foobar.toString()))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEnclosingRootPathExists() throws Exception { | ||
| FileSystem fs = getFileSystem(); | ||
| Path root = path("/"); | ||
| Path foobar = path("/foo/bar"); | ||
| fs.mkdirs(foobar); | ||
|
|
||
| assertEquals(root, fs.getEnclosingRoot(foobar)); | ||
| assertEquals(root, fs.getEnclosingRoot(path(foobar.toString()))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEnclosingRootPathDNE() throws Exception { | ||
| FileSystem fs = getFileSystem(); | ||
| Path foobar = path("/foo/bar"); | ||
| Path root = path("/"); | ||
|
|
||
| assertEquals(root, fs.getEnclosingRoot(foobar)); | ||
| assertEquals(root, fs.getEnclosingRoot(path(foobar.toString()))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEnclosingRootWrapped() throws Exception { | ||
| FileSystem fs = getFileSystem(); | ||
| Path root = path("/"); | ||
|
|
||
| assertEquals(root, fs.getEnclosingRoot(new Path("/foo/bar"))); | ||
|
|
||
| UserGroupInformation ugi = UserGroupInformation.createRemoteUser("foo"); | ||
| Path p = ugi.doAs((PrivilegedExceptionAction<Path>) () -> { | ||
| FileSystem wFs = getContract().getTestFileSystem(); | ||
| return wFs.getEnclosingRoot(new Path("/foo/bar")); | ||
| }); | ||
| assertEquals(root, p); | ||
| } | ||
|
|
||
| /** | ||
| * Create a path under the test path provided by | ||
| * the FS contract. | ||
| * @param filepath path string in | ||
| * @return a path qualified by the test filesystem | ||
| * @throws IOException IO problems | ||
| */ | ||
| protected Path path(String filepath) throws IOException { | ||
| return getFileSystem().makeQualified( | ||
| new Path(getContract().getTestPath(), filepath)); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.