summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-11-04 15:22:23 +0200
committerPaul Buetow <paul@buetow.org>2023-11-04 15:22:23 +0200
commit09ecd479863cf5db5b91776b64324660e23eeb97 (patch)
tree69a5f05c3f6861ecaf98c7945391963e35e58757 /internal
parent4dbf8b4854db75b549f0417ce9654ee286c1adb6 (diff)
remove redundant is_winner WinnerFile
Diffstat (limited to 'internal')
-rw-r--r--internal/config/config.go4
-rw-r--r--internal/quorum/quorum.go25
2 files changed, 3 insertions, 26 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 {