avijayanhwx commented on a change in pull request #1322: URL: https://github.com/apache/hadoop-ozone/pull/1322#discussion_r478578045
########## File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/upgrade/AbstractLayoutVersionManager.java ########## @@ -0,0 +1,110 @@ +/** + * 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.hadoop.ozone.upgrade; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Optional; +import java.util.TreeMap; + +import com.google.common.base.Preconditions; + +/** + * Layout Version Manager containing generic method implementations. + */ +@SuppressWarnings("visibilitymodifier") +public abstract class AbstractLayoutVersionManager implements + LayoutVersionManager { + + protected int metadataLayoutVersion; // MLV. + protected int softwareLayoutVersion; // SLV. + protected TreeMap<Integer, LayoutFeature> features = new TreeMap<>(); + protected Map<String, LayoutFeature> featureMap = new HashMap<>(); + protected volatile boolean isInitialized = false; + + protected void init(int version, LayoutFeature[] lfs) { + if (!isInitialized) { + metadataLayoutVersion = version; + initializeFeatures(lfs); + softwareLayoutVersion = features.lastKey(); + isInitialized = true; + } + } + + protected void initializeFeatures(LayoutFeature[] lfs) { + Arrays.stream(lfs).forEach(f -> { + Preconditions.checkArgument(!featureMap.containsKey(f.name())); + Preconditions.checkArgument(!features.containsKey(f.layoutVersion())); + features.put(f.layoutVersion(), f); + featureMap.put(f.name(), f); + }); + } + + public int getMetadataLayoutVersion() { + return metadataLayoutVersion; + } + + public int getSoftwareLayoutVersion() { + return softwareLayoutVersion; + } + + public boolean needsFinalization() { + return metadataLayoutVersion < softwareLayoutVersion; Review comment: In the v2 Upgrade doc, we were talking about LFV (Last Finalized Version) in terms of handling the Ratis "Apply Transaction" changes. For the first version, since we are adding 'Apply Transaction' changes also as Layout Features, we do not need that. Based on how often apply transaction changes are needed, in the next version of implementation, we can maintain "software version" separately from metadata layout version. The only extra added benefit for that is that we can support downgrades with just apply transaction changes, and no layout version changes. ---------------------------------------------------------------- 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: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: ozone-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org