[pve-devel] [PATCH cluster v2] add generic data broadcast interface

Dominik Csapak d.csapak at proxmox.com
Fri May 3 12:32:49 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>
---
sending it alone, awaiting review of the rest of my series
changes from v1:
* use modern sub syntax
* better naming

 data/PVE/Cluster.pm | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
index 5af11e6..a50785d 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_node_kv {
+    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->("kv/$key", $data);
+    };
+
+    warn $@ if $@;
+}
+
+sub get_node_kv {
+    my ($key, $nodename) = @_;
+
+    my $res = {};
+    my $get_node_data = sub {
+	my ($node) = @_;
+	eval {
+	    my $raw = $ipcc_get_status->("kv/$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) {
+	    $get_node_data->($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