From ec9c6317ffdc16e93ef77be39a273b64279d18c6 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Fri, 8 Apr 2022 10:05:04 +0900 Subject: [PATCH] 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 --- manifests/cron/purge_deleted.pp | 15 ++++++++++-- .../purge-batch_size-12871727027b7357.yaml | 5 ++++ spec/classes/heat_cron_purge_deleted_spec.rb | 23 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/purge-batch_size-12871727027b7357.yaml diff --git a/manifests/cron/purge_deleted.pp b/manifests/cron/purge_deleted.pp index 54b4531f..36253245 100644 --- a/manifests/cron/purge_deleted.pp +++ b/manifests/cron/purge_deleted.pp @@ -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, diff --git a/releasenotes/notes/purge-batch_size-12871727027b7357.yaml b/releasenotes/notes/purge-batch_size-12871727027b7357.yaml new file mode 100644 index 00000000..4cab3965 --- /dev/null +++ b/releasenotes/notes/purge-batch_size-12871727027b7357.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + The ``heat::cron::purge_deleted`` class now supports customizing batch size + of the purge operation. diff --git a/spec/classes/heat_cron_purge_deleted_spec.rb b/spec/classes/heat_cron_purge_deleted_spec.rb index f228e1cf..b1561f21 100644 --- a/spec/classes/heat_cron_purge_deleted_spec.rb +++ b/spec/classes/heat_cron_purge_deleted_spec.rb @@ -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!(