-
Notifications
You must be signed in to change notification settings - Fork 624
HDDS-14754. Add ZDU upgrade action to clean up leftover state #10889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
errose28
merged 5 commits into
apache:HDDS-14496-zdu
from
errose28:worktree/zdu-upgrade-action
Aug 3, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b926c35
Add ZDU upgrade actions
errose28 bf2c615
Update comment
errose28 9a98e4d
Add tests asserting crash behavior when upgrade actions fail to run o…
errose28 2542e2a
Add mocks for close
errose28 c63cfd5
Remove extra close mocks and try-with-resources
errose28 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...work/src/test/java/org/apache/hadoop/ozone/upgrade/TestAbstractUpgradeActionProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * 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 static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| import com.google.common.collect.ImmutableSet; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
| import org.apache.hadoop.hdds.ComponentVersion; | ||
| import org.apache.hadoop.hdds.upgrade.HDDSLayoutFeature; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Tests for {@link AbstractUpgradeActionProvider#load()}. | ||
| */ | ||
| class TestAbstractUpgradeActionProvider { | ||
|
|
||
| /** | ||
| * An upgrade action whose no-arg constructor fails to instantiate must abort {@code load()} rather than | ||
| * silently drop the action from the returned map, which would finalize its version as a no-op. | ||
| */ | ||
| @Test | ||
| public void testLoadFailsWhenActionCannotBeInstantiated() { | ||
| assertThrows(IllegalStateException.class, () -> new ThrowingActionProvider().load()); | ||
| } | ||
|
|
||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target(ElementType.TYPE) | ||
| private @interface TestUpgradeAction { | ||
| } | ||
|
|
||
| private interface TestAction extends UpgradeAction<Object> { | ||
| } | ||
|
|
||
| @TestUpgradeAction | ||
| public static class ThrowingTestAction implements TestAction { | ||
| ThrowingTestAction() { | ||
| throw new IllegalArgumentException("cannot construct test upgrade action"); | ||
| } | ||
|
|
||
| @Override | ||
| public void execute(Object arg) { | ||
| } | ||
| } | ||
|
|
||
| private static final class ThrowingActionProvider extends AbstractUpgradeActionProvider<TestAction> { | ||
| ThrowingActionProvider() { | ||
| super(ImmutableSet.of(TestUpgradeAction.class), TestAction.class, | ||
| TestAbstractUpgradeActionProvider.class.getPackage().getName()); | ||
| } | ||
|
|
||
| @Override | ||
| protected ComponentVersion extractVersion(Class<?> clazz) { | ||
| return HDDSLayoutFeature.INITIAL_VERSION; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...a/org/apache/hadoop/hdds/scm/server/upgrade/TestClearFinalizingStateScmUpgradeAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * 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.hdds.scm.server.upgrade; | ||
|
|
||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import org.apache.hadoop.hdds.scm.ha.SCMHAManager; | ||
| import org.apache.hadoop.hdds.scm.metadata.DBTransactionBuffer; | ||
| import org.apache.hadoop.hdds.scm.metadata.SCMMetadataStore; | ||
| import org.apache.hadoop.hdds.scm.server.StorageContainerManager; | ||
| import org.apache.hadoop.hdds.utils.db.Table; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Unit tests for {@link ClearFinalizingStateScmUpgradeAction}. | ||
| */ | ||
| class TestClearFinalizingStateScmUpgradeAction { | ||
|
|
||
| private static final String LEGACY_FINALIZING_KEY = "#FINALIZING"; | ||
|
|
||
| @Test | ||
| void testRemovesFinalizingKey() throws Exception { | ||
| @SuppressWarnings("unchecked") | ||
| Table<String, String> metaTable = mock(Table.class); | ||
| DBTransactionBuffer buffer = mock(DBTransactionBuffer.class); | ||
|
|
||
| SCMMetadataStore metadataStore = mock(SCMMetadataStore.class); | ||
| when(metadataStore.getMetaTable()).thenReturn(metaTable); | ||
|
|
||
| SCMHAManager haManager = mock(SCMHAManager.class); | ||
| when(haManager.getDBTransactionBuffer()).thenReturn(buffer); | ||
|
|
||
| StorageContainerManager scm = mock(StorageContainerManager.class); | ||
| when(scm.getScmMetadataStore()).thenReturn(metadataStore); | ||
| when(scm.getScmHAManager()).thenReturn(haManager); | ||
|
|
||
| new ClearFinalizingStateScmUpgradeAction().execute(scm); | ||
|
|
||
| verify(buffer).removeFromBuffer(metaTable, LEGACY_FINALIZING_KEY); | ||
| } | ||
|
|
||
| @Test | ||
| void testIdempotent() throws Exception { | ||
| // removeFromBuffer on an absent key is a no-op; call execute twice and expect no exception. | ||
| @SuppressWarnings("unchecked") | ||
| Table<String, String> metaTable = mock(Table.class); | ||
| DBTransactionBuffer buffer = mock(DBTransactionBuffer.class); | ||
|
|
||
| SCMMetadataStore metadataStore = mock(SCMMetadataStore.class); | ||
| when(metadataStore.getMetaTable()).thenReturn(metaTable); | ||
|
|
||
| SCMHAManager haManager = mock(SCMHAManager.class); | ||
| when(haManager.getDBTransactionBuffer()).thenReturn(buffer); | ||
|
|
||
| StorageContainerManager scm = mock(StorageContainerManager.class); | ||
| when(scm.getScmMetadataStore()).thenReturn(metadataStore); | ||
| when(scm.getScmHAManager()).thenReturn(haManager); | ||
|
|
||
| ClearFinalizingStateScmUpgradeAction action = new ClearFinalizingStateScmUpgradeAction(); | ||
| action.execute(scm); | ||
| action.execute(scm); | ||
|
|
||
| // Called twice, once per execution. | ||
| verify(buffer, org.mockito.Mockito.times(2)).removeFromBuffer(metaTable, LEGACY_FINALIZING_KEY); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...r/src/main/java/org/apache/hadoop/ozone/om/upgrade/ClearPreparedStateOmUpgradeAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * 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.OzoneManagerVersion.ZDU; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import org.apache.hadoop.hdds.server.ServerUtils; | ||
| import org.apache.hadoop.ozone.common.Storage; | ||
| import org.apache.hadoop.ozone.om.OzoneManager; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Removes leftover OM "prepare for upgrade" state written by pre-ZDU code. | ||
| * It is idempotent (delete-if-exists), so it is a no-op on clusters that were never prepared and | ||
| * on fresh ZDU clusters that never finalize. | ||
| */ | ||
| @OmUpgradeActionForVersion(version = ZDU) | ||
| public class ClearPreparedStateOmUpgradeAction implements OmUpgradeAction { | ||
| private static final Logger LOG = LoggerFactory.getLogger(ClearPreparedStateOmUpgradeAction.class); | ||
|
|
||
| // On-disk marker written by pre-ZDU OM prepare code; removed on ZDU finalization. | ||
| private static final String LEGACY_PREPARE_MARKER = "prepareMarker"; | ||
| // transactionInfoTable key written by pre-ZDU OM prepare code. | ||
| private static final String LEGACY_PREPARE_MARKER_KEY = "#PREPAREDINFO"; | ||
|
|
||
| @Override | ||
| public void execute(OzoneManager om) throws Exception { | ||
| // Reproduces the removed getPrepareMarkerFile() logic: <metadata dir>/current/prepareMarker. | ||
| File markerDir = new File(ServerUtils.getOzoneMetaDirPath(om.getConfiguration()), | ||
| Storage.STORAGE_DIR_CURRENT); | ||
| File marker = new File(markerDir, LEGACY_PREPARE_MARKER); | ||
| if (marker.exists()) { | ||
| if (!marker.delete()) { | ||
| throw new IOException("Failed to delete leftover OM prepare marker file " + marker); | ||
| } | ||
| LOG.info("Deleted leftover OM prepare marker file {}", marker); | ||
| } | ||
|
|
||
| // Direct RocksDB delete of the orphan prepare key, mirroring the removed startup cleanup. | ||
| om.getMetadataManager().getTransactionInfoTable().delete(LEGACY_PREPARE_MARKER_KEY); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is really unlikely to happen, but this is different from SCM, to throw this exception. If this happens the marker file deletion won't happen until finalization called again? Will the finalization fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally OM and SCM should crash if there is an error during finalization. We can't have the ratis group in a mixed finalization state. The existing tests only check that an exception is propagated out of the version manager, but it looks like neither component will actually crash. I'll add this to the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turns out OM and SCM were crashing if upgrade actions failed, because an
UpgradeExceptionis mapped to anINTERNAL_ERRORresult code which will crash each service. I added tests for this, although they look different due to the differences in how Ratis requests are processed on each service.DNs are expected to keep retrying finalization as instructed by SCM, since they do not need to match with a quorum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also added and tested that failure to load an upgrade action will throw an unchecked exception. Previously it was just logging an error which could result in a misconfigured upgrade action not running.