-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-1354] Block updates and replace on file groups in clustering #2275
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
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
70 changes: 70 additions & 0 deletions
70
...lient/hudi-client-common/src/main/java/org/apache/hudi/config/HoodieClusteringConfig.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,70 @@ | ||
| /* | ||
| * 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.config; | ||
|
|
||
| import org.apache.hudi.common.config.DefaultHoodieConfig; | ||
| import org.apache.hudi.table.action.clustering.update.RejectUpdateStrategy; | ||
| import org.apache.hudi.table.action.clustering.update.UpdateStrategy; | ||
|
|
||
| import java.io.File; | ||
| import java.io.FileReader; | ||
| import java.io.IOException; | ||
| import java.util.Properties; | ||
|
|
||
| public class HoodieClusteringConfig extends DefaultHoodieConfig { | ||
|
|
||
| public static final String CLUSTERING_UPDATES_STRATEGY_PROP = "hoodie.clustering.updates.strategy"; | ||
| public static final String DEFAULT_CLUSTERING_UPDATES_STRATEGY = RejectUpdateStrategy.class.getName(); | ||
|
|
||
| public HoodieClusteringConfig(Properties props) { | ||
| super(props); | ||
| } | ||
|
|
||
| public static Builder newBuilder() { | ||
| return new Builder(); | ||
| } | ||
|
|
||
| public static class Builder { | ||
| private final Properties props = new Properties(); | ||
|
|
||
| public Builder fromProperties(Properties props) { | ||
| this.props.putAll(props); | ||
| return this; | ||
| } | ||
|
|
||
| public Builder fromFile(File propertiesFile) throws IOException { | ||
| try (FileReader reader = new FileReader(propertiesFile)) { | ||
| this.props.load(reader); | ||
| return this; | ||
| } | ||
| } | ||
|
|
||
| public Builder withClusteringUpdatesStrategy(UpdateStrategy updatesStrategy) { | ||
| props.setProperty(CLUSTERING_UPDATES_STRATEGY_PROP, updatesStrategy.getClass().getName()); | ||
| return this; | ||
| } | ||
|
|
||
| public HoodieClusteringConfig build() { | ||
| HoodieClusteringConfig config = new HoodieClusteringConfig(props); | ||
| setDefaultOnCondition(props, !props.containsKey(CLUSTERING_UPDATES_STRATEGY_PROP), | ||
| CLUSTERING_UPDATES_STRATEGY_PROP, DEFAULT_CLUSTERING_UPDATES_STRATEGY); | ||
| return config; | ||
| } | ||
| } | ||
| } | ||
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
29 changes: 29 additions & 0 deletions
29
...lient-common/src/main/java/org/apache/hudi/exception/HoodieClusteringUpdateException.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,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.hudi.exception; | ||
|
|
||
| public class HoodieClusteringUpdateException extends HoodieException { | ||
| public HoodieClusteringUpdateException(String msg) { | ||
| super(msg); | ||
| } | ||
|
|
||
| public HoodieClusteringUpdateException(String msg, Throwable e) { | ||
| super(msg, e); | ||
| } | ||
| } |
61 changes: 61 additions & 0 deletions
61
...on/src/main/java/org/apache/hudi/table/action/clustering/update/RejectUpdateStrategy.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,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.hudi.table.action.clustering.update; | ||
|
|
||
| import org.apache.hudi.common.model.HoodieFileGroupId; | ||
| import org.apache.hudi.common.table.timeline.HoodieInstant; | ||
| import org.apache.hudi.common.util.collection.Pair; | ||
| import org.apache.hudi.exception.HoodieClusteringUpdateException; | ||
| import org.apache.hudi.table.WorkloadProfile; | ||
| import org.apache.hudi.table.WorkloadStat; | ||
| import org.apache.log4j.LogManager; | ||
| import org.apache.log4j.Logger; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class RejectUpdateStrategy implements UpdateStrategy { | ||
| private static final Logger LOG = LogManager.getLogger(RejectUpdateStrategy.class); | ||
|
|
||
lw309637554 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @Override | ||
| public void apply(List<Pair<HoodieFileGroupId, HoodieInstant>> fileGroupsInPendingClustering, WorkloadProfile workloadProfile) { | ||
| Set<Pair<String, String>> partitionPathAndFileIds = fileGroupsInPendingClustering.stream() | ||
lw309637554 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .map(entry -> Pair.of(entry.getLeft().getPartitionPath(), entry.getLeft().getFileId())).collect(Collectors.toSet()); | ||
| if (partitionPathAndFileIds.size() == 0) { | ||
| return; | ||
| } | ||
|
|
||
| Set<Map.Entry<String, WorkloadStat>> partitionStatEntries = workloadProfile.getPartitionPathStatMap().entrySet(); | ||
| for (Map.Entry<String, WorkloadStat> partitionStat : partitionStatEntries) { | ||
| for (Map.Entry<String, Pair<String, Long>> updateLocEntry : | ||
| partitionStat.getValue().getUpdateLocationToCount().entrySet()) { | ||
| String partitionPath = partitionStat.getKey(); | ||
| String fileId = updateLocEntry.getKey(); | ||
| if (partitionPathAndFileIds.contains(Pair.of(partitionPath, fileId))) { | ||
lw309637554 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| String msg = String.format("Not allowed to update the clustering files partition: %s fileID: %s. " | ||
| + "For pending clustering operations, we are not going to support update for now.", partitionPath, fileId); | ||
| LOG.error(msg); | ||
| throw new HoodieClusteringUpdateException(msg); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
41 changes: 41 additions & 0 deletions
41
...t-common/src/main/java/org/apache/hudi/table/action/clustering/update/UpdateStrategy.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,41 @@ | ||
| /* | ||
| * 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.table.action.clustering.update; | ||
|
|
||
| import org.apache.hudi.common.model.HoodieFileGroupId; | ||
| import org.apache.hudi.common.table.timeline.HoodieInstant; | ||
| import org.apache.hudi.common.util.collection.Pair; | ||
| import org.apache.hudi.table.WorkloadProfile; | ||
|
|
||
| import java.util.List; | ||
|
|
||
lw309637554 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /** | ||
| * When file groups in clustering, write records to these file group need to check. | ||
| */ | ||
| public interface UpdateStrategy { | ||
|
|
||
| /** | ||
| * check the update records to the file group in clustering. | ||
| * @param fileGroupsInPendingClustering | ||
| * @param workloadProfile workloadProfile have the records update info, | ||
| * just like BaseSparkCommitActionExecutor.getUpsertPartitioner use it. | ||
| */ | ||
| void apply(List<Pair<HoodieFileGroupId, HoodieInstant>> fileGroupsInPendingClustering, WorkloadProfile workloadProfile); | ||
lw309637554 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| } | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.