-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Clean up backup references to their schedules when the schedules are deleted #12401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.22
Are you sure you want to change the base?
Clean up backup references to their schedules when the schedules are deleted #12401
Conversation
|
@blueorangutan package |
|
@bernardodemarco a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 4.22 #12401 +/- ##
=========================================
Coverage 17.59% 17.59%
- Complexity 15599 15600 +1
=========================================
Files 5910 5910
Lines 529733 529734 +1
Branches 64719 64720 +1
=========================================
+ Hits 93215 93218 +3
+ Misses 426025 426024 -1
+ Partials 10493 10492 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16319 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR addresses the cleanup of orphaned backup schedule references in the cloud.backups table. When backup schedules are deleted, backups created from those schedules retain references to non-existent schedule IDs. The PR implements proper cleanup by setting backup_schedule_id to NULL before deleting schedules, and also removes unused code and database columns.
Changes:
- Implements cleanup of backup schedule references before schedule deletion
- Removes unused
backup_interval_typecolumn fromcloud.backupstable - Refactors backup schedule response creation from DAO layer to API layer
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| engine/schema/src/main/resources/META-INF/db/schema-42200to42210.sql | Adds SQL to drop unused backup_interval_type column |
| engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupScheduleDaoImpl.java | Implements cleanup logic in remove() method and removes unused response builder |
| engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupScheduleDao.java | Removes unused interface methods |
| server/src/main/java/com/cloud/api/ApiDBUtils.java | Removes delegation method for backup schedule response creation |
| server/src/main/java/com/cloud/api/ApiResponseHelper.java | Moves backup schedule response creation logic from DAO to API layer |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public boolean remove(Long id) { | ||
| String sql = "UPDATE backups SET backup_schedule_id = NULL WHERE backup_schedule_id = ?"; | ||
| TransactionLegacy transaction = TransactionLegacy.currentTxn(); | ||
| try { | ||
| PreparedStatement preparedStatement = transaction.prepareAutoCloseStatement(sql); | ||
| preparedStatement.setLong(1, id); | ||
| preparedStatement.executeUpdate(); | ||
| return super.remove(id); | ||
| } catch (SQLException e) { | ||
| return false; | ||
| } |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SQLException is caught but not logged or handled beyond returning false. This makes debugging difficult if the cleanup fails. Consider logging the exception with details about which schedule ID failed to be cleaned up.
| try { | ||
| PreparedStatement preparedStatement = transaction.prepareAutoCloseStatement(sql); | ||
| preparedStatement.setLong(1, id); | ||
| preparedStatement.executeUpdate(); | ||
| return super.remove(id); | ||
| } catch (SQLException e) { |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the backup reference cleanup succeeds but super.remove(id) fails, the backups will have NULL schedule references but the schedule will still exist. Consider wrapping both operations in a transaction to ensure atomicity, or handle the super.remove() failure case separately.
| try { | |
| PreparedStatement preparedStatement = transaction.prepareAutoCloseStatement(sql); | |
| preparedStatement.setLong(1, id); | |
| preparedStatement.executeUpdate(); | |
| return super.remove(id); | |
| } catch (SQLException e) { | |
| transaction.start(); | |
| try { | |
| PreparedStatement preparedStatement = transaction.prepareAutoCloseStatement(sql); | |
| preparedStatement.setLong(1, id); | |
| preparedStatement.executeUpdate(); | |
| boolean removed = super.remove(id); | |
| if (!removed) { | |
| transaction.rollback(); | |
| return false; | |
| } | |
| transaction.commit(); | |
| return true; | |
| } catch (SQLException e) { | |
| transaction.rollback(); |
| CALL `cloud_usage`.`IDEMPOTENT_ADD_COLUMN`('cloud_usage.usage_volume','vm_id', 'bigint UNSIGNED NULL COMMENT "VM ID associated with the volume usage"'); | ||
|
|
||
| -- Drops the unused "backup_interval_type" column of the "cloud.backups" table | ||
| ALTER TABLE `cloud`.`backups` DROP COLUMN `backup_interval_type`; |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The migration lacks a safety check (e.g., IF EXISTS or conditional check) to prevent failures if the column has already been dropped in a previous migration attempt. Consider using a procedure or adding a check to ensure idempotency.
| ALTER TABLE `cloud`.`backups` DROP COLUMN `backup_interval_type`; | |
| ALTER TABLE `cloud`.`backups` DROP COLUMN IF EXISTS `backup_interval_type`; |
Description
Currently, the
cloud.backupstable references a backup schedule through thebackup_schedule_idfield. It is only populated when a backup is created from a schedule. For ad hoc backups, the field's value is kept asNULL.Additionally, when backup schedules are deleted via the
deleteBackupScheduleAPI, their corresponding entries are expunged from the DB. However, the backups' references to the schedules are not cleaned up and, thus, these references remain indefinitely in thecloud.backupstable. It is important to highlight that, although the clean up process is not performed, it does not cause any bugs/side effects.Therefore, this PR proposes to clean up such references before deleting backup schedules from the DB. The PR also cleans up some pieces of the code related with backup schedules, removing unused methods, moving methods' definitions to appropriate layers of the project and dropping the unused
backup_interval_typecolumn from thecloud.backupstable (see #11223).Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?