From 09ecd479863cf5db5b91776b64324660e23eeb97 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 4 Nov 2023 15:22:23 +0200 Subject: remove redundant is_winner WinnerFile --- internal/config/config.go | 4 ---- internal/quorum/quorum.go | 25 +++---------------------- test/gorum-earth.json | 1 - test/gorum-mars.json | 1 - test/gorum-uranus.json | 1 - 5 files changed, 3 insertions(+), 29 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 09ccb7e..3968268 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -27,7 +27,6 @@ type Config struct { StateDir string LogToSyslog bool `json:"LogToSyslog,omitempty"` ScoreFile string - WinnerFile string Address string Nodes map[string]Node LoopIntervalS int64 `json:"LoopIntervalS,omitempty"` @@ -122,9 +121,6 @@ func (conf Config) setDefaults() (Config, error) { if conf.ScoreFile == "" { conf.ScoreFile = "scores" } - if conf.WinnerFile == "" { - conf.WinnerFile = "is_winner" - } if conf.LoopIntervalS == 0 { conf.LoopIntervalS = 10 } 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 { diff --git a/test/gorum-earth.json b/test/gorum-earth.json index d0c1660..0dc0d34 100644 --- a/test/gorum-earth.json +++ b/test/gorum-earth.json @@ -1,7 +1,6 @@ { "StateDir": "./", "ScoreFile": "scores.earth", - "WinnerFile": "is_winner.earth", "MyID": "earth", "RelaxedMode": true, "Address": "localhost:1234", diff --git a/test/gorum-mars.json b/test/gorum-mars.json index 2430eb3..72407c5 100644 --- a/test/gorum-mars.json +++ b/test/gorum-mars.json @@ -1,7 +1,6 @@ { "StateDir": "./", "ScoreFile": "scores.mars", - "WinnerFile": "is_winner.mars", "MyID": "mars", "RelaxedMode": true, "Address": ":1235", diff --git a/test/gorum-uranus.json b/test/gorum-uranus.json index a95f5a2..d57aa8f 100644 --- a/test/gorum-uranus.json +++ b/test/gorum-uranus.json @@ -1,7 +1,6 @@ { "StateDir": "./", "ScoreFile": "scores.uranus", - "WinnerFile": "is_winner.uranus", "MyID": "uranus", "RelaxedMode": true, "Address": ":1236", -- cgit v1.2.3