[pve-devel] [PATCH cluster v4 2/2] add generic data broadcast interface

Dominik Csapak d.csapak at proxmox.com
Thu May 16 17:12:31 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. listing ceph services
across the cluster, etc.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v3:
* remove key when data is undef
* die if size is too big (instead of warn and return; caller has to check)
* do not encode/decode anymore (caller has to do this now)

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

diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
index 3705a79..0cc092e 100644
--- a/data/PVE/Cluster.pm
+++ b/data/PVE/Cluster.pm
@@ -546,6 +546,54 @@ 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) = @_;
+
+    if (!defined($data)) {
+	eval {
+	    $ipcc_remove_status->("kv/$key");
+	};
+    } else {
+	die "cannot send a reference\n" if ref($data);
+	my $size = length($data);
+	# pmxcfs has an upper bound of 32k for each entry
+	die "data for '$key' too big\n"
+	    if $size >= (32*1024);
+
+	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) = @_;
+	my $raw = $ipcc_get_status->("kv/$key", $node);
+	$res->{$node} = $raw if $raw;
+    };
+
+    if ($nodename) {
+	$get_node_data->($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