You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "ArafatKhan2198 (via GitHub)" <gi...@apache.org> on 2024/10/29 08:25:36 UTC

[PR] HDDS-11615. Add Upgrade Action for Initial Schema Constraints for Unhealthy Container Table in Recon. [ozone]

ArafatKhan2198 opened a new pull request, #7372:
URL: https://github.com/apache/ozone/pull/7372

   ## What changes were proposed in this pull request?
   Description
   With Recon’s new schema versioning framework now integrated [HDDS-11465](https://issues.apache.org/jira/browse/HDDS-11465), it is essential to address initial schema constraints for existing tables. Previously, Recon lacked schema versioning, which meant there were no upgrade actions or mechanisms to adjust schema tables post-upgrade. This led to inconsistencies, especially when new enum states (like `MISSING` and `NEGATIVE_SIZE` in `UnHealthyContainerStates`) were introduced, as older schema versions might still persist despite upgrades.
   
   This ticket introduces a foundational upgrade action, InitialConstraintUpgradeAction, associated with the `INITIAL_VERSION` feature to handle any missed schema updates within the `UNHEALTHY_CONTAINERS` table. This upgrade action retroactively applies constraints and ensures all existing tables are correctly versioned. Moving forward, any updates or new metadata table introductions in Recon will be tracked and managed by version using the `ReconLayoutFeature` framework, enabling a structured upgrade process for future schema changes
   
   ## What is the link to the Apache JIRA
   https://issues.apache.org/jira/browse/HDDS-11615
   ## How was this patch tested?
   Manual Testing.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-11615. Add Upgrade Action for Initial Schema Constraints for Unhealthy Container Table in Recon. [ozone]

Posted by "sumitagrawl (via GitHub)" <gi...@apache.org>.
sumitagrawl commented on code in PR #7372:
URL: https://github.com/apache/ozone/pull/7372#discussion_r1822218459


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconUpgradeActionsModule.java:
##########
@@ -0,0 +1,17 @@
+package org.apache.hadoop.ozone.recon;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Singleton;
+import org.apache.hadoop.ozone.recon.upgrade.InitialConstraintUpgradeAction;
+
+/**
+ * Guice module for binding upgrade actions as singletons in Recon.
+ */
+public class ReconUpgradeActionsModule extends AbstractModule {
+
+  @Override
+  protected void configure() {
+    // Bind UpdateUnhealthyContainersConstraintAction as a singleton
+    bind(InitialConstraintUpgradeAction.class).in(Singleton.class);

Review Comment:
   This need not be registed / singleton, as used once only, can argument be passed ?



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-11615. Add Upgrade Action for Initial Schema Constraints for Unhealthy Container Table in Recon. [ozone]

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #7372:
URL: https://github.com/apache/ozone/pull/7372#issuecomment-2443556099

   Please wait for clean CI run in fork before opening PR.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-11615. Add Upgrade Action for Initial Schema Constraints for Unhealthy Container Table in Recon. [ozone]

Posted by "sumitagrawl (via GitHub)" <gi...@apache.org>.
sumitagrawl commented on code in PR #7372:
URL: https://github.com/apache/ozone/pull/7372#discussion_r1822178414


##########
hadoop-ozone/recon-codegen/src/main/java/org/hadoop/ozone/recon/schema/ContainerSchemaDefinition.java:
##########
@@ -70,18 +70,7 @@ public enum UnHealthyContainerStates {
   public void initializeSchema() throws SQLException {
     Connection conn = dataSource.getConnection();
     dslContext = DSL.using(conn);
-
     if (TABLE_EXISTS_CHECK.test(conn, UNHEALTHY_CONTAINERS_TABLE_NAME)) {

Review Comment:
   It should have "!" to if block while moving else part in if case.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-11615. Add Upgrade Action for Initial Schema Constraints for Unhealthy Container Table in Recon. [ozone]

Posted by "ArafatKhan2198 (via GitHub)" <gi...@apache.org>.
ArafatKhan2198 commented on PR #7372:
URL: https://github.com/apache/ozone/pull/7372#issuecomment-2467473856

   @devmadhuu @sumitagrawl can you please take a look!


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-11615. Add Upgrade Action for Initial Schema Constraints for Unhealthy Container Table in Recon. [ozone]

Posted by "devmadhuu (via GitHub)" <gi...@apache.org>.
devmadhuu commented on code in PR #7372:
URL: https://github.com/apache/ozone/pull/7372#discussion_r1832168823


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/upgrade/InitialConstraintUpgradeAction.java:
##########
@@ -0,0 +1,89 @@
+package org.apache.hadoop.ozone.recon.upgrade;
+
+import com.google.inject.Inject;
+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 final DataSource dataSource;
+  private DSLContext dslContext;
+
+  @Inject
+  public InitialConstraintUpgradeAction(DataSource dataSource) {
+    this.dataSource = dataSource;
+  }
+
+  @Override
+  public void execute() throws SQLException {
+    try (Connection conn = dataSource.getConnection()) {
+      if (!TABLE_EXISTS_CHECK.test(conn, UNHEALTHY_CONTAINERS_TABLE_NAME)) {
+        return;
+      }
+      dslContext = DSL.using(conn);
+      // Drop the existing constraint if it exists
+      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() {

Review Comment:
   You can remove the unused method `addUpdatedConstraint` from `ContainerSchemaDefinition` class.



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/upgrade/ReconLayoutVersionManager.java:
##########
@@ -47,12 +48,12 @@ public class ReconLayoutVersionManager {
   private int currentMLV;
 
   public ReconLayoutVersionManager(ReconSchemaVersionTableManager schemaVersionTableManager,

Review Comment:
   Also in this class while you finalize layout features here in `finalizeLayoutFeatures`, I found some edge case in old code when this layout framework was developed. After calling `execute` method of each action, we are updating the schema version in Recon SQL table. So both are in same try catch block and either of it can fail. If `execute` is success, but updating schema version fails, then also we are throwing the exception with log , but not reverting the action done by `execute`. So this is half baked inconsitency state of Recon. Pls check that part to make it robust.



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/upgrade/ReconLayoutVersionManager.java:
##########
@@ -47,12 +48,12 @@ public class ReconLayoutVersionManager {
   private int currentMLV;
 
   public ReconLayoutVersionManager(ReconSchemaVersionTableManager schemaVersionTableManager,
-                                   ReconContext reconContext)
+                                   ReconContext reconContext, Injector injector)

Review Comment:
   You need not to pass Injector reference here, as injector is only used to get instance once which you have binded in guice framework as Singleton. And those all `ReconUpgradeAction` classes will not be used in code flow anywhere. So impl classes of `ReconUpgradeAction` will be scanned using annotation and you can create instance of it there itself in your `registerUpgradeActions` scan code.



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconUpgradeActionsModule.java:
##########
@@ -0,0 +1,17 @@
+package org.apache.hadoop.ozone.recon;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Singleton;
+import org.apache.hadoop.ozone.recon.upgrade.InitialConstraintUpgradeAction;
+
+/**
+ * Guice module for binding upgrade actions as singletons in Recon.
+ */
+public class ReconUpgradeActionsModule extends AbstractModule {

Review Comment:
   You don't need this class because whatever action classes you will bind here, they are already being scanned using annotation.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-11615. Add Upgrade Action for Initial Schema Constraints for Unhealthy Container Table in Recon. [ozone]

Posted by "devmadhuu (via GitHub)" <gi...@apache.org>.
devmadhuu merged PR #7372:
URL: https://github.com/apache/ozone/pull/7372


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-11615. Add Upgrade Action for Initial Schema Constraints for Unhealthy Container Table in Recon. [ozone]

Posted by "ArafatKhan2198 (via GitHub)" <gi...@apache.org>.
ArafatKhan2198 commented on PR #7372:
URL: https://github.com/apache/ozone/pull/7372#issuecomment-2478383581

   Thanks for pointing out such a critical bug @devmadhuu, as discussed offline it would be better to address this in a separate JIRA - [HDDS-11716](https://issues.apache.org/jira/browse/HDDS-11716)
   It would be better to track it since its an important fix.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-11615. Add Upgrade Action for Initial Schema Constraints for Unhealthy Container Table in Recon. [ozone]

Posted by "ArafatKhan2198 (via GitHub)" <gi...@apache.org>.
ArafatKhan2198 commented on code in PR #7372:
URL: https://github.com/apache/ozone/pull/7372#discussion_r1843536428


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/upgrade/ReconLayoutVersionManager.java:
##########
@@ -47,12 +48,12 @@ public class ReconLayoutVersionManager {
   private int currentMLV;
 
   public ReconLayoutVersionManager(ReconSchemaVersionTableManager schemaVersionTableManager,

Review Comment:
   Will be addressed by :- https://issues.apache.org/jira/browse/HDDS-11716



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org