public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Aaron Lauterer <a.lauterer@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Fiona Ebner <f.ebner@proxmox.com>
Subject: Re: [pve-devel] [RFC cluster] status: clear stale kv stores upon sync
Date: Wed, 26 Feb 2025 17:13:24 +0100	[thread overview]
Message-ID: <415429c7-eec8-43ab-b53d-fdcab83f1795@proxmox.com> (raw)
In-Reply-To: <20221006125414.58279-1-f.ebner@proxmox.com>

In the context of another patch to improve the broadcasting of 
version-info across a cluster, Fiona mentioned [0] that this RFC would 
also be of interested to invalidate KV data of nodes that left the 
cluster, to avoid stale infos.

Had to adapt the paths in the patch file, but then it still applied to 
current master.
/data/src/status.c
/src/pmxcfs/status.c

Did a quick test and so far it seems to do what it promises. Once I stop 
the corosync service of a node, the version-info of it disappears right 
away.

[0] 
https://lore.proxmox.com/pve-devel/17363828-136f-4f85-ad41-3a34b1a56689@proxmox.com/

Consider this

Tested-By: Aaron Lauterer <a.lauterer@proxmox.com>


On  2022-10-06  14:54, Fiona Ebner wrote:
> This avoids that stale kv entries stay around when a node leaves the
> CPG. Now, each kv entry will be something a node sent after (or upon
> joining) the CPG.
> 
> This avoids scenarios where a user of pmxcfs (like pvestatd) on node A
> might not yet have had the time to broadcast up-to-date kv entries,
> but a user of pmxcfs on node B sees node A as online and uses the
> outdated value (which couldn't be detected as outdated).
> 
> In particular, this should be helpful for more static information
> broadcast by pvestatd which (mostly) doesn't change while a node is
> running.
> 
> Could also be done as part of the dfsm_confchg() callback, but then
> (at least) the additional guarantee of "confchg always happens before
> the kvstore messages during sync arrive" is needed (pointed out by
> Fabian). It should hold in practice, but dfsm_process_state_update()
> doesn't need such guarantees and is also a fitting place to do it.
> 
> The cfs_status_clear_other_kvstores() could take a hash table with the
> IDs to avoid the quadratic loop, but since the number of nodes in
> setups in practice is never too big, it's likely faster than the
> additional work of constructing that hash at the call side.
> 
> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
> ---
> 
> Many thanks to Fabian for helpful discussions!
> 
> Another alternative to avoid the quadratic loop would be to copy the
> hash table, iterating over skip_node_ids once to remove them from the
> hash table (but need to make sure the original value isn't freed!) and
> then iterate over the hash table once. Not sure how much nicer that
> would be though.
> 
>   data/src/status.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 47 insertions(+)
> 
> diff --git a/data/src/status.c b/data/src/status.c
> index 9bceaeb..3da57cf 100644
> --- a/data/src/status.c
> +++ b/data/src/status.c
> @@ -539,6 +539,46 @@ void cfs_status_set_clinfo(
>   	g_mutex_unlock (&mutex);
>   }
>   
> +void
> +cfs_status_clear_other_kvstores(
> +	uint32_t *skip_node_ids,
> +	int count)
> +{
> +	g_mutex_lock (&mutex);
> +
> +	if (!cfs_status.clinfo || !cfs_status.clinfo->nodes_byid) {
> +		goto unlock; /* ignore */
> +	}
> +
> +	GHashTable *ht = cfs_status.clinfo->nodes_byid;
> +	GHashTableIter iter;
> +	gpointer key, value;
> +
> +	g_hash_table_iter_init (&iter, ht);
> +
> +	// Quadratic in the number of nodes, but it's safe to assume that the number is small enough
> +	while (g_hash_table_iter_next (&iter, &key, &value)) {
> +		uint32_t nodeid = *(uint32_t *)key;
> +		cfs_clnode_t *clnode = (cfs_clnode_t *)value;
> +		gboolean skip = FALSE;
> +
> +		for (int i = 0; i < count; i++) {
> +			if (nodeid == skip_node_ids[i]) {
> +				skip = TRUE;
> +				break;
> +			}
> +		}
> +
> +		if (!skip && clnode->kvhash) {
> +			cfs_debug("clearing kv store of node %d", nodeid);
> +			g_hash_table_remove_all(clnode->kvhash);
> +		}
> +	}
> +
> +unlock:
> +	g_mutex_unlock (&mutex);
> +}
> +
>   static void
>   dump_kvstore_versions(
>   	GString *str,
> @@ -1769,12 +1809,15 @@ dfsm_process_state_update(
>   	g_return_val_if_fail(syncinfo != NULL, -1);
>   
>   	clog_base_t *clog[syncinfo->node_count];
> +	uint32_t sync_node_ids[syncinfo->node_count];
>   
>   	int local_index = -1;
>   	for (int i = 0; i < syncinfo->node_count; i++) {
>   		dfsm_node_info_t *ni = &syncinfo->nodes[i];
>   		ni->synced = 1;
>   
> +		sync_node_ids[i] = ni->nodeid;
> +
>   		if (syncinfo->local == ni)
>   			local_index = i;
>   
> @@ -1791,6 +1834,10 @@ dfsm_process_state_update(
>   		cfs_critical("unable to merge log files");
>   	}
>   
> +	// Clear our copy of the kvstore of every node that is not part of the current sync. When
> +	// such a node joins again, it will sync its current kvstore with cfs_kvstore_sync().
> +	cfs_status_clear_other_kvstores(sync_node_ids, syncinfo->node_count);
> +
>   	cfs_kvstore_sync();
>   
>   	return 1;



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


      reply	other threads:[~2025-02-26 16:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-06 12:54 [pve-devel] [RFC cluster] status: clear stale kv stores upon sync Fiona Ebner
2025-02-26 16:13 ` Aaron Lauterer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=415429c7-eec8-43ab-b53d-fdcab83f1795@proxmox.com \
    --to=a.lauterer@proxmox.com \
    --cc=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal