-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-11615. Add Upgrade Action for Initial Schema Constraints for Unhealthy Container Table in Recon. #7372
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d5f4138
HDDS-11615. Add Upgrade Action for Initial Schema Constraints for Unh…
ArafatKhan2198 38af4e9
Removed the usage of injector for the upgrade action
ArafatKhan2198 c1f0ba5
Fixed review comments
ArafatKhan2198 4909708
Fixed checkstyle issues and also added unit tests
ArafatKhan2198 240901f
Fixed failing UT
ArafatKhan2198 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
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
114 changes: 114 additions & 0 deletions
114
...n/src/main/java/org/apache/hadoop/ozone/recon/upgrade/InitialConstraintUpgradeAction.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,114 @@ | ||
| /* | ||
| * 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.recon.upgrade; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import org.apache.hadoop.ozone.recon.scm.ReconStorageContainerManagerFacade; | ||
| import org.hadoop.ozone.recon.schema.ContainerSchemaDefinition; | ||
| import org.jooq.DSLContext; | ||
| import org.jooq.impl.DSL; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import javax.sql.DataSource; | ||
| import java.sql.Connection; | ||
| import java.sql.SQLException; | ||
| import java.util.Arrays; | ||
|
|
||
| import static org.apache.hadoop.ozone.recon.upgrade.ReconLayoutFeature.INITIAL_VERSION; | ||
| import static org.apache.hadoop.ozone.recon.upgrade.ReconUpgradeAction.UpgradeActionType.FINALIZE; | ||
| import static org.hadoop.ozone.recon.codegen.SqlDbUtils.TABLE_EXISTS_CHECK; | ||
| import static org.hadoop.ozone.recon.schema.ContainerSchemaDefinition.UNHEALTHY_CONTAINERS_TABLE_NAME; | ||
| import static org.jooq.impl.DSL.field; | ||
| import static org.jooq.impl.DSL.name; | ||
|
|
||
| /** | ||
| * Upgrade action for the INITIAL schema version, which manages constraints | ||
| * for the UNHEALTHY_CONTAINERS table. | ||
| */ | ||
| @UpgradeActionRecon(feature = INITIAL_VERSION, type = FINALIZE) | ||
| public class InitialConstraintUpgradeAction implements ReconUpgradeAction { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(InitialConstraintUpgradeAction.class); | ||
| private DataSource dataSource; | ||
| private DSLContext dslContext; | ||
|
|
||
| @Override | ||
| public void execute(ReconStorageContainerManagerFacade scmFacade) throws SQLException { | ||
| this.dataSource = scmFacade.getDataSource(); | ||
| try (Connection conn = dataSource.getConnection()) { | ||
| if (!TABLE_EXISTS_CHECK.test(conn, UNHEALTHY_CONTAINERS_TABLE_NAME)) { | ||
| return; | ||
| } | ||
| dslContext = DSL.using(conn); | ||
| // Drop the existing constraint | ||
| dropConstraint(); | ||
| // Add the updated constraint with all enum states | ||
| addUpdatedConstraint(); | ||
| } catch (SQLException e) { | ||
| throw new SQLException("Failed to execute InitialConstraintUpgradeAction", e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Drops the existing constraint from the UNHEALTHY_CONTAINERS table. | ||
| */ | ||
| private void dropConstraint() { | ||
| String constraintName = UNHEALTHY_CONTAINERS_TABLE_NAME + "ck1"; | ||
| dslContext.alterTable(UNHEALTHY_CONTAINERS_TABLE_NAME) | ||
| .dropConstraint(constraintName) | ||
| .execute(); | ||
| LOG.debug("Dropped the existing constraint: {}", constraintName); | ||
| } | ||
|
|
||
| /** | ||
| * Adds the updated constraint directly within this class. | ||
| */ | ||
| private void addUpdatedConstraint() { | ||
| String[] enumStates = Arrays | ||
| .stream(ContainerSchemaDefinition.UnHealthyContainerStates.values()) | ||
| .map(Enum::name) | ||
| .toArray(String[]::new); | ||
|
|
||
| dslContext.alterTable(ContainerSchemaDefinition.UNHEALTHY_CONTAINERS_TABLE_NAME) | ||
| .add(DSL.constraint(ContainerSchemaDefinition.UNHEALTHY_CONTAINERS_TABLE_NAME + "ck1") | ||
| .check(field(name("container_state")) | ||
| .in(enumStates))) | ||
| .execute(); | ||
|
|
||
| LOG.info("Added the updated constraint to the UNHEALTHY_CONTAINERS table for enum state values: {}", | ||
| Arrays.toString(enumStates)); | ||
| } | ||
|
|
||
| @Override | ||
| public UpgradeActionType getType() { | ||
| return FINALIZE; | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| public void setDataSource(DataSource dataSource) { | ||
| this.dataSource = dataSource; | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| public void setDslContext(DSLContext dslContext) { | ||
| this.dslContext = dslContext; | ||
| } | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.