-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-16255. Add ChecksumFs.rename(path, path, boolean) to rename crc file as well when FileContext.rename(path, path, options) is called. #1388
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 3 commits
b95c366
06df471
d992c95
5a45551
1098295
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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * 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.util; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Defines a functional interface having two inputs which throws IOException. | ||
| */ | ||
| @FunctionalInterface | ||
| public interface CheckedBiFunction<LEFT, RIGHT, THROWABLE extends IOException> { | ||
|
||
| void apply(LEFT left, RIGHT right) throws THROWABLE; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| /** | ||
| * 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.util.EnumSet; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.local.LocalFs; | ||
| import org.apache.hadoop.fs.permission.FsPermission; | ||
| import static org.apache.hadoop.fs.CreateFlag.*; | ||
| import org.apache.hadoop.test.GenericTestUtils; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import static org.junit.Assert.*; | ||
steveloughran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * This class tests the functionality of ChecksumFs. | ||
| */ | ||
| public class TestChecksumFs { | ||
steveloughran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private Configuration conf; | ||
| private Path testRootDirPath; | ||
| private FileContext fc; | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| conf = getTestConfiguration(); | ||
| fc = FileContext.getFileContext(conf); | ||
| testRootDirPath = new Path(GenericTestUtils.getRandomizedTestDir() | ||
| .getAbsolutePath()); | ||
| mkdirs(testRootDirPath); | ||
| } | ||
|
|
||
| public void tearDown() throws Exception { | ||
steveloughran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fc.delete(testRootDirPath, true); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRenameFileToFile() throws Exception { | ||
| Path srcPath = new Path(testRootDirPath, "testRenameSrc"); | ||
| Path dstPath = new Path(testRootDirPath, "testRenameDst"); | ||
| verifyRename(srcPath, dstPath, false); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRenameFileToFileWithOverwrite() throws Exception { | ||
| Path srcPath = new Path(testRootDirPath, "testRenameSrc"); | ||
| Path dstPath = new Path(testRootDirPath, "testRenameDst"); | ||
| verifyRename(srcPath, dstPath, true); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRenameFileIntoDirFile() throws Exception { | ||
| Path srcPath = new Path(testRootDirPath, "testRenameSrc"); | ||
| Path dstPath = new Path(testRootDirPath, "testRenameDir/testRenameDst"); | ||
| mkdirs(dstPath); | ||
| verifyRename(srcPath, dstPath, false); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRenameFileIntoDirFileWithOverwrite() throws Exception { | ||
| Path srcPath = new Path(testRootDirPath, "testRenameSrc"); | ||
| Path dstPath = new Path(testRootDirPath, "testRenameDir/testRenameDst"); | ||
| mkdirs(dstPath); | ||
| verifyRename(srcPath, dstPath, true); | ||
| } | ||
|
|
||
| private void verifyRename(Path srcPath, Path dstPath, | ||
| boolean overwrite) throws Exception { | ||
| AbstractFileSystem fs = fc.getDefaultFileSystem(); | ||
| assertTrue(fs instanceof LocalFs); | ||
steveloughran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ChecksumFs checksumFs = (ChecksumFs) fs; | ||
|
|
||
| fs.delete(srcPath, true); | ||
| fs.delete(dstPath, true); | ||
|
|
||
| Options.Rename renameOpt = Options.Rename.NONE; | ||
| if (overwrite) { | ||
| renameOpt = Options.Rename.OVERWRITE; | ||
| createTestFile(checksumFs, dstPath, 2); | ||
| } | ||
|
|
||
| // ensure file + checksum are moved | ||
| createTestFile(checksumFs, srcPath, 1); | ||
| assertTrue(fc.util().exists(checksumFs.getChecksumFile(srcPath))); | ||
steveloughran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| checksumFs.rename(srcPath, dstPath, renameOpt); | ||
| assertTrue(fc.util().exists(checksumFs.getChecksumFile(dstPath))); | ||
| try (FSDataInputStream is = fs.open(dstPath)) { | ||
| assertEquals(1, is.readInt()); | ||
| } | ||
| } | ||
|
|
||
| private static Configuration getTestConfiguration() { | ||
| Configuration conf = new Configuration(false); | ||
| conf.set("fs.defaultFS", "file:///"); | ||
| conf.setClass("fs.AbstractFileSystem.file.impl", | ||
| org.apache.hadoop.fs.local.LocalFs.class, | ||
| org.apache.hadoop.fs.AbstractFileSystem.class); | ||
| return conf; | ||
| } | ||
|
|
||
| private void createTestFile(ChecksumFs fs, Path path, int content) | ||
| throws IOException { | ||
| try (FSDataOutputStream fout = fs.create(path, | ||
| EnumSet.of(CREATE, OVERWRITE), | ||
| Options.CreateOpts.perms(FsPermission.getDefault()))) { | ||
| fout.writeInt(content); | ||
| } | ||
| } | ||
|
|
||
| private void mkdirs(Path dirPath) throws IOException { | ||
| fc.mkdir(dirPath, FileContext.DEFAULT_PERM, true); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
Would it be wrong to delegate to myFs like here:
hadoop/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFs.java
Line 254 in d992c95
Just curious. What is the concrete class of the AbastractFileSystem field?
Uh oh!
There was an error while loading. Please reload this page.
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.
ChecksumFs should deal with checksum file by itself (others even don't have to know the existence of checksum - once all operations are pass through ChecksumFs's override methods): that's why the method should be override. Just delegating rename would have same result, checksum file leak.
If the source file is from local filesystem, I think it's RawLocalFs. It could be DelegateToFileSystem, but it will redirect to RawLocalFs eventually.
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.
Looking at this, its the more elegant functional API. Which is nice for hadoop 3+. But I fear its probably going to lose all that elegance on branch-2 (assuming you do want a backport). If you do, then simply copying the existing renameInternal to one with a new signature is going to be the simplest