linyiqun commented on a change in pull request #1322:
URL: https://github.com/apache/hadoop-ozone/pull/1322#discussion_r478813083



##########
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;
+  }
+
+  public boolean isAllowed(LayoutFeature layoutFeature) {
+    return layoutFeature.layoutVersion() <= metadataLayoutVersion;

Review comment:
       I am looking into for this logic again. If new version is not finalized, 
metadataLayoutVersion will still older than new SLV = max(version(feature)), 
that means this new introduced features contained in new Ozone version cannot 
work until we do the finalize. But actually sometimes, some features can have a 
minimal compatible version, it can allow to run >=  minimal compatible MLV.
   
   For the first step implementation, we could make each minimal compatible MLV 
as their current layout version, like
   
   
     public enum OMLayoutFeature implements LayoutFeature {
       INITIAL_VERSION(0, 0, "Initial Layout Version"),
       CREATE_EC(1, 1, ""),
       NEW_FEATURE(2, 2, "new feature", new NewOmFeatureUpgradeAction());
   
   
       private int layoutVersion;
       private int minCompatLayoutVersion
   
   And then use minCompatLayoutVersion to do compatibility check.




----------------------------------------------------------------
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

Reply via email to