You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2021/08/14 14:54:02 UTC

[GitHub] [hudi] vinothchandar commented on a change in pull request #3470: [HUDI-2268] Add upgrade and downgrade to and from 0.9.0

vinothchandar commented on a change in pull request #3470:
URL: https://github.com/apache/hudi/pull/3470#discussion_r688937740



##########
File path: hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/BaseOneToZeroDowngradeHandler.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.upgrade;
+
+import org.apache.hudi.common.config.ConfigProperty;
+import org.apache.hudi.common.engine.HoodieEngineContext;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.table.timeline.HoodieTimeline;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.table.HoodieTable;
+import org.apache.hudi.table.marker.WriteMarkers;
+import org.apache.hudi.table.marker.WriteMarkersFactory;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public abstract class BaseOneToZeroDowngradeHandler implements DowngradeHandler {
+
+  @Override
+  public Map<ConfigProperty, String> downgrade(HoodieWriteConfig config, HoodieEngineContext context, String instantTime) {
+    // fetch pending commit info
+    HoodieTable table = getTable(config, context);
+    HoodieTimeline inflightTimeline = table.getMetaClient().getCommitsTimeline().filterPendingExcludingCompaction();
+    List<HoodieInstant> commits = inflightTimeline.getReverseOrderedInstants().collect(Collectors.toList());
+    for (HoodieInstant commitInstant : commits) {

Review comment:
       rename: inflightInstant

##########
File path: hudi-client/hudi-spark-client/src/main/scala/org/apache/hudi/HoodieSparkWriterUtils.scala
##########
@@ -0,0 +1,64 @@
+/*
+ * 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
+
+import java.util.Properties
+import org.apache.hudi.common.config.TypedProperties
+import org.apache.hudi.keygen.constant.KeyGeneratorOptions
+import org.apache.hudi.keygen.factory.HoodieSparkKeyGeneratorFactory
+import org.apache.hudi.keygen.{BaseKeyGenerator, CustomAvroKeyGenerator, CustomKeyGenerator, KeyGenerator}
+import org.apache.spark.sql.sources.v2.DataSourceOptions
+
+import scala.collection.JavaConverters._
+
+/**
+ * A utility class for Spark writer
+ */
+object HoodieSparkWriterUtils {

Review comment:
       can this not go into any of the existing helper classes? avoid creating this class?

##########
File path: hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/BaseZeroToOneUpgradeHandler.java
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.upgrade;
+
+import org.apache.hudi.common.HoodieRollbackStat;
+import org.apache.hudi.common.config.ConfigProperty;
+import org.apache.hudi.common.engine.HoodieEngineContext;
+import org.apache.hudi.common.fs.FSUtils;
+import org.apache.hudi.common.model.HoodieTableType;
+import org.apache.hudi.common.model.IOType;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.marker.MarkerType;
+import org.apache.hudi.common.table.timeline.HoodieActiveTimeline;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.table.timeline.HoodieTimeline;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieRollbackException;
+import org.apache.hudi.table.HoodieTable;
+import org.apache.hudi.table.action.rollback.ListingBasedRollbackRequest;
+import org.apache.hudi.table.action.rollback.RollbackUtils;
+import org.apache.hudi.table.marker.WriteMarkers;
+import org.apache.hudi.table.marker.WriteMarkersFactory;
+
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.Path;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public abstract class BaseZeroToOneUpgradeHandler implements UpgradeHandler {

Review comment:
       I assume this is old code, just being relocated

##########
File path: hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/BaseOneToTwoUpgradeHandler.java
##########
@@ -0,0 +1,43 @@
+/*
+ * 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.upgrade;
+
+import org.apache.hudi.common.config.ConfigProperty;
+import org.apache.hudi.common.engine.HoodieEngineContext;
+import org.apache.hudi.common.table.HoodieTableConfig;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.keygen.constant.KeyGeneratorOptions;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public abstract class BaseOneToTwoUpgradeHandler implements UpgradeHandler {
+
+  @Override
+  public Map<ConfigProperty, String> upgrade(HoodieWriteConfig config, HoodieEngineContext context, String instantTime) {
+    Map<ConfigProperty, String> tablePropsToAdd = new HashMap<>();
+    tablePropsToAdd.put(HoodieTableConfig.HOODIE_TABLE_NAME_PROP, config.getTableName());

Review comment:
       this should be there always. do we need to add?

##########
File path: hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/BaseTwoToOneDowngradeHandler.java
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.upgrade;
+
+import org.apache.hudi.common.config.ConfigProperty;
+import org.apache.hudi.common.engine.HoodieEngineContext;
+import org.apache.hudi.common.fs.FSUtils;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.marker.MarkerType;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.table.timeline.HoodieTimeline;
+import org.apache.hudi.common.util.MarkerUtils;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieException;
+import org.apache.hudi.table.HoodieTable;
+import org.apache.hudi.table.marker.DirectWriteMarkers;
+
+import com.esotericsoftware.minlog.Log;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import static org.apache.hudi.common.util.MarkerUtils.MARKERS_FILENAME_PREFIX;
+
+public abstract class BaseTwoToOneDowngradeHandler implements DowngradeHandler {
+
+  @Override
+  public Map<ConfigProperty, String> downgrade(HoodieWriteConfig config, HoodieEngineContext context, String instantTime) {
+    HoodieTable table = getTable(config, context);
+    HoodieTableMetaClient metaClient = table.getMetaClient();
+
+    // re-create marker files if any partial timeline server based markers are found
+    HoodieTimeline inflightTimeline = metaClient.getCommitsTimeline().filterPendingExcludingCompaction();
+    List<HoodieInstant> commits = inflightTimeline.getReverseOrderedInstants().collect(Collectors.toList());
+    for (HoodieInstant commitInstant : commits) {
+      // Converts the markers in new format to old format of direct markers
+      try {
+        convertToDirectMarkers(
+            commitInstant.getTimestamp(), table, context, config.getMarkersDeleteParallelism());
+      } catch (IOException e) {
+        throw new HoodieException("Converting marker files to DIRECT style failed during downgrade", e);
+      }
+    }
+    return Collections.EMPTY_MAP;
+  }
+
+  abstract HoodieTable getTable(HoodieWriteConfig config, HoodieEngineContext context);
+
+  /**
+   * Converts the markers in new format(timeline server based) to old format of direct markers,
+   * i.e., one marker file per data file, without MARKERS.type file.
+   * This needs to be idempotent.
+   * 1. read all markers from timeline server based marker files
+   * 2. create direct style markers
+   * 3. delete marker type file
+   * 4. delete timeline server based marker files
+   *
+   * @param commitInstantTime instant of interest for marker conversion.
+   * @param table             instance of {@link HoodieTable} to use
+   * @param context           instance of {@link HoodieEngineContext} to use
+   * @param parallelism       parallelism to use
+   */
+  private void convertToDirectMarkers(final String commitInstantTime,
+                                      HoodieTable table,
+                                      HoodieEngineContext context,
+                                      int parallelism) throws IOException {
+    String markerDir = table.getMetaClient().getMarkerFolderPath(commitInstantTime);
+    FileSystem fileSystem = FSUtils.getFs(markerDir, context.getHadoopConf().newCopy());
+    Option<MarkerType> markerTypeOption = MarkerUtils.readMarkerType(fileSystem, markerDir);
+    if (markerTypeOption.isPresent()) {
+      switch (markerTypeOption.get()) {
+        case TIMELINE_SERVER_BASED:
+          // Reads all markers written by the timeline server
+          Map<String, Set<String>> markersMap =
+              MarkerUtils.readTimelineServerBasedMarkersFromFileSystem(
+                  markerDir, fileSystem, context, parallelism);
+          DirectWriteMarkers directWriteMarkers = new DirectWriteMarkers(table, commitInstantTime);
+          // Recreates the markers in the direct format
+          for (Set<String> markers : markersMap.values()) {

Review comment:
       `markersMap.values().stream().....` just one line?

##########
File path: hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/BaseTwoToOneDowngradeHandler.java
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.upgrade;
+
+import org.apache.hudi.common.config.ConfigProperty;
+import org.apache.hudi.common.engine.HoodieEngineContext;
+import org.apache.hudi.common.fs.FSUtils;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.marker.MarkerType;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.table.timeline.HoodieTimeline;
+import org.apache.hudi.common.util.MarkerUtils;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieException;
+import org.apache.hudi.table.HoodieTable;
+import org.apache.hudi.table.marker.DirectWriteMarkers;
+
+import com.esotericsoftware.minlog.Log;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import static org.apache.hudi.common.util.MarkerUtils.MARKERS_FILENAME_PREFIX;
+
+public abstract class BaseTwoToOneDowngradeHandler implements DowngradeHandler {
+
+  @Override
+  public Map<ConfigProperty, String> downgrade(HoodieWriteConfig config, HoodieEngineContext context, String instantTime) {
+    HoodieTable table = getTable(config, context);
+    HoodieTableMetaClient metaClient = table.getMetaClient();
+
+    // re-create marker files if any partial timeline server based markers are found
+    HoodieTimeline inflightTimeline = metaClient.getCommitsTimeline().filterPendingExcludingCompaction();
+    List<HoodieInstant> commits = inflightTimeline.getReverseOrderedInstants().collect(Collectors.toList());
+    for (HoodieInstant commitInstant : commits) {

Review comment:
       rename

##########
File path: hudi-common/src/main/java/org/apache/hudi/common/util/MarkerUtils.java
##########
@@ -216,4 +216,4 @@ public static void deleteMarkerTypeFile(FileSystem fileSystem, String markerDir)
       throw new HoodieIOException(ioe.getMessage(), ioe);
     }
   }
-}
+}

Review comment:
       pathStr.getPath().getName().startWith(MARKERS_FILENAME_PREFIX) seems like the right way to me. is there a place where we should change this

##########
File path: hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/hudi/HoodieSparkSqlWriter.scala
##########
@@ -118,7 +118,7 @@ object HoodieSparkSqlWriter {
     } else {
       // Handle various save modes
       handleSaveModes(sqlContext.sparkSession, mode, basePath, tableConfig, tblName, operation, fs)
-      val partitionColumns = HoodieWriterUtils.getPartitionColumns(keyGenerator)
+      val partitionColumns = HoodieSparkWriterUtils.getPartitionColumnsFromKeyGenerator(keyGenerator, toProperties(parameters))

Review comment:
       why change the name? you can just keep `getPartitionColumns()` given teh args are different anyway? encoding the arg type in the method name is a no-no in my book :) 

##########
File path: hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/BaseOneToZeroDowngradeHandler.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.upgrade;
+
+import org.apache.hudi.common.config.ConfigProperty;
+import org.apache.hudi.common.engine.HoodieEngineContext;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.table.timeline.HoodieTimeline;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.table.HoodieTable;
+import org.apache.hudi.table.marker.WriteMarkers;
+import org.apache.hudi.table.marker.WriteMarkersFactory;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public abstract class BaseOneToZeroDowngradeHandler implements DowngradeHandler {
+
+  @Override
+  public Map<ConfigProperty, String> downgrade(HoodieWriteConfig config, HoodieEngineContext context, String instantTime) {
+    // fetch pending commit info
+    HoodieTable table = getTable(config, context);
+    HoodieTimeline inflightTimeline = table.getMetaClient().getCommitsTimeline().filterPendingExcludingCompaction();
+    List<HoodieInstant> commits = inflightTimeline.getReverseOrderedInstants().collect(Collectors.toList());
+    for (HoodieInstant commitInstant : commits) {
+      // delete existing markers
+      WriteMarkers writeMarkers = WriteMarkersFactory.get(config.getMarkersType(), table, commitInstant.getTimestamp());
+      writeMarkers.quietDeleteMarkerDir(context, config.getMarkersDeleteParallelism());
+    }
+    return Collections.EMPTY_MAP;

Review comment:
       this means, nothing is getting added back to the properties right. 

##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/deltastreamer/DeltaSync.java
##########
@@ -249,7 +249,7 @@ public void refreshTimeline() throws IOException {
       }
     } else {
       this.commitTimelineOpt = Option.empty();
-      String partitionColumns = HoodieWriterUtils.getPartitionColumns(keyGenerator);
+      String partitionColumns = HoodieSparkWriterUtils.getPartitionColumnsFromKeyGenerator(keyGenerator, props);

Review comment:
       such a long name. :) lets just keep it short.

##########
File path: hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/BaseTwoToOneDowngradeHandler.java
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.upgrade;
+
+import org.apache.hudi.common.config.ConfigProperty;
+import org.apache.hudi.common.engine.HoodieEngineContext;
+import org.apache.hudi.common.fs.FSUtils;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.marker.MarkerType;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.table.timeline.HoodieTimeline;
+import org.apache.hudi.common.util.MarkerUtils;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieException;
+import org.apache.hudi.table.HoodieTable;
+import org.apache.hudi.table.marker.DirectWriteMarkers;
+
+import com.esotericsoftware.minlog.Log;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import static org.apache.hudi.common.util.MarkerUtils.MARKERS_FILENAME_PREFIX;
+
+public abstract class BaseTwoToOneDowngradeHandler implements DowngradeHandler {
+
+  @Override
+  public Map<ConfigProperty, String> downgrade(HoodieWriteConfig config, HoodieEngineContext context, String instantTime) {
+    HoodieTable table = getTable(config, context);
+    HoodieTableMetaClient metaClient = table.getMetaClient();
+
+    // re-create marker files if any partial timeline server based markers are found
+    HoodieTimeline inflightTimeline = metaClient.getCommitsTimeline().filterPendingExcludingCompaction();
+    List<HoodieInstant> commits = inflightTimeline.getReverseOrderedInstants().collect(Collectors.toList());
+    for (HoodieInstant commitInstant : commits) {
+      // Converts the markers in new format to old format of direct markers
+      try {
+        convertToDirectMarkers(
+            commitInstant.getTimestamp(), table, context, config.getMarkersDeleteParallelism());
+      } catch (IOException e) {
+        throw new HoodieException("Converting marker files to DIRECT style failed during downgrade", e);
+      }
+    }
+    return Collections.EMPTY_MAP;
+  }
+
+  abstract HoodieTable getTable(HoodieWriteConfig config, HoodieEngineContext context);
+
+  /**
+   * Converts the markers in new format(timeline server based) to old format of direct markers,
+   * i.e., one marker file per data file, without MARKERS.type file.
+   * This needs to be idempotent.
+   * 1. read all markers from timeline server based marker files
+   * 2. create direct style markers
+   * 3. delete marker type file
+   * 4. delete timeline server based marker files
+   *
+   * @param commitInstantTime instant of interest for marker conversion.
+   * @param table             instance of {@link HoodieTable} to use
+   * @param context           instance of {@link HoodieEngineContext} to use
+   * @param parallelism       parallelism to use
+   */
+  private void convertToDirectMarkers(final String commitInstantTime,
+                                      HoodieTable table,
+                                      HoodieEngineContext context,
+                                      int parallelism) throws IOException {
+    String markerDir = table.getMetaClient().getMarkerFolderPath(commitInstantTime);
+    FileSystem fileSystem = FSUtils.getFs(markerDir, context.getHadoopConf().newCopy());
+    Option<MarkerType> markerTypeOption = MarkerUtils.readMarkerType(fileSystem, markerDir);
+    if (markerTypeOption.isPresent()) {
+      switch (markerTypeOption.get()) {
+        case TIMELINE_SERVER_BASED:
+          // Reads all markers written by the timeline server
+          Map<String, Set<String>> markersMap =
+              MarkerUtils.readTimelineServerBasedMarkersFromFileSystem(
+                  markerDir, fileSystem, context, parallelism);
+          DirectWriteMarkers directWriteMarkers = new DirectWriteMarkers(table, commitInstantTime);
+          // Recreates the markers in the direct format
+          for (Set<String> markers : markersMap.values()) {
+            markers.forEach(directWriteMarkers::create);
+          }
+          // Delete marker type file
+          MarkerUtils.deleteMarkerTypeFile(fileSystem, markerDir);
+          // delete timeline server based markers
+          deleteTimelineBasedMarkerFiles(markerDir, fileSystem);
+          break;
+        default:
+          throw new HoodieException("The marker type \"" + markerTypeOption.get().name() + "\" is not supported.");
+      }
+    } else {
+      // incase of partial failures during downgrade, there is a chance that marker type file was deleted, but timeline server based marker files are left.
+      // so delete them if any
+      deleteTimelineBasedMarkerFiles(markerDir, fileSystem);

Review comment:
       this is okay, since only deletes the files with the prefix. so will not touch anything written using direct markers




-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org