SWIM Suspicion Round

medium · distributed-systems, membership, failure-detection, gossip

SWIM Suspicion Round

You are simulating one SWIM failure-detection round. Each node has a current membership state and a suspicion count. Reports from other nodes can increase or reset suspicion.

Rules (processed in order):

  • alive report: if the target is not dead, set state to alive, reset SuspectCount to 0, and clear any counted reporters for this round.
  • suspect report: if the target is alive and the reporter has not already reported this target since the last reset, increment SuspectCount.
  • If SuspectCount >= K, mark the target suspect (if not dead).
  • Reports about dead nodes are ignored.

Return the updated membership list in the same order as input.

Types

type Member struct {
    ID           int
    State        string // "alive", "suspect", "dead"
    SuspectCount int
}

type Report struct {
    Target   int
    Reporter int
    Kind     string // "alive" or "suspect"
}

Function signature

func SwimSuspectRound(members []Member, reports []Report, k int) []Member

Example

K = 2
members = [
  {ID:1, State:"alive", SuspectCount:0},
  {ID:2, State:"alive", SuspectCount:1},
]
reports = [
  {Target:2, Reporter:9, Kind:"suspect"},
]

Result: member 2 becomes "suspect" with SuspectCount=2

Constraints

  • 0 <= len(members), len(reports) <= 100000
  • 1 <= k <= 1000
  • IDs are unique in members

Notes

  • If the target is dead, leave it unchanged.
  • Duplicate suspect reports from the same reporter in the same round count once.
Run tests to see results
No issues detected