Two-Phase Commit Decision

easy · distributed-systems, transactions, coordination

Two-Phase Commit Decision

In Two-Phase Commit (2PC), the coordinator commits only if all participants vote to commit. Any abort or timeout forces an abort.

Given a list of votes, return the final decision: "commit" or "abort".

Votes are one of:

  • "commit"
  • "abort"
  • "timeout"

If votes is empty, return "abort".

Function signature

func TwoPhaseCommit(votes []string) string

Example

votes = ["commit", "commit", "timeout"]
output = "abort"
Run tests to see results
No issues detected