-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HUDI-1354] Block updates and replace on file groups in clustering
- Loading branch information
1 parent
4d05680
commit 0f5e49e
Showing
9 changed files
with
328 additions
and
1 deletion.
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 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 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 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 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); | ||
|
||
@Override | ||
public void apply(List<Pair<HoodieFileGroupId, HoodieInstant>> fileGroupsInPendingClustering, WorkloadProfile workloadProfile) { | ||
Set<Pair<String, String>> partitionPathAndFileIds = fileGroupsInPendingClustering.stream() | ||
.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))) { | ||
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 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; | ||
|
||
/** | ||
* 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); | ||
|
||
} |
This file contains 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 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 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.