sodonnel commented on code in PR #12004: URL: https://github.com/apache/ozone/pull/12004#discussion_r4526815890
########## 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: I added a test for this. It takes about 10 seconds to run on my laptop. Sometimes I feel these sort of tests are not worth the ongoing overhead, but this one isn't too bad so its probably worth having it. -- 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]
