From 510db7025333ee8867ffc276ec4738f8ad894b8f Mon Sep 17 00:00:00 2001 From: digimer Date: Tue, 2 May 2023 00:07:40 -0400 Subject: [PATCH] Another attempt to resolve the stoage group race condition. This moves the check for auto-assembly to scan-lvm. It only works for the first assemble, after that the user can/should use anvil-manage-storage-groups. Signed-off-by: digimer --- Anvil/Tools/Database.pm | 9 +++++- Anvil/Tools/Get.pm | 13 --------- scancore-agents/scan-lvm/scan-lvm | 48 +++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 14 deletions(-) diff --git a/Anvil/Tools/Database.pm b/Anvil/Tools/Database.pm index 1e842e1d..8d0dba12 100644 --- a/Anvil/Tools/Database.pm +++ b/Anvil/Tools/Database.pm @@ -5900,7 +5900,6 @@ ORDER BY my $storage_group_member_host_uuid = $row->[4]; my $storage_group_member_vg_uuid = $row->[5]; # This is the VG's internal UUID my $storage_group_member_note = $row->[6]; # If this is 'DELETED', the link isn't used anymore - my $storage_group_member_host_name = $anvil->data->{hosts}{host_uuid}{$storage_group_member_host_uuid}{short_host_name}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { storage_group_uuid => $storage_group_uuid, storage_group_anvil_uuid => $storage_group_anvil_uuid, @@ -5909,6 +5908,14 @@ ORDER BY storage_group_member_host_uuid => $storage_group_member_host_uuid, storage_group_member_vg_uuid => $storage_group_member_vg_uuid, storage_group_member_note => $storage_group_member_note, + }}); + + if (not exists $anvil->data->{hosts}{host_uuid}{$storage_group_member_host_uuid}) + { + $anvil->Database->get_hosts({debug => $debug}); + } + my $storage_group_member_host_name = $anvil->data->{hosts}{host_uuid}{$storage_group_member_host_uuid}{short_host_name}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { storage_group_member_host_name => $storage_group_member_host_name, }}); diff --git a/Anvil/Tools/Get.pm b/Anvil/Tools/Get.pm index 7a566660..3147b0d0 100644 --- a/Anvil/Tools/Get.pm +++ b/Anvil/Tools/Get.pm @@ -516,7 +516,6 @@ sub available_resources $anvil->Database->get_bridges({debug => $debug}); # Get the details. - my $host_uuid = $anvil->Get->host_uuid; my $anvil_name = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_name}; my $node1_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid}; my $node2_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node2_host_uuid}; @@ -524,20 +523,8 @@ sub available_resources 's1:anvil_name' => $anvil_name, 's2:node1_host_uuid' => $node1_host_uuid, 's3:node2_host_uuid' => $node2_host_uuid, - 's4:host_uuid' => $host_uuid, }}); - # If we're node 1, we'll try to assemble the storage group. Onle node 1 does this to help avoid race - # conditions. This both loads storage group data and assembles ungrouped VGs into storage groups, - # when possible. - if ($host_uuid eq $node1_host_uuid) - { - $anvil->Cluster->assemble_storage_groups({ - debug => 2, - anvil_uuid => $anvil_uuid, - }); - } - # This will store the available resources based on the least of the nodes. $anvil->data->{anvil_resources}{$anvil_uuid}{cpu}{cores} = 0; $anvil->data->{anvil_resources}{$anvil_uuid}{cpu}{threads} = 0; diff --git a/scancore-agents/scan-lvm/scan-lvm b/scancore-agents/scan-lvm/scan-lvm index 8e17eb86..7f59de3e 100755 --- a/scancore-agents/scan-lvm/scan-lvm +++ b/scancore-agents/scan-lvm/scan-lvm @@ -84,6 +84,9 @@ read_last_scan($anvil); # Loog for changes find_changes($anvil); +# Check storage for storage groups. +check_storage_groups($anvil); + # Shut down. $anvil->ScanCore->agent_shutdown({agent => $THIS_FILE}); $anvil->nice_exit({exit_code => 0}); @@ -93,6 +96,51 @@ $anvil->nice_exit({exit_code => 0}); # Functions # ############################################################################################################# +sub check_storage_groups +{ + my ($anvil) = @_; + + # Are we in an Anvil!? If so, are there any storage groups yet? + my $anvil_uuid = $anvil->Cluster->get_anvil_uuid(); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }}); + + if ($anvil_uuid) + { + # If we're node 1, we'll try to assemble the storage group. Onle node 1 does this to help avoid race + # conditions. This both loads storage group data and assembles ungrouped VGs into storage groups, + # when possible. + $anvil->Database->get_anvils(); + my $host_uuid = $anvil->Get->host_uuid; + my $anvil_name = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_name}; + my $node1_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid}; + my $node2_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node2_host_uuid}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 's1:anvil_name' => $anvil_name, + 's2:node1_host_uuid' => $node1_host_uuid, + 's3:node2_host_uuid' => $node2_host_uuid, + 's4:host_uuid' => $host_uuid, + }}); + if ($host_uuid eq $node1_host_uuid) + { + # Are there any storage groups yet? If not, try to assemble one. + my $query = "SELECT COUNT(*) FROM storage_groups WHERE storage_group_anvil_uuid = ".$anvil->Database->quote($anvil_uuid).";"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); + + my $count = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0]; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }}); + if (not $count) + { + $anvil->Cluster->assemble_storage_groups({ + debug => 2, + anvil_uuid => $anvil_uuid, + }); + } + } + } + + return(0); +} + sub find_changes { my ($anvil) = @_;