aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-16 20:42:16 +0000
committertv <tv@krebsco.de>2026-11-16 22:03:30 +0100
commit5cabcbfa81d6293c96d28c603621be331f1f9b0f (patch)
tree90174f644bc0da0cd4b237f5d4578d161c30dd20 /src/federation
parent5272813c3f8cba8d403f5a7571e0c7ddd252b198 (diff)
federation: the members a node's store names
The fold names the members, each with its group: for the federation, the nodes each party lists, each as its party's (`docs/store.md`, Members). A node keeps them as its store reads now, apart from the store, so that whoever asks doesn't wait while the store takes events: `Holding::member` tells whether a node, of a party, is one, or that the node holds no store and can't tell; `Holding::members` lists them.
Diffstat (limited to 'src/federation')
-rw-r--r--src/federation/held.rs36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/federation/held.rs b/src/federation/held.rs
index f8825e5..5b9a740 100644
--- a/src/federation/held.rs
+++ b/src/federation/held.rs
@@ -22,7 +22,7 @@
use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::path::PathBuf;
-use std::sync::{Arc, Mutex};
+use std::sync::{Arc, Mutex, RwLock};
use std::time::Duration;
use anyhow::{Context, Result, bail};
@@ -36,7 +36,7 @@ use super::store::{Fold, Id};
use super::version::Version;
use crate::document::{Change, ChangeHash, ReadDoc, ScalarValue, events, meta, store};
use crate::files::{FileKind, Files};
-use crate::locks::MutexExt;
+use crate::locks::{MutexExt, RwLockExt};
/// How long a node waits before it puts again what its document lacks, at least and at
/// most: random in between, so that not every node puts the same.
@@ -84,6 +84,9 @@ pub(crate) struct Holding {
file: Option<(PathBuf, Arc<Files>)>,
pin: Option<Id>,
party: Option<String>,
+ /// The members the store names, each with its party, as it reads now: apart from the
+ /// store, so that whoever asks doesn't wait while the store takes events.
+ members: RwLock<Option<BTreeSet<(String, String)>>>,
// A std mutex: never held while waiting for the document.
inner: Mutex<Inner>,
}
@@ -148,6 +151,7 @@ impl Holding {
file: Some((path, files)),
pin,
party,
+ members: RwLock::default(),
inner: Mutex::new(Inner {
kept,
..Inner::default()
@@ -254,6 +258,15 @@ impl Holding {
inner.kept = kept;
self.keep(&inner.kept);
}
+ let members: BTreeSet<(String, String)> = store.state().members().into_iter().collect();
+ let mut known = self.members.write_or_recover();
+ if known.as_ref() != Some(&members) {
+ info!(
+ members = members.len(),
+ "The store's members, as it reads now"
+ );
+ *known = Some(members);
+ }
}
/// Writes what the node keeps of its own to its file, if it has one.
@@ -316,6 +329,19 @@ impl Holding {
.unwrap_or_default()
}
+ /// Whether `node`, of `party`, is a member of the store as it reads now: one the fold
+ /// names with that party. None while the node holds no store, and can't tell.
+ pub(crate) fn member(&self, node: &str, party: Option<&str>) -> Option<bool> {
+ let members = self.members.read_or_recover();
+ let members = members.as_ref()?;
+ Some(party.is_some_and(|party| members.contains(&(node.to_owned(), party.to_owned()))))
+ }
+
+ /// The members the store names, each with its party, while the node holds a store.
+ pub(crate) fn members(&self) -> Option<BTreeSet<(String, String)>> {
+ self.members.read_or_recover().clone()
+ }
+
/// The party its operator says the node is of (`--store-party`).
pub(crate) fn party(&self) -> Option<&str> {
self.party.as_deref()
@@ -588,6 +614,12 @@ mod tests {
assert!(holding.unread(&Document::new(), 0).is_none());
read(&holding, &doc, 0);
assert_eq!(holding.with(|store| store.id()), Some(Id::of(&root)));
+ // Its first party lists a node.
+ let node = harness::node_id(0);
+ assert_eq!(holding.member(&node, Some("tv")), Some(true));
+ assert_eq!(holding.member(&node, Some("lass")), Some(false));
+ assert_eq!(holding.member(&node, None), Some(false));
+ assert_eq!(Holding::default().member(&node, Some("tv")), None);
let write = tv.write(&[Id::of(&root)], "home/tv/x", harness::str("1"));
let on = tv.write(&[Id::of(&write)], "home/tv/x", harness::str("2"));
// What it builds on comes later: it waits for it.