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


##########
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:
   After `stop()`, `omRatisServer` remains null here, so recovering across the 
QUOTA layout version with quota recalculation enabled (the default) makes 
`QuotaRepairUpgradeAction` call `checkLeaderStatus()` against a null Ratis 
server and aborts restart. Move the existing `initializeRatisServer(false)` 
call before this finalization call, while leaving Ratis startup after recovery. 
Add a restart regression test using the production upgrade actions.



##########
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:
   The regression is the missing startup invocation, but this test calls the 
already-existing helper directly. It therefore still passes if both new calls 
in `OzoneManager.start()` and `restart()` are removed. Please add a regression 
test that persists a DB version ahead of the VERSION file, starts/restarts OM 
without explicitly calling the helper, and verifies that the in-memory and 
persisted apparent versions advance to the DB version.



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