sumitagrawl commented on code in PR #8070:
URL: https://github.com/apache/ozone/pull/8070#discussion_r2003163338
##########
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);
Review Comment:
we need test behavior,
insert key1, insert key2 fails, update key2 success, --> so after commit, do
the data is available?
##########
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:
we may need add rollback in exception to close transaction
##########
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
Review Comment:
check if we need reset autoCommit to previous value
--
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]