zhangyue19921010 commented on code in PR #6133:
URL: https://github.com/apache/hudi/pull/6133#discussion_r1028232906
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/HoodieWriteHandle.java:
##########
@@ -187,8 +194,54 @@ protected Path makeNewFilePath(String partitionPath,
String fileName) {
* @param partitionPath Partition path
*/
protected void createMarkerFile(String partitionPath, String dataFileName) {
- WriteMarkersFactory.get(config.getMarkersType(), hoodieTable, instantTime)
- .create(partitionPath, dataFileName, getIOType());
+ WriteMarkers writeMarkers =
WriteMarkersFactory.get(config.getMarkersType(), hoodieTable, instantTime);
+ // do early conflict detection before create markers.
+ if (config.getWriteConcurrencyMode().supportsOptimisticConcurrencyControl()
+ && config.isEarlyConflictDetectionEnable()) {
+ HoodieEarlyConflictDetectionStrategy earlyConflictDetectionStrategy =
config.getEarlyConflictDetectionStrategy();
+ if (earlyConflictDetectionStrategy instanceof
HoodieTransactionDirectMarkerBasedEarlyConflictDetectionStrategy) {
+ createMarkerWithTransaction(earlyConflictDetectionStrategy,
writeMarkers, partitionPath, dataFileName);
+ } else {
+ createMarkerWithEarlyConflictDetection(earlyConflictDetectionStrategy,
writeMarkers, partitionPath, dataFileName);
+ }
+ } else {
+ // create marker directly
+ writeMarkers.create(partitionPath, dataFileName, getIOType());
+ }
Review Comment:
Nice catch here. Changed.
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/marker/SimpleTransactionDirectMarkerBasedEarlyConflictDetectionStrategy.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.marker;
+
+import org.apache.hadoop.fs.FileSystem;
+import
org.apache.hudi.common.conflict.detection.HoodieTransactionDirectMarkerBasedEarlyConflictDetectionStrategy;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.exception.HoodieEarlyConflictDetectionException;
+import org.apache.hudi.exception.HoodieIOException;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+import java.io.IOException;
+import java.util.ConcurrentModificationException;
+import java.util.Set;
+
+/**
+ * This strategy is used for direct marker writers, trying to do early
conflict detection.
+ * It will use fileSystem api like list and exist directly to check if there
is any marker file conflict.
+ */
+public class SimpleTransactionDirectMarkerBasedEarlyConflictDetectionStrategy
extends HoodieTransactionDirectMarkerBasedEarlyConflictDetectionStrategy {
+ private static final Logger LOG =
LogManager.getLogger(SimpleTransactionDirectMarkerBasedEarlyConflictDetectionStrategy.class);
+
+ @Override
+ public boolean hasMarkerConflict(String basePath, FileSystem fs, String
partitionPath, String fileId, String instantTime,
Review Comment:
Nice catch here. Changed.
--
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]