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.
-
The
SWIM.Member
representing this instance, also referred to as “myself”. -
Sequence numbers are used to identify messages and pair them up into request/replies.
See also
SWIM.SequenceNumber
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
andpingTimeout
.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.
-
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
tosuspicionTimeoutPeriodsMin
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 − (Max−Min) ----------) log(K + 1)
where:
Min
andMax
are the minimum and maximum Suspicion timeout. See SectionV-C
for discussion of their configuration.K
is the number of independent suspicions required to be received before setting the suspicion timeout toMin
. We defaultK
to3
.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.
-
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.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
wheren
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.
-
Declaration
Swift
public func onPeriodicPingTick() -> [PeriodicPingTickDirective]
-
Describes how a periodic tick should be handled.
See moreDeclaration
Swift
public enum PeriodicPingTickDirective
-
Declaration
Swift
public func onPing(pingOrigin: SWIMPingOriginPeer, payload: SWIM.GossipPayload, sequenceNumber: SWIM.SequenceNumber) -> [PingDirective]
-
Directs a shell implementation about how to handle an incoming
See more.ping
.Declaration
Swift
public enum PingDirective
-
Declaration
Swift
public func onPingResponse(response: SWIM.PingResponse, pingRequestOrigin: SWIMPingRequestOriginPeer?, pingRequestSequenceNumber: SWIM.SequenceNumber?) -> [PingResponseDirective]
-
Directs a shell implementation about how to handle an incoming
See more.pingRequest
.Declaration
Swift
public enum PingResponseDirective
-
Describes how a pingRequest should be performed.
Only a single
See moretarget
peer is used, however it may be pinged “through” a few other members. The amount of fan-out in pingRequests is configurable byswim.indirectProbeCount
.Declaration
Swift
public struct SendPingRequestDirective
-
Declaration
Swift
public func onPingRequest( target: SWIMPeer, pingRequestOrigin: SWIMPingRequestOriginPeer, payload: SWIM.GossipPayload, sequenceNumber: SWIM.SequenceNumber ) -> [PingRequestDirective]
-
Directs a shell implementation about how to handle an incoming
See more.pingRequest
.Declaration
Swift
public enum PingRequestDirective
-
This should be called on first successful (non-nack) pingRequestResponse
Declaration
Swift
public func onPingRequestResponse(_ response: SWIM.PingResponse, pinged pingedPeer: SWIMPeer) -> [PingRequestResponseDirective]
-
Declaration
Swift
public func onEveryPingRequestResponse(_ result: SWIM.PingResponse, pinged peer: SWIMPeer) -> [SWIM.Instance.PingRequestResponseDirective]
-
Directs a shell implementation about how to handle an incoming ping request response.
See moreDeclaration
Swift
public enum PingRequestResponseDirective
-
Indicates the gossip payload was processed and changes to the membership were made.
See moreDeclaration
Swift
public enum GossipProcessedDirective
-
Declaration
Swift
public func confirmDead(peer: SWIMPeer) -> ConfirmDeadDirective
-
Directs how to handle the result of a
See moreconfirmDead
call.Declaration
Swift
public enum ConfirmDeadDirective
-
Declaration
Swift
public var debugDescription: String { get }
-
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.Declaration
Swift
public enum LHModifierEvent : Equatable
-
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 }