diff options
| author | Paul Buetow <paul@buetow.org> | 2023-11-04 15:22:23 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-11-04 15:22:23 +0200 |
| commit | 09ecd479863cf5db5b91776b64324660e23eeb97 (patch) | |
| tree | 69a5f05c3f6861ecaf98c7945391963e35e58757 /internal/quorum | |
| parent | 4dbf8b4854db75b549f0417ce9654ee286c1adb6 (diff) | |
remove redundant is_winner WinnerFile
Diffstat (limited to 'internal/quorum')
| -rw-r--r-- | internal/quorum/quorum.go | 25 |
1 files changed, 3 insertions, 22 deletions
diff --git a/internal/quorum/quorum.go b/internal/quorum/quorum.go index ab24063..9bce233 100644 --- a/internal/quorum/quorum.go +++ b/internal/quorum/quorum.go @@ -134,7 +134,7 @@ func (quo Quorum) scores() (scores Scores) { return } -func (quo *Quorum) strs() (string, string) { +func (quo *Quorum) strs() string { scores := quo.scores() log.Println("quorum scores:", scores) winner, err := scores.Winner() @@ -143,7 +143,6 @@ func (quo *Quorum) strs() (string, string) { } var sb strings.Builder - winnerStr := "" for i, score := range scores { sb.WriteString("At position ") @@ -151,9 +150,6 @@ func (quo *Quorum) strs() (string, string) { if score.ID == quo.conf.MyID { sb.WriteString(" is current node ") - if score.Is(winner) { - winnerStr = fmt.Sprintf("Yeah, I, %s, am the winner!", winner.ID) - } } else { sb.WriteString(" is partner node ") } @@ -169,11 +165,11 @@ func (quo *Quorum) strs() (string, string) { sb.WriteString("\n") } - return winnerStr, sb.String() + return sb.String() } func (quo *Quorum) persist(changed bool) error { - winnerStr, scoresStr := quo.strs() + scoresStr := quo.strs() if changed { if err := notify(quo.conf, "GORUM: Quorum changed", scoresStr); err != nil { @@ -187,24 +183,9 @@ func (quo *Quorum) persist(changed bool) error { } } - if err := quo.persistWinner(winnerStr); err != nil { - return err - } - return writeFileViaTmp(fmt.Sprintf("%s/%s", quo.conf.StateDir, quo.conf.ScoreFile), scoresStr) } -func (quo *Quorum) persistWinner(winnerStr string) error { - winnerFile := fmt.Sprintf("%s/%s", quo.conf.StateDir, quo.conf.WinnerFile) - if winnerStr == "" { - if _, err := os.Stat(winnerFile); err != nil { - return os.Remove(winnerFile) - } - return nil - } - return writeFileViaTmp(winnerFile, winnerStr) -} - func (quo *Quorum) makeMyVote() (vote.Vote, bool) { newVote, err := quo.expireOldVotes() if err != nil { |
