You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2021/02/01 10:19:36 UTC

[GitHub] [cloudstack] weizhouapache commented on a change in pull request #4582: Upgrade: check systemvm template before db changes

weizhouapache commented on a change in pull request #4582:
URL: https://github.com/apache/cloudstack/pull/4582#discussion_r567708383



##########
File path: engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java
##########
@@ -232,11 +233,41 @@ protected void runScript(Connection conn, InputStream file) {
 
     }
 
+    private void updateSystemVmTemplates(DbUpgrade[] upgrades) {
+        for (int i = upgrades.length - 1; i >= 0; i--) {
+            DbUpgrade upgrade = upgrades[i];
+            if (upgrade instanceof DbUpgradeSystemVmTemplate) {
+                TransactionLegacy txn = TransactionLegacy.open("Upgrade");
+                txn.start();
+                try {
+                    Connection conn;
+                    try {
+                        conn = txn.getConnection();
+                    } catch (SQLException e) {
+                        String errorMessage = "Unable to upgrade the database";
+                        s_logger.error(errorMessage, e);
+                        throw new CloudRuntimeException(errorMessage, e);
+                    }
+                    ((DbUpgradeSystemVmTemplate)upgrade).updateSystemVmTemplates(conn);
+                    break;
+                } catch (CloudRuntimeException e) {
+                    String errorMessage = "Unable to upgrade the database";
+                    s_logger.error(errorMessage, e);
+                    throw new CloudRuntimeException(errorMessage, e);
+                } finally {
+                    txn.close();

Review comment:
       > @ustcweizhou I believe there's a need to do a txn.commit() before closing the transaction as the DB changes made as part of the updateSystemVmTemplate() gets rolled back
   > 
   > ```
   > Rolling back the transaction: Time = 22 Name =  Upgrade; called by -TransactionLegacy.rollback:888-TransactionLegacy.removeUpTo:831-TransactionLegacy.close:655-DatabaseUpgradeChecker.updateSystemVmTemplates:264-DatabaseUpgradeChecker.upgrade:275-DatabaseUpgradeChecker.check:379-CloudStackExtendedLifeCycle.checkIntegrity:64-CloudStackExtendedLifeCycle.start:54-DefaultLifecycleProcessor.doStart:182-DefaultLifecycleProcessor.access$200:53-DefaultLifecycleProcessor$LifecycleGroup.start:360-DefaultLifecycleProcessor.startBeans:158
   > 2021-02-01 09:50:57,795 DEBUG [c.c.u.DatabaseUpgradeChecker] (main:null) (logid:) Running upgrade Upgrade41500to41510 to upgrade from 4.15.0.0-4.15.1.0 to 4.15.1.0
   > ```
   
   @Pearl1594 thanks for testing.
   could you tell how to reproduce the issue ?
   




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org