-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[Core] support write to the external path #4770
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
Merged
JingsongLi
merged 24 commits into
apache:master
from
neuyilan:dev/qhl/support_tiered_storage_1224_write
Jan 6, 2025
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6718af4
support write to the external path
neuyilan 6edd281
fix compile error
neuyilan 098d08e
fix tests
neuyilan fbf5c4d
Merge branch 'master' into dev/qhl/support_tiered_storage_1224_write
neuyilan 9f8ecd2
merge master
neuyilan 3a00acc
fix the clone tests
neuyilan cbb695e
merge master and reslove conflicts
neuyilan e323a63
fix review comments
neuyilan 9965db3
fix review comments
neuyilan a1f2af0
support external-paths.strategy
neuyilan 63625df
remove useless codes
neuyilan 240e6ba
Merge branch 'master' into dev/qhl/support_tiered_storage_1224_write
neuyilan 20affd2
make ExternalPathProvider implements Serializable
neuyilan 823adcf
add toString and hash method in ExternalPathProvider
neuyilan f981331
fix docs description
neuyilan 1637325
add ExternalPathProviderTest
neuyilan a025e65
add doc for ExternalPathProviderTest
neuyilan 80b8721
remove useless codes
neuyilan bcb2be1
add isExternalPath field in SingleFileWriter
neuyilan f3303c1
change data-file.external-paths.specific-fs to string
neuyilan 3a63857
Revert "fix the clone tests"
neuyilan 928a02d
fix review comments and add some IT tests
neuyilan 4848298
fix IT
neuyilan 701b79a
add external path IT
neuyilan 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
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
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
82 changes: 82 additions & 0 deletions
82
paimon-common/src/main/java/org/apache/paimon/fs/DataFileExternalPathProvider.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,82 @@ | ||
| /* | ||
| * 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.paimon.fs; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
|
|
||
| /** Provider for external data paths. */ | ||
| public class DataFileExternalPathProvider implements Serializable { | ||
| @Nullable private final TableExternalPathProvider tableExternalPathProvider; | ||
| private final Path relativeBucketPath; | ||
|
|
||
| public DataFileExternalPathProvider( | ||
| @Nullable TableExternalPathProvider tableExternalPathProvider, | ||
| Path relativeBucketPath) { | ||
| this.tableExternalPathProvider = tableExternalPathProvider; | ||
| this.relativeBucketPath = relativeBucketPath; | ||
| } | ||
|
|
||
| /** | ||
| * Get the next external data path. | ||
| * | ||
| * @return the next external data path | ||
| */ | ||
| public Optional<Path> getNextExternalDataPath() { | ||
| return Optional.ofNullable(tableExternalPathProvider) | ||
| .flatMap(TableExternalPathProvider::getNextExternalPath) | ||
| .map(path -> new Path(path, relativeBucketPath)); | ||
| } | ||
|
|
||
| public boolean externalPathExists() { | ||
| return tableExternalPathProvider != null && tableExternalPathProvider.externalPathExists(); | ||
| } | ||
|
|
||
| @Override | ||
| public final boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (!(o instanceof DataFileExternalPathProvider)) { | ||
| return false; | ||
| } | ||
|
|
||
| DataFileExternalPathProvider that = (DataFileExternalPathProvider) o; | ||
| return Objects.equals(tableExternalPathProvider, that.tableExternalPathProvider) | ||
| && Objects.equals(relativeBucketPath, that.relativeBucketPath); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(tableExternalPathProvider, relativeBucketPath); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "DataFileExternalPathProvider{" | ||
| + " externalPathProvider=" | ||
| + tableExternalPathProvider | ||
| + ", relativeBucketPath=" | ||
| + relativeBucketPath | ||
| + "}"; | ||
| } | ||
| } |
192 changes: 192 additions & 0 deletions
192
paimon-common/src/main/java/org/apache/paimon/fs/TableExternalPathProvider.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,192 @@ | ||
| /* | ||
| * 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.paimon.fs; | ||
|
|
||
| import org.apache.paimon.CoreOptions.ExternalPathStrategy; | ||
| import org.apache.paimon.annotation.VisibleForTesting; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
| import java.util.Random; | ||
|
|
||
| /** Provider for external paths. */ | ||
| public class TableExternalPathProvider implements Serializable { | ||
| private final Map<String, Path> externalPathsMap; | ||
| private final List<Path> externalPathsList; | ||
|
|
||
| private final ExternalPathStrategy externalPathStrategy; | ||
| private final String externalSpecificFS; | ||
| private int currentIndex = 0; | ||
| private boolean externalPathExists; | ||
|
|
||
| public TableExternalPathProvider( | ||
| String externalPaths, | ||
| ExternalPathStrategy externalPathStrategy, | ||
| String externalSpecificFS) { | ||
| this.externalPathsMap = new HashMap<>(); | ||
| this.externalPathsList = new ArrayList<>(); | ||
| this.externalPathStrategy = externalPathStrategy; | ||
| if (externalSpecificFS != null) { | ||
| this.externalSpecificFS = externalSpecificFS.toLowerCase(); | ||
| } else { | ||
| this.externalSpecificFS = null; | ||
| } | ||
| initExternalPaths(externalPaths); | ||
| if (!externalPathsList.isEmpty()) { | ||
| this.currentIndex = new Random().nextInt(externalPathsList.size()); | ||
| } | ||
| } | ||
|
|
||
| private void initExternalPaths(String externalPaths) { | ||
| if (externalPaths == null) { | ||
| return; | ||
| } | ||
|
|
||
| String[] tmpArray = externalPaths.split(","); | ||
| for (String s : tmpArray) { | ||
| Path path = new Path(s.trim()); | ||
| String scheme = path.toUri().getScheme(); | ||
| if (scheme == null) { | ||
| throw new IllegalArgumentException("scheme should not be null: " + path); | ||
| } | ||
| scheme = scheme.toLowerCase(); | ||
| externalPathsMap.put(scheme, path); | ||
| externalPathsList.add(path); | ||
| } | ||
|
|
||
| if (externalPathStrategy != null | ||
| && externalPathStrategy.equals(ExternalPathStrategy.SPECIFIC_FS)) { | ||
| if (externalSpecificFS == null) { | ||
| throw new IllegalArgumentException("external specific fs should not be null: "); | ||
| } | ||
|
|
||
| if (!externalPathsMap.containsKey(externalSpecificFS)) { | ||
| throw new IllegalArgumentException( | ||
| "external specific fs not found: " + externalSpecificFS); | ||
| } | ||
| } | ||
|
|
||
| if (!externalPathsMap.isEmpty() | ||
| && !externalPathsList.isEmpty() | ||
| && externalPathStrategy != ExternalPathStrategy.NONE) { | ||
| externalPathExists = true; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get the next external path. | ||
| * | ||
| * @return the next external path | ||
| */ | ||
| public Optional<Path> getNextExternalPath() { | ||
| if (externalPathsMap == null || externalPathsMap.isEmpty()) { | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| switch (externalPathStrategy) { | ||
| case NONE: | ||
| return Optional.empty(); | ||
| case SPECIFIC_FS: | ||
| return getSpecificFSExternalPath(); | ||
| case ROUND_ROBIN: | ||
| return getRoundRobinPath(); | ||
| default: | ||
| return Optional.empty(); | ||
| } | ||
| } | ||
|
|
||
| private Optional<Path> getSpecificFSExternalPath() { | ||
| if (!externalPathsMap.containsKey(externalSpecificFS)) { | ||
| return Optional.empty(); | ||
| } | ||
| return Optional.of(externalPathsMap.get(externalSpecificFS)); | ||
| } | ||
|
|
||
| private Optional<Path> getRoundRobinPath() { | ||
| currentIndex = (currentIndex + 1) % externalPathsList.size(); | ||
| return Optional.of(externalPathsList.get(currentIndex)); | ||
| } | ||
|
|
||
| public boolean externalPathExists() { | ||
| return externalPathExists; | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| public Map<String, Path> getExternalPathsMap() { | ||
| return externalPathsMap; | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| public List<Path> getExternalPathsList() { | ||
| return externalPathsList; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
|
|
||
| TableExternalPathProvider that = (TableExternalPathProvider) o; | ||
| return currentIndex == that.currentIndex | ||
| && externalPathExists == that.externalPathExists | ||
| && externalPathsMap.equals(that.externalPathsMap) | ||
| && externalPathsList.equals(that.externalPathsList) | ||
| && externalPathStrategy == that.externalPathStrategy | ||
| && Objects.equals(externalSpecificFS, that.externalSpecificFS); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "ExternalPathProvider{" | ||
| + " externalPathsMap=" | ||
| + externalPathsMap | ||
| + ", externalPathsList=" | ||
| + externalPathsList | ||
| + ", externalPathStrategy=" | ||
| + externalPathStrategy | ||
| + ", externalSpecificFS='" | ||
| + externalSpecificFS | ||
| + '\'' | ||
| + ", currentIndex=" | ||
| + currentIndex | ||
| + ", externalPathExists=" | ||
| + externalPathExists | ||
| + "}"; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash( | ||
| externalPathsMap, | ||
| externalPathsList, | ||
| externalPathStrategy, | ||
| externalSpecificFS, | ||
| currentIndex, | ||
| externalPathExists); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Please add nullable for all nullable methods and fields. ALL, not just this one.