Add way to periodically trim Nova DB

We're adding 2 services that are responsible for executing db purge and
archive_deleted_rows. Services will be deployed by default, but left
stopped/disabled. This way we allow deployers to enable/disable
feature by changing value of nova_archive/purge_deleted.

Otherwise, when variables set to true once, setting them to false won't
lead to stopoing of DB trimming and that would need to be done manualy.

Change-Id: I9f110f663fae71f5f3c01c6d09e6d1302d517466
This commit is contained in:
Dmitriy Rabotyagov 2023-04-20 15:13:01 +02:00 committed by Dmitriy Rabotyagov
parent 2925c1c29c
commit efe64725e1
3 changed files with 90 additions and 0 deletions

View File

@ -785,3 +785,28 @@ nova_pki_install_certificates:
group: "{{ nova_system_user_name }}"
mode: "0600"
condition: "{{ nova_backend_ssl }}"
# Periodically move records for deleted resources to shadow tables
nova_archive_deleted: False
# When to start archive task. Reffer to Systemd Calendar Events for guidance
# on format:
# https://www.freedesktop.org/software/systemd/man/systemd.time.html#Calendar%20Events
nova_archive_deleted_on_calendar: "*-*-* 00:00:00"
# Archive events that are older then the timeframe below.
# Should be in a format of bash date string
nova_archive_deleted_before: "6 month ago"
# Delete records instead of moving them to shadow tables
nova_archive_deleted_purge: False
# Archive instance task log
nova_archive_task_log: False
# Delay the timer by a randomly selected amount of time.
nova_archive_deleted_randomized_delay_sec: 0
# Periodically purge shadow tables, where archived records are stored
nova_purge_deleted: False
# When to start purge task.
nova_purge_deleted_on_calendar: "*-*-* 01:00:00"
# Purge events that are older then the timeframe below.
nova_purge_deleted_before: "24 month ago"
# Delay the timer by a randomly selected amount of time.
nova_purge_deleted_randomized_delay_sec: 0

View File

@ -0,0 +1,19 @@
---
features:
- |
Added option to periodically clean-up deleted records from Nova
database. Having a lot of records for the deleted instances affects
service performance.
With that 2 new services are being introduced: ``nova-archive-deleted``
and ``nova-purge-deleted`` that will be called periodically using
corresponsive systemd timers on the first nova-conductor host.
By default these services are disabled/stopped and database cleanup
is not performed. You can enable this behaviour by defining variables
``nova_archive_deleted`` and ``nova_purge_deleted``.
Service ``nova-archive-deleted`` will execute
`nova-manage db archive_deleted_rows` while ``nova-archive-deleted``
will execute `nova-manage db purge`. Please correspond to nova-manage
documentation for more information on what these commands do:
https://docs.openstack.org/nova/latest/cli/nova-manage.html

View File

@ -53,3 +53,49 @@
when:
- data_migrations is not skipped
- data_migrations is succeeded
- name: Create service and timer for archiving deleted records
include_role:
name: systemd_service
vars:
systemd_service_restart_changed: false
systemd_user_name: "{{ nova_system_user_name }}"
systemd_group_name: "{{ nova_system_group_name }}"
systemd_tempd_prefix: openstack
systemd_slice_name: "{{ nova_system_slice_name }}"
systemd_lock_dir: "{{ nova_lock_dir }}"
systemd_services:
- service_name: "nova-archive-deleted"
execstarts:
- /bin/sh -c "{{ _db_nova_bin }}/nova-manage db archive_deleted_rows --until-complete --all-cells --before \"$(date -d '{{ nova_archive_deleted_before }}' +'%%Y-%%m-%%d %%H:%%M')\" {{ (nova_archive_deleted_purge) | ternary('--purge', '') }} {{ (nova_archive_task_log) | ternary('--task-log', '') }}"
environment:
UMASK: '0640'
UMASK_DIR: '0750'
program_sandboxing:
RuntimeDirectory: 'nova-archive-deleted'
enabled: "{{ nova_archive_deleted }}"
timer:
state: "{{ nova_archive_deleted | ternary('started', 'stopped') }}"
enabled: "{{ nova_archive_deleted }}"
options:
OnCalendar: "{{ nova_archive_deleted_on_calendar }}"
RandomizedDelaySec: "{{ nova_archive_deleted_randomized_delay_sec }}"
Persistent: true
Unit: "nova-archive-deleted.service"
- service_name: "nova-purge-deleted"
execstarts:
- /bin/sh -c "{{ _db_nova_bin }}/nova-manage db purge --until-complete --all-cells --before \"$(date -d '{{ nova_purge_deleted_before }}' +'%%Y-%%m-%%d %%H:%%M')\""
environment:
UMASK: '0640'
UMASK_DIR: '0750'
program_sandboxing:
RuntimeDirectory: 'nova-purge-deleted'
enabled: "{{ nova_purge_deleted }}"
timer:
state: "{{ nova_purge_deleted | ternary('started', 'stopped') }}"
enabled: "{{ nova_purge_deleted }}"
options:
OnCalendar: "{{ nova_purge_deleted_on_calendar }}"
RandomizedDelaySec: "{{ nova_purge_deleted_randomized_delay_sec }}"
Persistent: true
Unit: "nova-purge-deleted.service"