Skip to main content

evaluate

Function evaluate 

Source
pub fn evaluate(
    state: &RoleState,
    me: &MemberId,
    now_millis: i64,
    config: &LeaseConfig,
) -> Decision
Expand description

Decides what me does about the role of state at now_millis.

The rules are:

  1. A member that is not in the roster gets Decision::NotRegistered. It has no rank, because rank comes from the registration record.
  2. A member that the lease names, while that lease is live, gets Decision::Hold.
  3. A challenger of rank n gets Decision::Challenge from deadline + n * challenge_stagger on. With no lease, the anchor is the registration instant of the member instead of a deadline, so rank 0 challenges at once and rank n challenges n staggers later.
  4. Every other member gets Decision::Wait, and the instant it carries is the earliest instant at which this answer changes for an unchanged role state.

The anchor of rule 3 always comes from the role state and never from now_millis. A member that has no lease to wait for anchors on its own registration record. An anchor of “now plus n staggers” would move forward on every evaluation, and a standby of rank 1 or more would then wait for ever while rank 0 is dead.

The member of an expired lease keeps rank 0, so it reclaims its own role at its own deadline. See RoleState::rank_of.

A caller re-evaluates when it reads a new record, and at the latest at the instant that Decision::Wait names.