Support tuning batch size of DB purge operation

The heat-manage purge_deleted command supports customizing batch size,
number of stacks to delete by a single transaction. This change adds
the new parameter to customize the parameter.

Change-Id: Id980c6f975f22baa305d3cd84378c98b3e9f84f2
This commit is contained in:
Takashi Kajinami 2022-04-08 10:05:04 +09:00
parent f267f9a1d8
commit ec9c6317ff
3 changed files with 41 additions and 2 deletions

View File

@ -46,6 +46,10 @@
# (optional) Path to file to which rows should be archived
# Defaults to '/var/log/heat/heat-purge_deleted.log'.
#
# [*batch_size*]
# (optional) Number of stacks to delete at a time (per transaction).
# Defaults to undef.
#
class heat::cron::purge_deleted (
$ensure = present,
$minute = 1,
@ -57,7 +61,8 @@ class heat::cron::purge_deleted (
$user = $::heat::params::user,
$age = 1,
$age_type = 'days',
$destination = '/var/log/heat/heat-purge_deleted.log'
$destination = '/var/log/heat/heat-purge_deleted.log',
$batch_size = undef,
) inherits heat::params {
if ! member(['days', 'hours', 'minutes', 'seconds'], $age_type) {
@ -70,9 +75,15 @@ class heat::cron::purge_deleted (
$sleep = "sleep `expr \${RANDOM} \\% ${maxdelay}`; "
}
if $batch_size != undef {
$batch_size_opt = "-b ${batch_size} "
} else {
$batch_size_opt = ''
}
cron { 'heat-manage purge_deleted':
ensure => $ensure,
command => "${sleep}heat-manage purge_deleted -g ${age_type} ${age} >>${destination} 2>&1",
command => "${sleep}heat-manage purge_deleted -g ${age_type} ${age} ${batch_size_opt}>>${destination} 2>&1",
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
user => $user,
minute => $minute,

View File

@ -0,0 +1,5 @@
---
features:
- |
The ``heat::cron::purge_deleted`` class now supports customizing batch size
of the purge operation.

View File

@ -64,6 +64,29 @@ describe 'heat::cron::purge_deleted' do
end
end
describe 'when batch_size is set' do
before :each do
params.merge!(
:batch_size => 100
)
end
it 'disables the cron job' do
is_expected.to contain_cron('heat-manage purge_deleted').with(
:ensure => params[:ensure],
:command => "heat-manage purge_deleted -g days 1 -b #{params[:batch_size]} >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => 'heat',
:minute => params[:minute],
:hour => params[:hour],
:monthday => params[:monthday],
:month => params[:month],
:weekday => params[:weekday],
:require => 'Anchor[heat::dbsync::end]'
)
end
end
describe 'when disabling cron job' do
before :each do
params.merge!(