caio.co/de/foca

Notification::Rename is better than Renamed at least

Id
4023207b609dafdd242c136390b1dfb594348ac0
Author
Caio
Commit time
2024-03-17T20:19:18+01:00

Modified examples/foca_insecure_udp_agent.rs

@@ -361,7 +361,7
Notification::Idle => {
tracing::info!("cluster empty");
}
- Notification::Renamed(old, new) => {
+ Notification::Rename(old, new) => {
tracing::info!("member {old:?} is now known as {new:?}");
}

Modified src/lib.rs

@@ -1229,7 +1229,7
member_id = tracing::field::debug(&id),
"Renamed"
);
- runtime.notify(Notification::Renamed(old, id.clone()));
+ runtime.notify(Notification::Rename(old, id.clone()));
}

if summary.changed_active_set {
@@ -4100,7 +4100,7
assert_eq!(Ok(()), foca.apply(Member::alive(renewed), &mut runtime));
assert_eq!(1, foca.num_members());
// Should notify the runtime about the change
- expect_notification!(runtime, Notification::Renamed(member, renewed));
+ expect_notification!(runtime, Notification::Rename(member, renewed));
// But no MemberUp notification should be fired, since
// previous addr was already active
reject_notification!(runtime, Notification::MemberUp(member));
@@ -4113,7 +4113,7
assert_eq!(Ok(()), foca.apply(Member::down(inactive), &mut runtime));
assert_eq!(0, foca.num_members());
// We get notified of the rename
- expect_notification!(runtime, Notification::Renamed(renewed, inactive));
+ expect_notification!(runtime, Notification::Rename(renewed, inactive));
// AND about the member going down with its new identity
expect_notification!(runtime, Notification::MemberDown(inactive));
// but nothing about the (now overriden, forgotten) previous one
@@ -4127,7 +4127,7
assert_eq!(Ok(()), foca.apply(Member::suspect(active), &mut runtime));
assert_eq!(1, foca.num_members());
// Should notify about the rename
- expect_notification!(runtime, Notification::Renamed(inactive, active));
+ expect_notification!(runtime, Notification::Rename(inactive, active));
// And about the member being active
expect_notification!(runtime, Notification::MemberUp(active));

Modified src/runtime.rs

@@ -77,8 +77,29
/// Can only happen if `MemberUp(T)` happened before.
MemberDown(T),

- /// FIXME docs. better name?
- Renamed(T, T),
+ /// Foca has learned that there's a more recent identity with
+ /// the same address and chose to use it instead of the previous
+ /// one.
+ ///
+ /// So `Notification::Rename(A,B)` means that we knew about a member
+ /// `A` but now there's a `B` with the same `Identity::Addr` and
+ /// foca chose to keep it. i.e. `B.win_addr_conflict(A) == true`.
+ ///
+ /// This happens naturally when a member rejoins the cluster after
+ /// any event (maybe they were declared down and `Identity::renew`d
+ /// themselves, maybe it's a restart/upgrade process)
+ ///
+ /// Example:
+ ///
+ /// If `A` was considered Down and `B` is Alive, you'll get
+ /// two notifications, in order:
+ //
+ /// 1. `Notification::Rename(A,B)`
+ /// 2. `Notification::MemberUp(B)`
+ ///
+ /// However, if there's no liveness change (both are active
+ /// or both are down), you'll only get the `Rename` notification
+ Rename(T, T),

/// Foca's current identity is known by at least one active member
/// of the cluster.