-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-5936] Fix serialization problem when FileStatus is not serializable #8190
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4a0159a
Expose filename when getting commit time from illegal filename
CTTY fb86d9a
Merge remote-tracking branch 'opensource/master'
CTTY d915b2f
Fix serialization problem by using HoodieFileStatus
CTTY d741f6f
minor
CTTY eb50e54
Clean up spark context after test
CTTY 3691e52
Add HoodieSerializableFileStatus to cover avro 1.8.2
CTTY File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
.../hudi-spark-client/src/test/java/org/apache/hudi/common/fs/NonSerializableFileSystem.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /* | ||
| * 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.hudi.common.fs; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.FSDataInputStream; | ||
| import org.apache.hadoop.fs.FSDataOutputStream; | ||
| import org.apache.hadoop.fs.FileStatus; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.fs.permission.FsPermission; | ||
| import org.apache.hadoop.util.Progressable; | ||
|
|
||
| import java.io.FileNotFoundException; | ||
| import java.io.IOException; | ||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
|
|
||
| /** | ||
| * A non-serializable file system for testing only. See {@link TestHoodieSerializableFileStatus} | ||
| * Can't make this an inner class as the outer class would also be non-serializable and invalidate | ||
| * the purpose of testing | ||
| */ | ||
| public class NonSerializableFileSystem extends FileSystem { | ||
| @Override | ||
| public URI getUri() { | ||
| try { | ||
| return new URI(""); | ||
| } catch (URISyntaxException e) { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public FSDataInputStream open(Path path, int i) throws IOException { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public FSDataOutputStream create(Path path, FsPermission fsPermission, boolean b, int i, | ||
| short i1, long l, Progressable progressable) throws IOException { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public FSDataOutputStream append(Path path, int i, Progressable progressable) | ||
| throws IOException { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean rename(Path path, Path path1) throws IOException { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean delete(Path path, boolean b) throws IOException { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public FileStatus[] listStatus(Path path) throws FileNotFoundException, IOException { | ||
| FileStatus[] ret = new FileStatus[5]; | ||
| for (int i = 0; i < 5; i++) { | ||
| ret[i] = new FileStatus(100L, false, 1, 10000L, | ||
| 0L, 0, null, "owner", "group", path) { | ||
| Configuration conf = getConf(); | ||
|
|
||
| @Override | ||
| public long getLen() { | ||
| return -1; | ||
| } | ||
| }; | ||
| } | ||
| return ret; | ||
| } | ||
|
|
||
| @Override | ||
| public void setWorkingDirectory(Path path) {} | ||
|
|
||
| @Override | ||
| public Path getWorkingDirectory() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean mkdirs(Path path, FsPermission fsPermission) throws IOException { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public FileStatus getFileStatus(Path path) throws IOException { | ||
| return null; | ||
| } | ||
|
|
||
| public Configuration getConf() { | ||
| return new Configuration(); | ||
| } | ||
| } |
86 changes: 86 additions & 0 deletions
86
...park-client/src/test/java/org/apache/hudi/common/fs/TestHoodieSerializableFileStatus.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| * 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.hudi.common.fs; | ||
|
|
||
| import org.apache.hudi.client.common.HoodieSparkEngineContext; | ||
| import org.apache.hudi.common.engine.HoodieEngineContext; | ||
| import org.apache.hudi.testutils.HoodieClientTestHarness; | ||
|
|
||
| import org.apache.hadoop.fs.FileStatus; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.spark.SparkException; | ||
|
|
||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.TestInstance; | ||
| import org.junit.jupiter.api.TestInstance.Lifecycle; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Test the if {@link HoodieSerializableFileStatus} is serializable | ||
| */ | ||
| @TestInstance(Lifecycle.PER_CLASS) | ||
| public class TestHoodieSerializableFileStatus extends HoodieClientTestHarness { | ||
|
|
||
| HoodieEngineContext engineContext; | ||
| List<Path> testPaths; | ||
|
|
||
| @BeforeAll | ||
| public void setUp() throws IOException { | ||
| initSparkContexts(); | ||
| testPaths = new ArrayList<>(5); | ||
| for (int i = 0; i < 5; i++) { | ||
| testPaths.add(new Path("s3://table-bucket/")); | ||
| } | ||
| engineContext = new HoodieSparkEngineContext(jsc); | ||
| } | ||
|
|
||
| @AfterAll | ||
| public void tearDown() { | ||
| cleanupSparkContexts(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNonSerializableFileStatus() { | ||
| Exception e = Assertions.assertThrows(SparkException.class, | ||
| () -> { | ||
| List<FileStatus> statuses = engineContext.flatMap(testPaths, path -> { | ||
| FileSystem fileSystem = new NonSerializableFileSystem(); | ||
| return Arrays.stream(fileSystem.listStatus(path)); | ||
| }, 5); | ||
| }, | ||
| "Serialization is supposed to fail!"); | ||
| Assertions.assertTrue(e.getMessage().contains("com.esotericsoftware.kryo.KryoException: java.util.ConcurrentModificationException")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testHoodieFileStatusSerialization() { | ||
| List<HoodieSerializableFileStatus> statuses = engineContext.flatMap(testPaths, path -> { | ||
| FileSystem fileSystem = new NonSerializableFileSystem(); | ||
| return Arrays.stream(HoodieSerializableFileStatus.fromFileStatuses(fileSystem.listStatus(path))); | ||
| }, 5); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
hudi-common/src/main/java/org/apache/hudi/common/fs/HoodieSerializableFileStatus.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * 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.hudi.common.fs; | ||
|
|
||
| import org.apache.hadoop.fs.FileStatus; | ||
| import org.apache.hadoop.fs.Path; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.Arrays; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** | ||
| * A serializable file status implementation | ||
| * <p> | ||
| * Use `HoodieFileStatus` generated by Avro instead this class if possible | ||
| * This class is needed because `hudi-hadoop-mr-bundle` relies on Avro 1.8.2, | ||
| * and won't work well with `HoodieFileStatus` | ||
| */ | ||
| public class HoodieSerializableFileStatus implements Serializable { | ||
|
|
||
| private Path path; | ||
| private long length; | ||
| private Boolean isDir; | ||
| private short blockReplication; | ||
| private long blockSize; | ||
| private long modificationTime; | ||
| private long accessTime; | ||
|
|
||
| HoodieSerializableFileStatus(FileStatus fileStatus) { | ||
| this(fileStatus.getPath(), | ||
| fileStatus.getLen(), | ||
| fileStatus.isDirectory(), | ||
| fileStatus.getReplication(), | ||
| fileStatus.getBlockSize(), | ||
| fileStatus.getModificationTime(), | ||
| fileStatus.getAccessTime()); | ||
| } | ||
|
|
||
| HoodieSerializableFileStatus(Path path, long length, boolean isDir, short blockReplication, | ||
| long blockSize, long modificationTime, long accessTime) { | ||
| this.path = path; | ||
| this.length = length; | ||
| this.isDir = isDir; | ||
| this.blockReplication = blockReplication; | ||
| this.blockSize = blockSize; | ||
| this.modificationTime = modificationTime; | ||
| this.accessTime = accessTime; | ||
| } | ||
|
|
||
| public Path getPath() { | ||
| return path; | ||
| } | ||
|
|
||
| public long getLen() { | ||
| return length; | ||
| } | ||
|
|
||
| public Boolean isDirectory() { | ||
| return isDir; | ||
| } | ||
|
|
||
| public short getReplication() { | ||
| return blockReplication; | ||
| } | ||
|
|
||
| public long getBlockSize() { | ||
| return blockSize; | ||
| } | ||
|
|
||
| public long getModificationTime() { | ||
| return modificationTime; | ||
| } | ||
|
|
||
| public long getAccessTime() { | ||
| return accessTime; | ||
| } | ||
|
|
||
| public static HoodieSerializableFileStatus fromFileStatus(FileStatus status) { | ||
| return new HoodieSerializableFileStatus(status); | ||
| } | ||
|
|
||
| public static HoodieSerializableFileStatus[] fromFileStatuses(FileStatus[] statuses) { | ||
| return Arrays.stream(statuses) | ||
| .map(status -> HoodieSerializableFileStatus.fromFileStatus(status)) | ||
| .collect(Collectors.toList()) | ||
| .toArray(new HoodieSerializableFileStatus[statuses.length]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@CTTY looks like in the latest master, we no longer return
FileStatushere (thePathinstances are used instead). Is this PR still needed?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.
You are right, I don't think this is needed anymore
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.
Got it. I'll close this PR.