satishkotha commented on a change in pull request #2263:
URL: https://github.com/apache/hudi/pull/2263#discussion_r545553782
##########
File path:
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metrics/HoodieMetrics.java
##########
@@ -48,6 +49,7 @@
private Timer deltaCommitTimer = null;
private Timer finalizeTimer = null;
private Timer compactionTimer = null;
+ private Timer clusteringTimer = null;
Review comment:
This is specific to clustering operation and only used in
WriteClient#cluster.
We could have a different timer for insertOverwrite and replace commands if
needed. I like this approach because replace can mean multiple things. Let me
know if you think common timer makes more sense.
##########
File path:
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/action/cluster/strategy/PartitionAwareScheduleClusteringStrategy.java
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.cluster.strategy;
+
+import org.apache.hudi.avro.model.HoodieClusteringGroup;
+import org.apache.hudi.avro.model.HoodieClusteringPlan;
+import org.apache.hudi.avro.model.HoodieClusteringStrategy;
+import org.apache.hudi.client.common.HoodieEngineContext;
+import org.apache.hudi.common.fs.FSUtils;
+import org.apache.hudi.common.model.FileSlice;
+import org.apache.hudi.common.model.HoodieRecordPayload;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieIOException;
+import org.apache.hudi.table.HoodieTable;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * Scheduling strategy with restriction that clustering groups can only
contain files from same partition.
+ */
+public abstract class PartitionAwareScheduleClusteringStrategy<T extends
HoodieRecordPayload,I,K,O> extends ScheduleClusteringStrategy<T,I,K,O> {
+ private static final Logger LOG =
LogManager.getLogger(PartitionAwareScheduleClusteringStrategy.class);
+ // With more than 50 groups, we see performance degradation with this
Strategy implementation.
+ private static final int MAX_CLUSTERING_GROUPS_STRATEGY = 50;
+
+ public PartitionAwareScheduleClusteringStrategy(HoodieTable table,
HoodieEngineContext engineContext, HoodieWriteConfig writeConfig) {
+ super(table, engineContext, writeConfig);
+ }
+
+ /**
+ * Create Clustering group based on files eligible for clustering in the
partition.
+ */
+ protected abstract Stream<HoodieClusteringGroup>
buildClusteringGroupsForPartition(String partitionPath,
+
List<FileSlice> fileSlices);
+
+ /**
+ * Return list of partition paths to be considered for clustering.
+ */
+ protected List<String> filterPartitionPaths(List<String> partitionPaths) {
+ return partitionPaths;
+ }
+
+ @Override
+ public Option<HoodieClusteringPlan> generateClusteringPlan() {
+ try {
+ HoodieTableMetaClient metaClient = getHoodieTable().getMetaClient();
+ LOG.info("Scheduling clustering for " + metaClient.getBasePath());
+ List<String> partitionPaths =
FSUtils.getAllPartitionPaths(metaClient.getFs(), metaClient.getBasePath(),
+ getWriteConfig().shouldAssumeDatePartitioning());
+
+ // filter the partition paths if needed to reduce list status
+ partitionPaths = filterPartitionPaths(partitionPaths);
+
+ if (partitionPaths.isEmpty()) {
+ // In case no partitions could be picked, return no clustering plan
+ return Option.empty();
+ }
+
+ long maxClusteringGroups = getWriteConfig().getClusteringMaxNumGroups();
Review comment:
Fixed.
##########
File path:
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/action/cluster/strategy/PartitionAwareScheduleClusteringStrategy.java
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.cluster.strategy;
+
+import org.apache.hudi.avro.model.HoodieClusteringGroup;
+import org.apache.hudi.avro.model.HoodieClusteringPlan;
+import org.apache.hudi.avro.model.HoodieClusteringStrategy;
+import org.apache.hudi.client.common.HoodieEngineContext;
+import org.apache.hudi.common.fs.FSUtils;
+import org.apache.hudi.common.model.FileSlice;
+import org.apache.hudi.common.model.HoodieRecordPayload;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieIOException;
+import org.apache.hudi.table.HoodieTable;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * Scheduling strategy with restriction that clustering groups can only
contain files from same partition.
+ */
+public abstract class PartitionAwareScheduleClusteringStrategy<T extends
HoodieRecordPayload,I,K,O> extends ScheduleClusteringStrategy<T,I,K,O> {
+ private static final Logger LOG =
LogManager.getLogger(PartitionAwareScheduleClusteringStrategy.class);
+ // With more than 50 groups, we see performance degradation with this
Strategy implementation.
+ private static final int MAX_CLUSTERING_GROUPS_STRATEGY = 50;
+
+ public PartitionAwareScheduleClusteringStrategy(HoodieTable table,
HoodieEngineContext engineContext, HoodieWriteConfig writeConfig) {
+ super(table, engineContext, writeConfig);
+ }
+
+ /**
+ * Create Clustering group based on files eligible for clustering in the
partition.
+ */
+ protected abstract Stream<HoodieClusteringGroup>
buildClusteringGroupsForPartition(String partitionPath,
+
List<FileSlice> fileSlices);
+
+ /**
+ * Return list of partition paths to be considered for clustering.
+ */
+ protected List<String> filterPartitionPaths(List<String> partitionPaths) {
+ return partitionPaths;
+ }
+
+ @Override
+ public Option<HoodieClusteringPlan> generateClusteringPlan() {
+ try {
+ HoodieTableMetaClient metaClient = getHoodieTable().getMetaClient();
+ LOG.info("Scheduling clustering for " + metaClient.getBasePath());
+ List<String> partitionPaths =
FSUtils.getAllPartitionPaths(metaClient.getFs(), metaClient.getBasePath(),
+ getWriteConfig().shouldAssumeDatePartitioning());
+
+ // filter the partition paths if needed to reduce list status
+ partitionPaths = filterPartitionPaths(partitionPaths);
+
+ if (partitionPaths.isEmpty()) {
+ // In case no partitions could be picked, return no clustering plan
+ return Option.empty();
+ }
+
+ long maxClusteringGroups = getWriteConfig().getClusteringMaxNumGroups();
+ if (maxClusteringGroups > MAX_CLUSTERING_GROUPS_STRATEGY) {
+ LOG.warn("Reducing max clustering groups to " +
MAX_CLUSTERING_GROUPS_STRATEGY + " for performance reasons");
+ maxClusteringGroups = MAX_CLUSTERING_GROUPS_STRATEGY;
+ }
+
+ List<HoodieClusteringGroup> clusteringGroups = partitionPaths.stream()
Review comment:
Updated.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]