ArafatKhan2198 commented on PR #7149:
URL: https://github.com/apache/ozone/pull/7149#issuecomment-2342636455

   I needed to ensure that the code for altering the table works correctly.
   
   - For testing purposes, I made some changes to the code where I drop the 
existing constraint and add a new one that allows all unhealthy container 
states except MISSING. Please note, the removal of the MISSING container state 
is temporary and only for testing purposes; I will add it back later.
   - The reason for this test is that, during the initial load, Recon creates a 
schema that accepts all container states.
   - Upon restarting Recon, it checks if the table exists. Since the table will 
already exist after the initial load, the system will drop the current 
constraint and add a new one where the MISSING container state is excluded for 
testing purposes.
   
   - Below are the code changes I made to the method:
   
   ```
     private void addUpdatedConstraint() {
       // Get all enum values as a list of strings
       String[] enumStates = Arrays.stream(UnHealthyContainerStates.values())
           .map(Enum::name)
           .filter(state -> !state.equals("MISSING"))  // Exclude MISSING for 
testing
           .toArray(String[]::new);
   
       LOG.info("Adding updated constraint with states: {}", 
Arrays.toString(enumStates));
   
       // Alter the table to add the updated constraint
       dslContext.alterTable(UNHEALTHY_CONTAINERS_TABLE_NAME)
           .add(DSL.constraint(UNHEALTHY_CONTAINERS_TABLE_NAME + "ck1")
               .check(field(name("container_state"))
                   .in(enumStates)))
           .execute();
     }
     
   ```
   To test this, I simulated MISSING containers in Recon by creating a 
container and then stopping all the datanodes, which triggers the MISSING 
container scenario.
   When Recon attempted to add these MISSING container records to the 
unhealthyContainerTable, it failed and threw a constraint violation error, 
confirming that our code works correctly.
   
   ```
   2024-09-10 18:09:23 2024-09-10 12:39:23,070 
[Recon-EventQueue-DeadNodeForReconDeadNodeHandler] ERROR 
scm.ReconDeadNodeHandler: Error trying to verify Node operational state from 
SCM.
   2024-09-10 18:09:23 org.jooq.exception.DataAccessException: SQL [insert into 
"UNHEALTHY_CONTAINERS" ("container_id", "container_state", "in_state_since", 
"expected_replica_count", "actual_replica_count", "replica_delta", "reason") 
values (cast(? as bigint), cast(? as varchar(32672)), cast(? as bigint), cast(? 
as int), cast(? as int), cast(? as int), cast(? as varchar(32672)))]; The check 
constraint 'UNHEALTHY_CONTAINERSck1' was violated while performing an INSERT or 
UPDATE on table '"RECON"."UNHEALTHY_CONTAINERS"'.
   ```
   
   This error shows that the `MISSING` container state is not allowed, as 
expected, confirming that the new constraint works correctly. I will later 
reintroduce the MISSING container state into the list once testing is complete


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