-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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 all commits
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 |
---|---|---|
|
@@ -601,7 +601,40 @@ 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. | ||
|
||
For object stores, even with the same enclosing root, there is no guarantee file or directory rename is atomic | ||
|
||
The following statement is always true: | ||
`getEnclosingRoot(p) == getEnclosingRoot(getEnclosingRoot(p))` | ||
|
||
|
||
```python | ||
path in ancestors(FS, p) or path == p: | ||
isDir(FS, 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 | ||
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) 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. 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("/"); | ||
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. 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,103 @@ | ||
/** | ||
* 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("Ensure getEnclosingRoot on the root directory returns the root directory", | ||
root, fs.getEnclosingRoot(foobar)); | ||
assertEquals("Ensure getEnclosingRoot called on itself returns the root directory", | ||
root, fs.getEnclosingRoot(fs.getEnclosingRoot(foobar))); | ||
assertEquals( | ||
"Ensure getEnclosingRoot for different paths in the same enclosing root " | ||
+ "returns the same path", | ||
fs.getEnclosingRoot(root), fs.getEnclosingRoot(foobar)); | ||
assertEquals("Ensure getEnclosingRoot on a path returns the root directory", | ||
root, fs.getEnclosingRoot(methodPath())); | ||
assertEquals("Ensure getEnclosingRoot called on itself on a path returns the root directory", | ||
root, fs.getEnclosingRoot(fs.getEnclosingRoot(methodPath()))); | ||
assertEquals( | ||
"Ensure getEnclosingRoot for different paths in the same enclosing root " | ||
+ "returns the same path", | ||
fs.getEnclosingRoot(root), | ||
fs.getEnclosingRoot(methodPath())); | ||
} | ||
|
||
|
||
@Test | ||
public void testEnclosingRootPathExists() throws Exception { | ||
FileSystem fs = getFileSystem(); | ||
Path root = path("/"); | ||
Path foobar = methodPath(); | ||
fs.mkdirs(foobar); | ||
|
||
assertEquals( | ||
"Ensure getEnclosingRoot returns the root directory when the root directory exists", | ||
root, fs.getEnclosingRoot(foobar)); | ||
assertEquals("Ensure getEnclosingRoot returns the root directory when the directory exists", | ||
root, fs.getEnclosingRoot(foobar)); | ||
} | ||
|
||
@Test | ||
public void testEnclosingRootPathDNE() throws Exception { | ||
FileSystem fs = getFileSystem(); | ||
Path foobar = path("/foo/bar"); | ||
Path root = path("/"); | ||
|
||
// . | ||
assertEquals( | ||
"Ensure getEnclosingRoot returns the root directory even when the path does not exist", | ||
root, fs.getEnclosingRoot(foobar)); | ||
assertEquals( | ||
"Ensure getEnclosingRoot returns the root directory even when the path does not exist", | ||
root, fs.getEnclosingRoot(methodPath())); | ||
} | ||
|
||
@Test | ||
public void testEnclosingRootWrapped() throws Exception { | ||
FileSystem fs = getFileSystem(); | ||
Path root = path("/"); | ||
|
||
assertEquals("Ensure getEnclosingRoot returns the root directory when the directory exists", | ||
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("Ensure getEnclosingRoot works correctly within a wrapped FileSystem", root, p); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.