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

Dominik Csapak d.csapak at proxmox.com
Tue May 14 11:15:50 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 v2:
* user proper sub ($sub->() vs $get_node_data->())
* encode data only once
* add comment about maximum pmxcfs size
* die instead of eval/warn/syslog (caller must handle failure)
* remove post if variable declaration

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

diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
index 5af11e6..4c719eb 100644
--- a/data/PVE/Cluster.pm
+++ b/data/PVE/Cluster.pm
@@ -540,6 +540,50 @@ 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 $enc_data = encode_json($data);
+    my $size = length($enc_data);
+    # pmxcfs has an upper bound of 32k for each entry
+    if ($size >= (32 * 1024)) {
+	warn "data for '$key' too big\n";
+	return;
+    }
+
+    eval {
+	$ipcc_update_status->("kv/$key", $enc_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} = decode_json($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