ArafatKhan2198 commented on code in PR #8070:
URL: https://github.com/apache/ozone/pull/8070#discussion_r2000413275


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/ContainerHealthSchemaManager.java:
##########
@@ -123,7 +126,26 @@ public void 
insertUnhealthyContainerRecords(List<UnhealthyContainers> recs) {
             rec.getContainerState());
       });
     }
-    unhealthyContainersDao.insert(recs);
+
+    try (Connection connection = 
containerSchemaDefinition.getDataSource().getConnection()) {
+      connection.setAutoCommit(false); // Turn off auto-commit for 
transactional control
+      for (UnhealthyContainers rec : recs) {
+        try {
+          unhealthyContainersDao.insert(rec);
+        } catch (DataAccessException dataAccessException) {
+          // Log the error and just update other fields of the existing record
+          // in case of ConstraintViolationException being actually thrown.
+          unhealthyContainersDao.update(rec);
+          LOG.error("Error while inserting unhealthy container record: {}", 
rec,

Review Comment:
   Would it be a good idea to log both the old record and the new record that 
we will override?
   Just a suggestion?
   
   ```
           // Fetch the existing record before updating
           UnhealthyContainers existingRecord = 
unhealthyContainersDao.get(rec.getContainerID());
           
           // Log both previous and new record details
           LOG.error("Duplicate entry detected for container ID {}. Updating 
existing record.\n"
                     + "Previous Record: {}\nNew Record: {}", 
                     rec.getContainerID(), existingRecord, rec);
           
           // Perform update
           unhealthyContainersDao.update(rec);
   ```



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/ContainerHealthSchemaManager.java:
##########
@@ -123,7 +126,26 @@ public void 
insertUnhealthyContainerRecords(List<UnhealthyContainers> recs) {
             rec.getContainerState());
       });
     }
-    unhealthyContainersDao.insert(recs);
+
+    try (Connection connection = 
containerSchemaDefinition.getDataSource().getConnection()) {
+      connection.setAutoCommit(false); // Turn off auto-commit for 
transactional control
+      for (UnhealthyContainers rec : recs) {

Review Comment:
   The patch logs the error inside the loop for each failed insert, which could 
lead to excessive logging if a large number of records fail ?
   



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