1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use BTreeSet;
/// A point-in-time snapshot of committed cluster membership.
///
/// Delivered via [`crate::EmbeddedEngine::watch_membership`] whenever a `ConfChange`
/// entry commits. The snapshot reflects the membership state **after** the
/// change has been applied, so `borrow()` always returns a consistent view.
///
/// ## Idempotency
///
/// `committed_index` is the Raft log index of the `ConfChange` entry that
/// triggered this snapshot. It is strictly monotonically increasing across
/// snapshots and can be used as an idempotency key:
///
/// ```ignore
/// if snapshot.committed_index <= self.last_applied {
/// return; // already handled
/// }
/// self.last_applied = snapshot.committed_index;
/// scheduler.rebalance(&snapshot);
/// ```
///
/// ## Diff computation
///
/// No diff fields are included. Because `watch::channel` is lossy (only the
/// latest value is retained), a diff embedded in the snapshot could be stale
/// if the receiver is slow and skips an intermediate change. Callers that
/// need a diff should compute it against their own previous snapshot:
///
/// ```ignore
/// let prev = std::mem::replace(&mut self.prev_snapshot, snapshot.clone());
/// let joined: BTreeSet<_> = snapshot.members.difference(&prev.members).copied().collect();
/// let left: BTreeSet<_> = prev.members.difference(&snapshot.members).copied().collect();
/// ```