Upgrade: check systemvm template before db changes#4582
Conversation
|
@davidjumani @rhtyd |
|
@ustcweizhou isn't the whole db upgrade path wrapped in a transaction? I suppose the whole transaction would fail without committing anything to the DB? |
@rhtyd new system template is checked in performMigration. Before that, sql in script will be committed options are |
575cbcd to
7e9babc
Compare
DaanHoogland
left a comment
There was a problem hiding this comment.
good functionality, good code.
| 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(); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
can we put this in a separate method?
|
test proposal:
|
@DaanHoogland yes, exactly |
|
@DaanHoogland @rhtyd |
|
@blueorangutan package |
|
@shwstppr a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress. |
|
Packaging result: ✔centos7 ✔centos8 ✔debian. JID-2583 |
|
@blueorangutan test |
|
@DaanHoogland a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests |
|
jenkins build failed at point below. close/open this pr to retry. |
|
Trillian test result (tid-3413)
|
| s_logger.error(errorMessage, e); | ||
| throw new CloudRuntimeException(errorMessage, e); | ||
| } finally { | ||
| txn.close(); |
There was a problem hiding this 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
There was a problem hiding this 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 ?
There was a problem hiding this comment.
@weizhouapache I tested this by merging this code to master. However, the steps are equivalent to :
- Deploy a 4.14 env
- Register the template (4.15 template)
- upgrade to 4.15
- The Management server comes up fine, but, if we check the cloud.configuration value (in the DB) for attribute - "router.template." notice it doesn't update the template name to the new one.
The case of not applying the DB changes when template isn't registered, works absolutely fine.
There was a problem hiding this comment.
@Pearl1594 yeah, you are right !
pushed a change.
thanks for review and testing.
|
@blueorangutan package |
|
@rhtyd a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress. |
|
Packaging result: ✖centos7 ✖centos8 ✖debian. JID-2630 |
|
@blueorangutan package |
|
@Pearl1594 a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress. |
|
Packaging result: ✔centos7 ✖centos8 ✔debian. JID-2636 |
|
@blueorangutan package |
|
@rhtyd a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress. |
|
Packaging result: ✖centos7 ✖centos8 ✖debian. JID-2754 |
|
@blueorangutan package |
|
@shwstppr a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress. |
|
Packaging result: ✖centos7 ✔centos8 ✔debian. JID-2807 |
|
@blueorangutan package |
|
@rhtyd a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress. |
|
Packaging result: ✔centos7 ✔centos8 ✔debian. JID-2815 |
|
I think we don't need this as the upgrade was tested manually by @Pearl1594 . better safe though |
|
@DaanHoogland a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests |
|
Trillian test result (tid-3608)
|
|
|
||
| @Override | ||
| public void performDataMigration(Connection conn) { | ||
| updateSystemVmTemplates(conn); |
There was a problem hiding this comment.
+1 important thing to remember now is not to run this again
Description
Currently in upgrade cloudstack checks the systemvm template after db changes.
if user do not install systemvm template and uprgade cloudstack (for example install packages with newer version), upgrade will fail. in this case it will be very complicated to rollback the db if there is no db backup.
This pr checks the latest (only the last) systemvm template in upgrade path, and exits if required systemvm template is not registered.
Types of changes
Feature/Enhancement Scale or Bug Severity
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?