leesf commented on a change in pull request #940: [HUDI-130] Paths written in compaction plan needs to be relative to base-path URL: https://github.com/apache/incubator-hudi/pull/940#discussion_r331748507
########## File path: hudi-common/src/main/java/org/apache/hudi/common/model/version/MetadataMigrator.java ########## @@ -0,0 +1,104 @@ +/* + * 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.model.version; + +import com.google.common.base.Preconditions; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.common.util.collection.Pair; + +/** + * Migrates a specific metadata type stored in .hoodie folder to latest version + * @param <T> + */ +public class MetadataMigrator<T> { + + private final Map<Integer, VersionMigrator<T>> migrators; + private final Integer latestVersion; + private final Integer oldestVersion; + + public MetadataMigrator(HoodieTableMetaClient metaClient, List<VersionMigrator<T>> migratorList) { + migrators = migratorList.stream().map(m -> + Pair.of(m.getManagedVersion(), m)).collect(Collectors.toMap(Pair::getKey, Pair::getValue)); + latestVersion = migrators.keySet().stream().reduce((x, y) -> x > y ? x : y).get(); + oldestVersion = migrators.keySet().stream().reduce((x, y) -> x < y ? x : y).get(); + } + + /** + * Upgrade Metadata version to its latest + * @param metadata Metadata + * @param metadataVersion Current version of metadata + * @return + */ + public T upgradeToLatest(T metadata, int metadataVersion) { + if (metadataVersion == latestVersion) { + return metadata; + } + + int newVersion = metadataVersion + 1; + while (newVersion <= latestVersion) { + VersionMigrator<T> upgrader = migrators.get(newVersion); + metadata = upgrader.upgradeFrom(metadata); + newVersion += 1; + } + return metadata; + } + + /** + * Migrate metadata to a specific version + * @param metadata Hoodie Table Meta Client + * @param metadataVersion Metadata Version + * @param targetVersion Target Version + * @return Review comment: ditto ---------------------------------------------------------------- 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] With regards, Apache Git Services
