-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
HADOOP-18807. Close child file systems in ViewFileSystem when cache is disabled. #5847
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1926,12 +1926,46 @@ enum RenameStrategy { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
SAME_FILESYSTEM_ACROSS_MOUNTPOINT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private void closeChildFileSystems(FileSystem fs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (fs != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
FileSystem[] childFs = fs.getChildFileSystems(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for (FileSystem child : childFs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
steveloughran marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (child != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String disableCacheName = String.format("fs.%s.impl.disable.cache", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
child.getUri().getScheme()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (config.getBoolean(disableCacheName, false)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. should we check the child config rather than the viewfs one? would they ever be different? 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. Child file system always use their parent's config. We can take a look at line 346 and line 350 of the code below: Lines 335 to 361 in c44823d
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. @steveloughran means that we should only check viewfs config, rather than every child config here. As you mentioned code segment, it also shows that check viewfs only is enough IMO. 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. works for me |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
child.close(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} catch (IOException e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LOG.info("Fail closing ViewFileSystem's child filesystem " + fs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public void close() throws IOException { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
super.close(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (enableInnerCache && cache != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cache.closeAll(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cache.clear(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!enableInnerCache) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for (InodeTree.MountPoint<FileSystem> mountPoint : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fsState.getMountPoints()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
FileSystem targetFs = mountPoint.target.getTargetFileSystemForClose(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. how about to invoke getTargetFileSystem directly? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
closeChildFileSystems(targetFs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (fsState.isRootInternalDir() && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fsState.getRootFallbackLink() != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
closeChildFileSystems( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fsState.getRootFallbackLink().getTargetFileSystem()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* 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.viewfs; | ||
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. if this test uses file:// as the childen fs then it could be added in hadoop common, which is where viewfs is implemented. Doing that means that yetus will run the test on every change to hadoop-common, which is needed to stop regressions in viewfs only being found later 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. Sorry I don't fully understand what you mean. Do you suggest moving this test file to hadoop-common? 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. yes, and to use the localfs. yetus doesnt run the hadoop-hdfs tests when a patch just goes near hadoop-common, so the test needs to get there. 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. When the cache is disabled, 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.
Hi @steveloughran this change can trigger hadoop-hdfs unit test, but it could not ensure to be launched later actually. I am also concerned it could not cover this case if use local FS only here as @zhangshuyan0 mentioned above 'LocalFileSystem#close() didn't do anything special'. Any suggestions? Thanks. 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. oh, ok. |
||
|
||
import java.io.IOException; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
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. check import ordering |
||
import org.apache.hadoop.fs.FileSystem; | ||
import org.apache.hadoop.fs.FsConstants; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.test.AbstractHadoopTestBase; | ||
import org.junit.Test; | ||
|
||
import static org.apache.hadoop.test.LambdaTestUtils.intercept; | ||
|
||
public class TestViewFileSystemClose extends AbstractHadoopTestBase { | ||
|
||
/** | ||
* Verify that all child file systems of a ViewFileSystem will be shut down | ||
* when the cache is disabled. | ||
* @throws IOException | ||
*/ | ||
@Test | ||
public void testFileSystemLeak() throws Exception { | ||
|
||
Configuration conf = new Configuration(); | ||
conf.set("fs.viewfs.impl", ViewFileSystem.class.getName()); | ||
conf.setBoolean("fs.viewfs.enable.inner.cache", false); | ||
conf.setBoolean("fs.viewfs.impl.disable.cache", true); | ||
conf.setBoolean("fs.hdfs.impl.disable.cache", true); | ||
|
||
String rootPath = "hdfs://localhost/tmp"; | ||
ConfigUtil.addLink(conf, "/data", new Path(rootPath, "data").toUri()); | ||
ViewFileSystem viewFs = | ||
(ViewFileSystem) FileSystem.get(FsConstants.VIEWFS_URI, conf); | ||
|
||
FileSystem[] children = viewFs.getChildFileSystems(); | ||
viewFs.close(); | ||
FileSystem.closeAll(); | ||
for (FileSystem fs : children) { | ||
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. use LambdaTestUtils.intercept() here |
||
intercept(IOException.class, "Filesystem closed", | ||
"Expect Filesystem closed IOException", | ||
() -> fs.create(new Path(rootPath, "neverSuccess"))); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what difference between this method and
getTargetFileSystem
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some target FileSystem may not have be initialized.
getTargetFileSystem
initializes all target FileSystems (line1039 below). It's costly and unnecessary when we just try to close them.hadoop/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java
Lines 1036 to 1039 in c44823d