bvaradar commented on code in PR #11923:
URL: https://github.com/apache/hudi/pull/11923#discussion_r1821647351
##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestSevenToEightUpgrade.scala:
##########
@@ -34,10 +34,12 @@ class TestSevenToEightUpgrade extends
RecordLevelIndexTestBase {
@EnumSource(classOf[HoodieTableType])
def testPartitionFieldsWithUpgrade(tableType: HoodieTableType): Unit = {
val partitionFields = "partition:simple"
+ // Downgrade handling for metadata not yet ready.
val hudiOpts = commonOpts ++ Map(
DataSourceWriteOptions.TABLE_TYPE.key -> tableType.name(),
DataSourceWriteOptions.KEYGENERATOR_CLASS_NAME.key ->
KeyGeneratorType.CUSTOM.getClassName,
- DataSourceWriteOptions.PARTITIONPATH_FIELD.key -> partitionFields)
+ DataSourceWriteOptions.PARTITIONPATH_FIELD.key -> partitionFields,
+ "hoodie.metadata.enable" -> "false")
Review Comment:
Disabling metadata as the compatibility handling yet to be done.
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/EightToSevenDowngradeHandler.java:
##########
@@ -72,20 +81,43 @@ public Map<ConfigProperty, String>
downgrade(HoodieWriteConfig config, HoodieEng
HoodieTableMetaClient metaClient =
HoodieTableMetaClient.builder().setConf(context.getStorageConf().newInstance()).setBasePath(config.getBasePath()).build();
List<HoodieInstant> instants =
metaClient.getActiveTimeline().getInstants();
if (!instants.isEmpty()) {
+ InstantFileNameFactory instantFileNameFactory =
metaClient.getTimelineLayout().getInstantFileNameFactory();
+ CommitMetadataSerDeV2 commitMetadataSerDeV2 = new
CommitMetadataSerDeV2();
+ CommitMetadataSerDeV1 commitMetadataSerDeV1 = new
CommitMetadataSerDeV1();
+ ActiveTimelineV1 activeTimelineV1 = new ActiveTimelineV1(metaClient);
+ String tmpFilePrefix = "temp_commit_file_for_eight_to_seven_downgrade_";
context.map(instants, instant -> {
- if (instant.getFileName().contains(UNDERSCORE)) {
+ String fileName = instantFileNameFactory.getFileName(instant);
+ if (fileName.contains(UNDERSCORE)) {
try {
// Rename the metadata file name from the
${instant_time}_${completion_time}.action[.state] format in version 1.x to the
${instant_time}.action[.state] format in version 0.x.
- StoragePath fromPath = new StoragePath(metaClient.getMetaPath(),
instant.getFileName());
- StoragePath toPath = new StoragePath(metaClient.getMetaPath(),
instant.getFileName().replaceAll(UNDERSCORE + "\\d+", ""));
- boolean success = metaClient.getStorage().rename(fromPath, toPath);
+ StoragePath fromPath = new StoragePath(metaClient.getMetaPath(),
fileName);
+ StoragePath toPath = new StoragePath(metaClient.getMetaPath(),
fileName.replaceAll(UNDERSCORE + "\\d+", ""));
+ boolean success = true;
Review Comment:
Added logic to change commit metadata format to json when downgrading.
##########
hudi-common/src/main/java/org/apache/hudi/common/table/timeline/versioning/v1/CompletionTimeQueryViewV1.java:
##########
@@ -0,0 +1,239 @@
+/*
+ * 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.table.timeline.versioning.v1;
+
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.log.InstantRange;
+import org.apache.hudi.common.table.timeline.CompletionTimeQueryView;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.table.timeline.HoodieInstantTimeGenerator;
+import org.apache.hudi.common.table.timeline.HoodieTimeline;
+import org.apache.hudi.common.table.timeline.InstantComparatorUtils;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.VisibleForTesting;
+
+import java.io.Serializable;
+import java.time.Instant;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
+
+import static
org.apache.hudi.common.table.timeline.InstantComparatorUtils.GREATER_THAN_OR_EQUALS;
+import static
org.apache.hudi.common.table.timeline.InstantComparatorUtils.LESSER_THAN;
+
+public class CompletionTimeQueryViewV1 implements CompletionTimeQueryView,
Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private static final long MILLI_SECONDS_IN_THREE_DAYS = 3 * 24 * 3600 * 1000;
+
+ private static final long MILLI_SECONDS_IN_ONE_DAY = 24 * 3600 * 1000;
+
+ private final HoodieTableMetaClient metaClient;
+
+ /**
+ * Mapping from instant start time -> completion time.
+ * Should be thread-safe data structure.
+ */
+ private final ConcurrentMap<String, String> beginToCompletionInstantTimeMap;
+
+ /**
+ * The cursor instant time to eagerly load from, by default load last N days
of completed instants.
+ * It can grow dynamically with lazy loading. e.g. assuming an initial
cursor instant as t10,
+ * a completion query for t5 would trigger lazy loading with this cursor
instant updated to t5.
+ * This sliding window model amortizes redundant loading from different
queries.
+ */
+ private volatile String cursorInstant;
+
+ /**
+ * The first write instant on the active timeline, used for query
optimization.
+ */
+ private final String firstNonSavepointCommit;
+
+ /**
+ * The constructor.
+ *
+ * @param metaClient The table meta client.
+ */
+ public CompletionTimeQueryViewV1(HoodieTableMetaClient metaClient) {
+ this(metaClient, HoodieInstantTimeGenerator.formatDate(new
Date(Instant.now().minusMillis(MILLI_SECONDS_IN_THREE_DAYS).toEpochMilli())));
+ }
+
+ /**
+ * The constructor.
+ *
+ * @param metaClient The table meta client.
+ * @param eagerLoadInstant The earliest instant time to eagerly load from,
by default load last N days of completed instants.
+ */
+ public CompletionTimeQueryViewV1(HoodieTableMetaClient metaClient, String
eagerLoadInstant) {
+ this.metaClient = metaClient;
+ this.beginToCompletionInstantTimeMap = new ConcurrentHashMap<>();
+ this.cursorInstant = InstantComparatorUtils.minInstant(eagerLoadInstant,
metaClient.getActiveTimeline().firstInstant().map(HoodieInstant::getRequestTime).orElse(""));
+ // Note: use getWriteTimeline() to keep sync with the fs view
visibleCommitsAndCompactionTimeline, see
AbstractTableFileSystemView.refreshTimeline.
+ this.firstNonSavepointCommit =
metaClient.getActiveTimeline().getWriteTimeline().getFirstNonSavepointCommit().map(HoodieInstant::getRequestTime).orElse("");
+ load();
+ }
+
+ @Override
+ public boolean isCompleted(String beginInstantTime) {
+ // archival does not proceed beyond the first savepoint, so any instant
before that is completed.
+ return this.beginToCompletionInstantTimeMap.containsKey(beginInstantTime)
|| isArchived(beginInstantTime);
+ }
+
+ @Override
+ public boolean isArchived(String instantTime) {
+ return InstantComparatorUtils.compareTimestamps(instantTime, LESSER_THAN,
this.firstNonSavepointCommit);
+ }
+
+ @Override
+ public boolean isCompletedBefore(String baseInstant, String instantTime) {
+ Option<String> completionTimeOpt = getCompletionTime(baseInstant,
instantTime);
+ if (completionTimeOpt.isPresent()) {
+ return InstantComparatorUtils.compareTimestamps(completionTimeOpt.get(),
LESSER_THAN, baseInstant);
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isSlicedAfterOrOn(String baseInstant, String instantTime) {
+ Option<String> completionTimeOpt = getCompletionTime(baseInstant,
instantTime);
+ if (completionTimeOpt.isPresent()) {
+ return InstantComparatorUtils.compareTimestamps(completionTimeOpt.get(),
GREATER_THAN_OR_EQUALS, baseInstant);
+ }
+ return true;
+ }
+
+ @Override
+ public Option<String> getCompletionTime(String baseInstant, String
instantTime) {
+ Option<String> completionTimeOpt = getCompletionTime(instantTime);
+ if (completionTimeOpt.isPresent()) {
+ String completionTime = completionTimeOpt.get();
+ if (completionTime.length() != baseInstant.length()) {
+ // ==============================================================
+ // LEGACY CODE
+ // ==============================================================
+ // Fixes the completion time to reflect the completion sequence
correctly
+ // if the file slice base instant time is not in datetime format.
+ // For example, many test cases just use integer string as the instant
time.
+ // CAUTION: this fix only works for OCC(Optimistic Concurrency
Control).
+ // for NB-CC(Non-blocking Concurrency Control), the file slicing may
be incorrect.
+ return Option.of(instantTime);
+ }
+ }
+ return completionTimeOpt;
+ }
+
+ @Override
+ public Option<String> getCompletionTime(String beginTime) {
+ String completionTime =
this.beginToCompletionInstantTimeMap.get(beginTime);
+ if (completionTime != null) {
+ return Option.of(completionTime);
+ }
+
+ // ***This is the key change between V1 and V2 completion time
query-view***
+ if (isArchived(beginTime)) {
+ // Completion time and begin time are same for archived instants.
+ return Option.of(beginTime);
+ }
+ // the instant is still pending
+ return Option.empty();
+ }
+
+ @Override
+ public List<String> getInstantTimes(
+ HoodieTimeline timeline,
+ Option<String> rangeStart,
+ Option<String> rangeEnd,
+ InstantRange.RangeType rangeType) {
+ // assumes any instant/transaction lasts at most 1 day to optimize the
query efficiency.
+ return getInstantTimes(timeline, rangeStart, rangeEnd, rangeType, s ->
HoodieInstantTimeGenerator.instantTimeMinusMillis(s, MILLI_SECONDS_IN_ONE_DAY));
+ }
+
+ @Override
+ @VisibleForTesting
+ public List<String> getInstantTimes(
+ String rangeStart,
+ String rangeEnd,
+ Function<String, String> earliestInstantTimeFunc) {
+ return
getInstantTimes(metaClient.getCommitsTimeline().filterCompletedInstants(),
Option.ofNullable(rangeStart), Option.ofNullable(rangeEnd),
+ InstantRange.RangeType.CLOSED_CLOSED, earliestInstantTimeFunc);
+ }
+
+ /**
+ * Queries the instant start time with given completion time range.
+ *
+ * @param timeline The timeline.
+ * @param rangeStart The query range start completion time.
+ * @param rangeEnd The query range end completion time.
+ * @param rangeType The range type.
+ * @param earliestInstantTimeFunc The function to generate the earliest
start time boundary
+ * with the minimum completion time.
+ *
+ * @return The sorted instant time list.
+ */
+ private List<String> getInstantTimes(
+ HoodieTimeline timeline,
+ Option<String> rangeStart,
+ Option<String> rangeEnd,
+ InstantRange.RangeType rangeType,
+ Function<String, String> earliestInstantTimeFunc) {
+ throw new RuntimeException("Not Implemented Yet !");
Review Comment:
Incremental query view for V1 not yet implemented
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/config/HoodieWriteConfig.java:
##########
@@ -2872,8 +2874,9 @@ public Builder withSchemaEvolutionEnable(boolean enable) {
}
public Builder withWriteTableVersion(int writeVersion) {
- writeConfig.setValue(WRITE_TABLE_VERSION,
String.valueOf(HoodieTableVersion.fromVersionCode(writeVersion).versionCode()));
- return this;
+ HoodieTableVersion tableVersion =
HoodieTableVersion.fromVersionCode(writeVersion);
Review Comment:
Table Version and Timeline layout version needs to be consistent with each
other. Hence, setting the corresponding timeline layout version here.
--
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]