yihua commented on code in PR #6133: URL: https://github.com/apache/hudi/pull/6133#discussion_r1064236073
########## hudi-common/src/main/java/org/apache/hudi/common/conflict/detection/HoodieDirectMarkerBasedEarlyConflictDetectionStrategy.java: ########## @@ -0,0 +1,109 @@ +/* + * 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.conflict.detection; + +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hudi.common.model.HoodieCommitMetadata; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.common.table.timeline.HoodieInstant; +import org.apache.hudi.common.util.StringUtils; +import org.apache.hudi.exception.HoodieIOException; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public abstract class HoodieDirectMarkerBasedEarlyConflictDetectionStrategy implements HoodieEarlyConflictDetectionStrategy { + private static final Logger LOG = LogManager.getLogger(HoodieDirectMarkerBasedEarlyConflictDetectionStrategy.class); + + public abstract boolean hasMarkerConflict(String basePath, FileSystem fs, String partitionPath, String dataFileName, String instantTime, + Set<HoodieInstant> completedCommitInstants, HoodieTableMetaClient metaClient); + + public abstract void resolveMarkerConflict(String basePath, String partitionPath, String dataFileName); + + /** + * We need to do list operation here. + * In order to reduce the list pressure as much as possible, first we build path prefix in advance: '$base_path/.temp/instant_time/partition_path', + * and only list these specific partition_paths we need instead of list all the '$base_path/.temp/' + * @param basePath + * @param partitionPath + * @param fileId 162b13d7-9530-48cf-88a4-02241817ae0c-0_1-74-100_003.parquet + * @return true if current fileID is already existed under .temp/instant_time/partition_path/.. + * @throws IOException + */ + public boolean checkMarkerConflict(String basePath, String partitionPath, String fileId, + FileSystem fs, String instantTime) throws IOException { + String tempFolderPath = getTempFolderPath(basePath); + long res = Arrays.stream(fs.listStatus(new Path(tempFolderPath))) + .parallel() + .map(FileStatus::getPath) + .filter(markerPath -> { + return !markerPath.getName().equalsIgnoreCase(instantTime); + }) Review Comment: I think there's a gap here. We should use the active timeline loaded at the beginning of one commit to determine which inflight instants to check against, instead of checking and filtering all marker folders under `.temp/` which is inefficient. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
