dombizita commented on code in PR #12004:
URL: https://github.com/apache/ozone/pull/12004#discussion_r4525331228


##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/upgrade/TestOMStartupWithDifferentApparentVersions.java:
##########
@@ -0,0 +1,206 @@
+/*
+ * 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.om.upgrade;
+
+import static org.apache.hadoop.ozone.OzoneConsts.APPARENT_VERSION_KEY;
+import static org.apache.hadoop.ozone.OzoneManagerVersion.SOFTWARE_VERSION;
+import static org.apache.hadoop.ozone.OzoneManagerVersion.ZDU;
+import static 
org.apache.hadoop.ozone.om.upgrade.OMLayoutFeature.INITIAL_VERSION;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.UUID;
+import org.apache.hadoop.hdds.ComponentVersion;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.OzoneManagerVersion;
+import org.apache.hadoop.ozone.om.OMConfigKeys;
+import org.apache.hadoop.ozone.om.OMStorage;
+import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * Ensures OM finalizes on startup when the DB records a higher apparent 
version than the VERSION file, and that it
+ * fails startup when the VERSION file records an apparent version that is 
larger than the software version.
+ */
+public class TestOMStartupWithDifferentApparentVersions {
+
+  @TempDir
+  private Path folder;
+
+  @Test
+  public void 
testStartupFailsWhenApparentVersionBeyondLastKnownComponentVersion() throws 
Exception {
+    assertStartupFailsWithInvalidVersionMessage(SOFTWARE_VERSION.serialize() + 
1);
+  }
+
+  /**
+   * An OM that stops after replacing its DB with a finalized checkpoint, but 
before updating its VERSION file, cannot
+   * replay the finalization from the Raft log, so it should finalize up to 
the version in its DB on restart.
+   */
+  @Test
+  public void testStartupFinalizesToApparentVersionInDB() throws Exception {
+    OzoneConfiguration conf = createOMStorage(INITIAL_VERSION.serialize());
+    try (OMVersionManager versionManager = createVersionManager(conf);
+        OmMetadataManagerImpl metadataManager = new 
OmMetadataManagerImpl(conf, null)) {
+      // Without a version in the DB, startup leaves the OM pre-finalized.
+      
assertThat(metadataManager.getMetaTable().get(APPARENT_VERSION_KEY)).isNull();
+      
assertThat(versionManager.getApparentVersion()).isEqualTo(INITIAL_VERSION);
+
+      // The DB is ahead of the VERSION file, as the interrupted install 
leaves it. The OM finalizes to the DB version.
+      // finalizeFromDBIfRequired is called by OM.start(), but calling that 
here keeps the test fast and self-contained,
+      // since starting OM requires SCM and other infrastructure.
+      metadataManager.getMetaTable().put(APPARENT_VERSION_KEY, 
String.valueOf(SOFTWARE_VERSION.serialize()));
+      versionManager.finalizeFromDBIfRequired(metadataManager.getMetaTable());

Review Comment:
   This looks valid too, there should be a test like cases in 
`TestOMUpgradeFinalization`.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java:
##########
@@ -2141,6 +2145,10 @@ public void restart() throws IOException {
 
     instantiateServices(false);
 
+    // If the OM stopped during a snapshot install after the DB was replaced, 
the VERSION file is behind the DB,
+    // and the finalization included in the snapshot is not in the Raft log to 
be replayed.
+    versionManager.finalizeFromDBIfRequired(metadataManager.getMetaTable());

Review Comment:
   This seems to be a valid scenario, it looks like the patch attached to the 
jira added this guard to the `QuotaRepairUpgradeAction`, but it makes more 
sense to me to move the the call after `initializeRatisServer(false)`.
   ```
   --- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/upgrade/QuotaRepairUpgradeAction.java
   +++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/upgrade/QuotaRepairUpgradeAction.java
   @@ -39,7 +39,10 @@ public void execute(OzoneManager arg) throws Exception {
        boolean enabled = arg.getConfiguration().getBoolean(
            OMConfigKeys.OZONE_OM_UPGRADE_QUOTA_RECALCULATE_ENABLE,
            OMConfigKeys.OZONE_OM_UPGRADE_QUOTA_RECALCULATE_ENABLE_DEFAULT);
   -    if (enabled) {
   +    if (enabled && arg.getOmRatisServer() == null) {
   +      // An OM that finalizes from its DB on startup has no Ratis server 
yet, so it is not the leader.
   +      LOG.warn("Skip quota repair operation during upgrade on the node as 
its Ratis server is not started yet.");
   +    } else if (enabled) {
          // just trigger quota repair and status can be checked via CLI
          try {
            arg.checkLeaderStatus();
   ```
   



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to