Skip to content

Template cleanup : Update vm_template table to set template as removed on deletion - #4748

Merged
yadvr merged 6 commits into
apache:4.15from
shapeblue:4.15-cleanup-temp
Mar 24, 2021
Merged

yadvr merged 6 commits into
apache:4.15from
shapeblue:4.15-cleanup-temp

Conversation

@Pearl1594

@Pearl1594 Pearl1594 commented Mar 4, 2021 •

Copy link
Copy Markdown
Contributor

Description

Addresses: #4470
This PR fixes the issue noticed while deleting a template in a zone and also adds cleanup, in order to remove such templates left behind. The following is currently observed currently:
In a Zone with only 1 store:

  • when a template (private/public) is deleted, the template is marked as Inactive, but not removed
    In a Zone with > 1 store:
  • when a private template is deleted, the template is marked as Inactive, but not removed. For eg, after deletion, the following is observed:
MariaDB [cloud]> select id,type,name,uuid,format,public,size,state,created,removed from vm_template where id =204\G
*************************** 1. row ***************************
     id: 204
   type: USER
   name: template-private-2storesZone
   uuid: d899e386-fd23-4c8b-9834-9cac9cd6febe
 format: QCOW2
 public: 0
   size: 52428800
  state: Inactive
created: 2021-03-04 06:09:22
removed: NULL
1 row in set (0.00 sec)

MariaDB [cloud]> select id,template_id,store_id,created,state,size,store_role,install_path from template_store_ref where template_id =204\G
*************************** 1. row ***************************
          id: 18
 template_id: 204
    store_id: 1
     created: 2021-03-04 06:09:22
       state: Destroyed
        size: 52428800
  store_role: Image
install_path: template/tmpl/2/204/1ba40914-9eba-33de-93b0-8c05ea6fc753.qcow2
1 row in set (0.01 sec)
  • When a public template is deleted, the templates are set as destroyed on the secondary store (template_store_ref), but it continues to be marked as Active in the vm_template table. For example, On deletion:
MariaDB [cloud]> select id,type,name,uuid,format,public,size,state,created,removed from vm_template where id =205\G
*************************** 1. row ***************************
     id: 205
   type: USER
   name: template-public-2storesZone
   uuid: 25cbaa26-d114-46d7-8285-cb1180fb5cee
 format: QCOW2
 public: 1
   size: 52428800
  state: Active
created: 2021-03-04 06:11:52
removed: NULL
1 row in set (0.00 sec)

MariaDB [cloud]> select id,template_id,store_id,created,state,size,store_role,install_path from template_store_ref where template_id =205\G
*************************** 1. row ***************************
          id: 19
 template_id: 205
    store_id: 2
     created: 2021-03-04 06:11:52
       state: Destroyed
        size: 52428800
  store_role: Image
install_path: template/tmpl/2/205/848ef57e-80a3-3b79-a8c9-a7ef7316165a.qcow2
*************************** 2. row ***************************
          id: 20
 template_id: 205
    store_id: 1
     created: 2021-03-04 06:11:52
       state: Destroyed
        size: 52428800
  store_role: Image
install_path: template/tmpl/2/205/40db7f18-3d06-3527-b7f3-6db5811a3121.qcow2
2 rows in set (0.01 sec)

Notice template still appears Active when destroyed on secondary store

Post fix: On deletion of a public template registered in a zone with > 1 image store (here, 2)

MariaDB [cloud]> select id,type,name,uuid,format,public,size,state,created,removed from vm_template where id =208\G
*************************** 1. row ***************************
     id: 208
   type: USER
   name: template-public-2storesPostFix
   uuid: 2e60aba8-4daf-4dee-9626-d78ccaeca158
 format: QCOW2
 public: 1
   size: 52428800
  state: Inactive
created: 2021-03-04 07:14:37
removed: 2021-03-04 07:16:01
1 row in set (0.00 sec)

MariaDB [cloud]> select id,template_id,store_id,created,state,size,store_role,install_path from template_store_ref where template_id =208\G
*************************** 1. row ***************************
          id: 24
 template_id: 208
    store_id: 1
     created: 2021-03-04 07:14:37
       state: Destroyed
        size: 52428800
  store_role: Image
install_path: template/tmpl/2/208/38b47a1b-7e92-3851-952b-99b9e898b268.qcow2
*************************** 2. row ***************************
          id: 25
 template_id: 208
    store_id: 2
     created: 2021-03-04 07:14:37
       state: Destroyed
        size: 52428800
  store_role: Image
install_path: template/tmpl/2/208/8f30693b-c3a7-3f68-be23-dc3f0ced082e.qcow2
2 rows in set (0.00 sec)

With this patch, when the cleanup job is triggered, it also cleans up all templates that are marked as Inactive but not removed (reduced the cleanup interval by modifying the following global settings: storage.cleanup.interval and storage.cleanup.delay)

MariaDB [cloud]> select id,type,name,uuid,format,public,size,state,created,removed from vm_template where id in (202, 203, 204, 205)\G
*************************** 1. row ***************************
     id: 202
   type: USER
   name: template-private
   uuid: 195264b5-65e9-41ba-9c65-c992c5f34046
 format: QCOW2
 public: 0
   size: 52428800
  state: Inactive
created: 2021-03-04 05:47:30
removed: 2021-03-04 07:07:54
*************************** 2. row ***************************
     id: 203
   type: USER
   name: template-public
   uuid: e8039473-25c2-4254-b4fb-25b74ea6ef44
 format: QCOW2
 public: 1
   size: 52428800
  state: Inactive
created: 2021-03-04 05:58:26
removed: 2021-03-04 07:07:54
*************************** 3. row ***************************
     id: 204
   type: USER
   name: template-private-2storesZone
   uuid: d899e386-fd23-4c8b-9834-9cac9cd6febe
 format: QCOW2
 public: 0
   size: 52428800
  state: Inactive
created: 2021-03-04 06:09:22
removed: 2021-03-04 07:07:54
*************************** 4. row ***************************
     id: 205
   type: USER
   name: template-public-2storesZone
   uuid: 25cbaa26-d114-46d7-8285-cb1180fb5cee
 format: QCOW2
 public: 1
   size: 52428800
  state: Inactive
created: 2021-03-04 06:11:52
removed: 2021-03-04 07:07:54

Also tested a scenario where in a template can be present in other zones as well. In such a case, when a public template is destroyed in a specific zone, the template is left as Active - if it present in other zones:

MariaDB [cloud]> select * from template_zone_ref where template_id = 212\G
*************************** 1. row ***************************
          id: 24
     zone_id: 1
 template_id: 212
     created: 2021-03-04 07:55:08
last_updated: 2021-03-04 07:55:08
     removed: 2021-03-04 07:57:11
*************************** 2. row ***************************
          id: 25
     zone_id: 2
 template_id: 212
     created: 2021-03-04 07:56:23
last_updated: 2021-03-04 07:56:23
     removed: NULL
2 rows in set (0.00 sec)

MariaDB [cloud]> select id,type,name,uuid,format,public,size,state,created,removed from vm_template where id =212\G
*************************** 1. row ***************************
     id: 212
   type: USER
   name: test-multizone
   uuid: 0ef1505a-8863-4728-87fd-cbb0c8884cc2
 format: QCOW2
 public: 1
   size: 52428800
  state: Active
created: 2021-03-04 07:55:08
removed: NULL
1 row in set (0.00 sec)

MariaDB [cloud]> select id,template_id,store_id,created,state,size,store_role,install_path from template_store_ref where template_id =212\G
*************************** 1. row ***************************
          id: 37
 template_id: 212
    store_id: 3
     created: 2021-03-04 07:55:08
       state: Destroyed
        size: 52428800
  store_role: Image
install_path: template/tmpl/2/212/18fe8ef9-565c-3cf0-b418-885bdd6ade55.qcow2
*************************** 2. row ***************************
          id: 38
 template_id: 212
    store_id: 1
     created: 2021-03-04 07:55:08
       state: Destroyed
        size: 52428800
  store_role: Image
install_path: template/tmpl/2/212/c4fada96-bf51-356d-b47a-3efb95e71f84.qcow2
2 rows in set (0.01 sec)


Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

How Has This Been Tested?

Observations and tests mentioned above

@Pearl1594

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@Pearl1594 a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@Pearl1594
Pearl1594 changed the base branch from master to 4.15 March 4, 2021 10:40
@Pearl1594 Pearl1594 added this to the 4.15.1.0 milestone Mar 4, 2021
@Pearl1594
Pearl1594 requested a review from shwstppr March 4, 2021 10:41
@blueorangutan

Copy link
Copy Markdown

Packaging result: ✔centos7 ✔centos8 ✔debian. JID-2864

@Pearl1594

Copy link
Copy Markdown
Contributor Author

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@Pearl1594 a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@Pearl1594 Pearl1594 changed the title Update vm_template table to set template as removed on deletion Template cleanup : Update vm_template table to set template as removed on deletion Mar 4, 2021
@blueorangutan

Copy link
Copy Markdown

Trillian test result (tid-3649)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 36750 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr4748-t3649-kvm-centos7.zip
Intermittent failure detected: /marvin/tests/smoke/test_kubernetes_clusters.py
Intermittent failure detected: /marvin/tests/smoke/test_privategw_acl.py
Intermittent failure detected: /marvin/tests/smoke/test_templates.py
Intermittent failure detected: /marvin/tests/smoke/test_vm_life_cycle.py
Smoke tests completed. 82 look OK, 4 have error(s)
Only failed tests results shown below:

Test Result Time (s) Test File
test_04_rvpc_privategw_static_routes Failure 237.79 test_privategw_acl.py
ContextSuite context=TestKubernetesCluster>:teardown Error 64.57 test_kubernetes_clusters.py
test_03_deploy_vm_wrong_checksum Error 48.67 test_templates.py
test_01_migrate_VM_and_root_volume Error 59.05 test_vm_life_cycle.py
test_02_migrate_VM_with_two_data_disks Error 51.14 test_vm_life_cycle.py

Comment on lines +434 to +437
InactiveUnremovedTmpltSearch = createSearchBuilder();
InactiveUnremovedTmpltSearch.and("state", InactiveUnremovedTmpltSearch.entity().getState(), SearchCriteria.Op.IN);
InactiveUnremovedTmpltSearch.and("removed", InactiveUnremovedTmpltSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
InactiveUnremovedTmpltSearch.done();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this used anywhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @DaanHoogland . It was supposed to be referenced at listUnRemovedTemplatesByStates() - fixed it.

@yadvr
yadvr requested a review from DaanHoogland March 11, 2021 07:39

@DaanHoogland DaanHoogland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor requests, code looks good.

Comment on lines +575 to +582
List<VMTemplateZoneVO> templateZones = templateZoneDao.listByTemplateId(template.getId());
List<Long> zoneIds = templateZones.stream().map(VMTemplateZoneVO::getZoneId).collect(Collectors.toList());
if (zoneIds.size() > 0) {
return success;
}
template.setRemoved(new Date());
template.setState(State.Inactive);
templateDao.update(template.getId(), template);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete() ranges from line 454 to line 621. It deserves its own worker class. I won't ask that (hint hint, wink wink) but can you at least extract your new bit to a separate method?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (iStores == null || iStores.size() == 0) {
// Mark template as Inactive.
template.setState(VirtualMachineTemplate.State.Inactive);
templateDao.remove(template.getId());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a templateDao member in this class and a _tmpltDao in TemplateAdapterBase, and though I like the first name better, its presence is pollution/technical debt. I think you should use the one from the based class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +1327 to +1331
List<VMTemplateVO> vmTemplateVOS = _templateDao.listUnRemovedTemplatesByStates(VirtualMachineTemplate.State.Inactive);
for (VMTemplateVO template: vmTemplateVOS) {
template.setRemoved(new Date());
_templateDao.update(template.getId(), template);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you extract this? method already reaches from l1156-1339. ( a class StorageCleaner required :| )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pearl1594

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@Pearl1594 a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress. [S]

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✔️ centos7 ✔️ centos8 ✔️ debian. SL-JID 189

@Pearl1594

Copy link
Copy Markdown
Contributor Author

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@Pearl1594 a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

Trillian test result (tid-205)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 38360 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr4748-t205-kvm-centos7.zip
Intermittent failure detected: /marvin/tests/smoke/test_kubernetes_clusters.py
Intermittent failure detected: /marvin/tests/smoke/test_templates.py
Intermittent failure detected: /marvin/tests/smoke/test_vm_life_cycle.py
Smoke tests completed. 83 look OK, 3 have error(s)
Only failed tests results shown below:

Test Result Time (s) Test File
ContextSuite context=TestKubernetesCluster>:teardown Error 70.92 test_kubernetes_clusters.py
test_03_deploy_vm_wrong_checksum Error 49.66 test_templates.py
test_01_migrate_VM_and_root_volume Error 73.31 test_vm_life_cycle.py
test_02_migrate_VM_with_two_data_disks Error 52.90 test_vm_life_cycle.py

@Pearl1594

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@Pearl1594 a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

domainid=self.account.domainid,
serviceofferingid=self.service_offering.id
)
self.cleanup.append(tmpl)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd say this, self.cleanup.append(tmpl) is supposed to go to line 1325,
and this line should read self.cleanup.append(virtual_machine)

lines 1339 and 1340 should be removed. As this code is at the moment virtual_machne will be appended to cleanup only if the create fails and self.fail(...) is not called.

a cleanup should go directly after a create (or register) and only if the remove happens for some other reason it should be removed from the list again (if a double delete would be a problem)

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✔️ centos7 ✔️ centos8 ✔️ debian. SL-JID 210

@Pearl1594

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@Pearl1594 a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✔️ centos7 ✔️ centos8 ✔️ debian. SL-JID 213

@Pearl1594

Copy link
Copy Markdown
Contributor Author

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@Pearl1594 a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

Trillian test result (tid-234)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 38991 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr4748-t234-kvm-centos7.zip
Intermittent failure detected: /marvin/tests/smoke/test_kubernetes_clusters.py
Intermittent failure detected: /marvin/tests/smoke/test_vm_life_cycle.py
Smoke tests completed. 84 look OK, 2 have error(s)
Only failed tests results shown below:

Test Result Time (s) Test File
ContextSuite context=TestKubernetesCluster>:teardown Error 73.12 test_kubernetes_clusters.py
test_01_migrate_VM_and_root_volume Error 69.15 test_vm_life_cycle.py
test_02_migrate_VM_with_two_data_disks Error 51.03 test_vm_life_cycle.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants