# HG changeset patch
# User Sami Hiltunen <shiltunen@gitlab.com>
# Date 1652136719 0
#      Mon May 09 22:51:59 2022 +0000
# Node ID 228e2b9d7848132177fc50662fc69b9db0669272
# Parent  308afda689a2b7eee670c96daa84ecb2bc94c1c2
Add Praefect verifier deletion logic config option

Adds a configuration option to enable deletion of invalid metadata
records found by Praefect's metadata verifier.

Related https://gitlab.com/gitlab-org/gitaly/-/issues/4211

Changelog: added

diff --git a/files/gitlab-config-template/gitlab.rb.template b/files/gitlab-config-template/gitlab.rb.template
--- a/files/gitlab-config-template/gitlab.rb.template
+++ b/files/gitlab-config-template/gitlab.rb.template
@@ -2419,6 +2419,7 @@
 #   }
 # }
 # praefect['background_verification_verification_interval'] = "72h"
+# praefect['background_verification_delete_invalid_records'] = false
 # praefect['sentry_dsn'] = "https://<key>:<secret>@sentry.io/<project>"
 # praefect['sentry_environment'] = "production"
 # praefect['auto_migrate'] = true
diff --git a/files/gitlab-cookbooks/praefect/attributes/default.rb b/files/gitlab-cookbooks/praefect/attributes/default.rb
--- a/files/gitlab-cookbooks/praefect/attributes/default.rb
+++ b/files/gitlab-cookbooks/praefect/attributes/default.rb
@@ -42,3 +42,4 @@
 default['praefect']['consul_service_name'] = 'praefect'
 default['praefect']['consul_service_meta'] = nil
 default['praefect']['background_verification_verification_interval'] = nil
+default['praefect']['background_verification_delete_invalid_records'] = nil
diff --git a/files/gitlab-cookbooks/praefect/templates/default/praefect-config.toml.erb b/files/gitlab-cookbooks/praefect/templates/default/praefect-config.toml.erb
--- a/files/gitlab-cookbooks/praefect/templates/default/praefect-config.toml.erb
+++ b/files/gitlab-cookbooks/praefect/templates/default/praefect-config.toml.erb
@@ -67,6 +67,9 @@
 <% if @background_verification_verification_interval %>
 verification_interval = '<%= @background_verification_verification_interval %>'
 <% end %>
+<% if @background_verification_delete_invalid_records %>
+delete_invalid_records = <%= @background_verification_delete_invalid_records %>
+<% end %>
 
 <% @virtual_storages.each do |name, config| %>
 [[virtual_storage]]
diff --git a/spec/chef/cookbooks/praefect/recipes/praefect_spec.rb b/spec/chef/cookbooks/praefect/recipes/praefect_spec.rb
--- a/spec/chef/cookbooks/praefect/recipes/praefect_spec.rb
+++ b/spec/chef/cookbooks/praefect/recipes/praefect_spec.rb
@@ -155,6 +155,7 @@
                          reconciliation_scheduling_interval: reconciliation_scheduling_interval,
                          reconciliation_histogram_buckets: reconciliation_histogram_buckets,
                          background_verification_verification_interval: '168h',
+                         background_verification_delete_invalid_records: true,
                        })
       end
 
@@ -197,7 +198,8 @@
                 'scheduling_interval' => '1m'
               },
               'background_verification' => {
-                'verification_interval' => '168h'
+                'verification_interval' => '168h',
+                'delete_invalid_records' => true
               },
               'sentry' => {
                 'sentry_dsn' => 'https://my_key:my_secret@sentry.io/test_project',