[pve-devel] [PATCH ha-manager 3/4] CRM: release lock on shutdown request

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Jan 13 15:15:32 CET 2016


release the manager lock on a shutdown request, so another CRM slave
can get it and continue to work without waiting for the lock timeout

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/HA/CRM.pm      | 8 ++++++++
 src/PVE/HA/Env.pm      | 9 +++++++++
 src/PVE/HA/Env/PVE2.pm | 9 +++++++++
 src/PVE/HA/Sim/Env.pm  | 9 +++++++++
 4 files changed, 35 insertions(+)

diff --git a/src/PVE/HA/CRM.pm b/src/PVE/HA/CRM.pm
index 4196bba..e9c1783 100644
--- a/src/PVE/HA/CRM.pm
+++ b/src/PVE/HA/CRM.pm
@@ -206,6 +206,14 @@ sub do_one_iteration {
 		    delete $self->{ha_manager_wd};
 		}
 
+		# release the manager lock, so another CRM slave can get it
+		# and continue to work without waiting for the lock timeout
+		$haenv->log('info', "voluntary release CRM lock");
+		if (!$haenv->release_ha_manager_lock()) {
+		    $haenv->log('notice', "CRM lock release failed, let the" .
+				" lock timeout");
+		}
+
 		$shutdown = 1;
 
 	    } else {
diff --git a/src/PVE/HA/Env.pm b/src/PVE/HA/Env.pm
index fe31893..74ce545 100644
--- a/src/PVE/HA/Env.pm
+++ b/src/PVE/HA/Env.pm
@@ -120,6 +120,15 @@ sub get_ha_manager_lock {
     return $self->{plug}->get_ha_manager_lock();
 }
 
+# release the cluster wide manager lock.
+# when released another CRM may step up and get the lock, thus this should only
+# get called when shutting down/deactivating the current master
+sub release_ha_manager_lock {
+    my ($self) = @_;
+
+    return $self->{plug}->release_ha_manager_lock();
+}
+
 # acquire a cluster wide node agent lock
 sub get_ha_agent_lock {
     my ($self, $node) = @_;
diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm
index 0741f5a..1920a09 100644
--- a/src/PVE/HA/Env/PVE2.pm
+++ b/src/PVE/HA/Env/PVE2.pm
@@ -260,6 +260,15 @@ sub get_ha_manager_lock {
     return $self->get_pve_lock("ha_manager_lock");
 }
 
+# release the cluster wide manager lock.
+# when released another CRM may step up and get the lock, thus this should only
+# get called when shutting down/deactivating the current master
+sub release_ha_manager_lock {
+    my ($self) = @_;
+
+    return rmdir("$lockdir/ha_manager_lock");
+}
+
 sub get_ha_agent_lock {
     my ($self, $node) = @_;
 
diff --git a/src/PVE/HA/Sim/Env.pm b/src/PVE/HA/Sim/Env.pm
index d7b8122..56cc7f8 100644
--- a/src/PVE/HA/Sim/Env.pm
+++ b/src/PVE/HA/Sim/Env.pm
@@ -215,6 +215,15 @@ sub get_ha_manager_lock {
     return $self->sim_get_lock('ha_manager_lock');
 }
 
+# release the cluster wide manager lock.
+# when released another CRM may step up and get the lock, thus this should only
+# get called when shutting down/deactivating the current master
+sub release_ha_manager_lock {
+    my ($self) = @_;
+
+    return $self->sim_get_lock('ha_manager_lock', 1);
+}
+
 sub get_ha_agent_lock_name {
     my ($self, $node) = @_;
 
-- 
2.1.4





More information about the pve-devel mailing list