Instance

public final class Instance : SWIMProtocol
extension SWIM.Instance: CustomDebugStringConvertible

The SWIM.Instance encapsulates the complete algorithm implementation of the SWIM protocol.

Please refer to SWIM for an in-depth discussion of the algorithm and extensions implemented in this package.

See also

SWIM for a complete and in depth discussion of the protocol.
  • The settings currently in use by this instance.

    Declaration

    Swift

    public let settings: SWIM.Settings
  • The SWIM.Member representing this instance, also referred to as “myself”.

    Declaration

    Swift

    public var member: SWIM.Member { get }
  • Sequence numbers are used to identify messages and pair them up into request/replies.

    Declaration

    Swift

    public func nextSequenceNumber() -> SWIM.SequenceNumber
  • Lifeguard IV.A. Local Health Multiplier (LHM)

    These different sources of feedback are combined in a Local Health Multiplier (LHM). LHM is a saturating counter, with a max value S and min value zero, meaning it will not increase above S or decrease below zero.

    The local health multiplier (LHM for short) is designed to relax the probeInterval and pingTimeout.

    The value MUST be >= 0.

    See also

    SWIM.Instance.LHModifierEvent for details how and when the LHM is adjusted.

    Declaration

    Swift

    public var localHealthMultiplier: Int { get set }
  • Creates a new SWIM algorithm instance.

    Declaration

    Swift

    public init(settings: SWIM.Settings, myself: SWIMPeer)
  • Adjust the Local Health-aware Multiplier based on the event causing it.

    Declaration

    Swift

    public func adjustLHMultiplier(_ event: LHModifierEvent)

    Parameters

    event

    event which causes the LHM adjustment.

  • Current SWIM protocol period (i.e. which round of gossip the instance is in).

    Declaration

    Swift

    public var protocolPeriod: Int { get }
  • Local Health Aware Suspicion timeout calculation, as defined Lifeguard IV.B.

    Suspicion timeout is logarithmically decaying from suspicionTimeoutPeriodsMax to suspicionTimeoutPeriodsMin depending on a number of suspicion confirmations.

    Suspicion timeout adjusted according to number of known independent suspicions of given member.

    See: Lifeguard IV-B: Local Health Aware Suspicion

    The timeout for a given suspicion is calculated as follows:

                                                log(C + 1) 􏰁
    SuspicionTimeout =􏰀 max(Min, Max  (MaxMin) ----------)
                                                log(K + 1)
    

    where:

    • Min and Max are the minimum and maximum Suspicion timeout. See Section V-C for discussion of their configuration.
    • K is the number of independent suspicions required to be received before setting the suspicion timeout to Min. We default K to 3.
    • C is the number of independent suspicions about that member received since the local suspicion was raised.

    Declaration

    Swift

    public func suspicionTimeout(suspectedByCount: Int) -> DispatchTimeInterval
  • Checks if a deadline is expired (relating to current time).

    Declaration

    Swift

    public func isExpired(deadline: DispatchTime) -> Bool

    Parameters

    deadline

    deadline we want to check if it’s expired

    Return Value

    true if the now() time is “past” the deadline

  • Create a gossip payload (i.e. a set of SWIM.Gossip messages) that should be gossiped with failure detector messages, or using some other medium.

    Declaration

    Swift

    public func makeGossipPayload(to target: SWIMAddressablePeer?) -> SWIM.GossipPayload

    Parameters

    target

    Allows passing the target peer this gossip will be sent to. If gossiping to a specific peer, and given peer is suspect, we will always prioritize letting it know that it is being suspected, such that it can refute the suspicion as soon as possible, if if still is alive.

    Return Value

    The gossip payload to be gossiped.

SWIM Member helper functions

  • Returns status of the passed in peer’s member of the cluster, if known.

    Declaration

    Swift

    public func status(of peer: SWIMAddressablePeer) -> SWIM.Status?

    Parameters

    peer

    the peer to look up the status for.

    Return Value

    Status of the peer, if known.

  • Checks if the passed in peer is already a known member of the swim cluster.

    Note: .dead members are eventually removed from the swim instance and as such peers are not remembered forever!

    Declaration

    Swift

    public func isMember(_ peer: SWIMAddressablePeer, ignoreUID: Bool = false) -> Bool

    Parameters

    peer

    Peer to check if it currently is a member

    ignoreUID

    Whether or not to ignore the peers UID, e.g. this is useful when issuing a “join 127.0.0.1:7337” command, while being unaware of the nodes specific UID. When it joins, it joins with the specific UID after all.

    Return Value

    true if the peer is currently a member of the swim cluster (regardless of status it is in)

  • Returns specific SWIM.Member instance for the passed in peer.

    Declaration

    Swift

    public func member(for peer: SWIMAddressablePeer) -> SWIM.Member?

    Parameters

    peer

    peer whose member should be looked up (by its node identity, including the UID)

    Return Value

    the peer’s member instance, if it currently is a member of this cluster

  • Returns specific SWIM.Member instance for the passed in node.

    Declaration

    Swift

    public func member(for node: ClusterMembership.Node) -> SWIM.Member?

    Parameters

    node

    node whose member should be looked up (matching also by node UID)

    Return Value

    the peer’s member instance, if it currently is a member of this cluster

  • Count of only non-dead members.

    See also

    SWIM.Status

    Declaration

    Swift

    public var notDeadMemberCount: Int { get }
  • Count of all “other” members known to this instance (meaning members other than myself).

    This is equal to n-1 where n is the number of nodes in the cluster.

    Declaration

    Swift

    public var otherMemberCount: Int { get }
  • Count of all members, including the myself node as well as any unreachable and dead nodes which are still kept in the membership.

    Declaration

    Swift

    public var allMemberCount: Int { get }
  • Lists all members known to this SWIM instance currently, potentially including even .dead nodes.

    Complexity

    O(1)

    Declaration

    Swift

    public var members: SWIM.Membership { get }

    Return Value

    Returns all current members of the cluster, including suspect, unreachable and potentially dead members.

On Periodic Ping Tick Handler

On Ping Handler

On Ping Response Handlers

On Ping Request

On Ping Request Response

Confirm Dead

Handling SWIM protocol interactions

SWIM Lifeguard Local Health Modifier event

  • Events which cause the modification of the Local health aware Multiplier to be adjusted.

    The LHM is increased (in increments of 1) whenever an event occurs that indicates that the instance is not processing incoming messages in timely order.

    It is decreased and decreased (by 1), whenever it processes a successful ping/ack cycle, meaning that is is healthy and properly processing incoming messages on time.

    See also

    Lifeguard IV.A. Local Health Aware Probe, which describes the rationale behind the events.
    See more

    Declaration

    Swift

    public enum LHModifierEvent : Equatable

SWIM Logging Metadata

  • Allows for convenient adding of additional metadata to the SWIM.Instance.metadata.

    Declaration

    Swift

    public func metadata(_ additional: Logger.Metadata) -> Logger.Metadata
  • While the SWIM.Instance is not meant to be logging by itself, it does offer metadata for loggers to use.

    Declaration

    Swift

    public var metadata: Logger.Metadata { get }