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


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/upgrade/ReconLayoutVersionManager.java:
##########
@@ -84,26 +85,41 @@ public void 
finalizeLayoutFeatures(ReconStorageContainerManagerFacade scmFacade)
     List<ReconLayoutFeature> featuresToFinalize = getRegisteredFeatures();
 
     for (ReconLayoutFeature feature : featuresToFinalize) {
-      try {
-        // Fetch only the FINALIZE action for the feature
-        Optional<ReconUpgradeAction> action = 
feature.getAction(ReconUpgradeAction.UpgradeActionType.FINALIZE);
-        if (action.isPresent()) {
-          // Execute the upgrade action & update the schema version in the DB
-          action.get().execute(scmFacade);
-          updateSchemaVersion(feature.getVersion());
-          LOG.info("Feature versioned {} finalized successfully.", 
feature.getVersion());
+      try (Connection connection = scmFacade.getDataSource().getConnection()) {
+        connection.setAutoCommit(false); // Turn off auto-commit for 
transactional control
+
+        try {
+          // Fetch only the FINALIZE action for the feature
+          Optional<ReconUpgradeAction> action = 
feature.getAction(ReconUpgradeAction.UpgradeActionType.FINALIZE);
+          if (action.isPresent()) {
+            // Update the schema version in the database
+            updateSchemaVersion(feature.getVersion(), connection);
+
+            // Execute the upgrade action
+            action.get().execute(scmFacade);
+
+            // Commit the transaction only if both operations succeed
+            connection.commit();
+            LOG.info("Feature versioned {} finalized successfully.", 
feature.getVersion());
+          }
+        } catch (Exception e) {
+          // Rollback any pending changes for the current feature due to 
failure
+          connection.rollback();

Review Comment:
   Although Apache Derby automatically rolls back uncommitted transactions on 
connection closure, explicitly calling connection.rollback() ensures 
future-proofing against database changes, maintains clear intent in the code, 
and immediately releases resources like locks making our code more robust.
   
   @devmadhuu 



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