devmadhuu commented on code in PR #8070:
URL: https://github.com/apache/ozone/pull/8070#discussion_r2003759040
##########
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.debug("Error while inserting unhealthy container record: {}",
rec,
+ dataAccessException);
+ }
+ }
+ // Commit all the records inserted and updated.
+ connection.commit();
+ } catch (Exception e) {
+ LOG.error("Failed to get connection over {} ",
UNHEALTHY_CONTAINERS_TABLE_NAME, e);
Review Comment:
Done
--
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]