[pve-devel] [RFC cluster 1/1] add generic data broadcast interface

Dominik Csapak d.csapak at proxmox.com
Fri Apr 26 08:21:25 CEST 2019


similar to how we handle the cluster wide tasklist and rrd data,
have an interface that can sync data across the cluster

this data is only transient and will not be written to disk

we can use this for a number of things, e.g. getting the locks of the
guests clusterwide, listing ceph services across the cluster, etc.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 data/PVE/Cluster.pm | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
index 5af11e6..ea36a0a 100644
--- a/data/PVE/Cluster.pm
+++ b/data/PVE/Cluster.pm
@@ -540,6 +540,53 @@ sub get_nodelist {
     return [ keys %$nodelist ];
 }
 
+# best effort data store for cluster
+# this data is gone if the pmxcfs is restarted, but only the local data,
+# so we should not use this for very important data
+sub broadcast_data {
+    my ($key, $data) = @_;
+
+    my $size = length(encode_json($data));
+    if ($size >= (32 * 1024)) {
+	warn "data for '$key' too big\n";
+	return;
+    }
+
+    eval {
+	&$ipcc_update_status($key, $data);
+    };
+
+    warn $@ if $@;
+}
+
+sub get_data {
+    my ($key, $nodename) = @_;
+
+    my $res = {};
+    my $sub = sub {
+	my ($node) = @_;
+	eval {
+	    my $raw = &$ipcc_get_status($key, $node);
+	    my $data = decode_json($raw) if $raw;
+	    $res->{$node} = $data;
+	};
+	my $err = $@;
+	syslog('err', $err) if $err;
+    };
+
+    if ($nodename) {
+	$sub->($nodename);
+    } else {
+	my $nodelist = get_nodelist();
+
+	foreach my $node (@$nodelist) {
+	    $sub->($node);
+	}
+    }
+
+    return $res;
+}
+
 # $data must be a chronological descending ordered array of tasks
 sub broadcast_tasklist {
     my ($data) = @_;
-- 
2.11.0





More information about the pve-devel mailing list