summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-10-21 12:47:46 +0300
committerPaul Buetow <paul@buetow.org>2023-10-21 12:47:46 +0300
commit61919768cfe4df8fbd709e8e6034f4c4c83def27 (patch)
tree17e69ec1a57aee73eb7300bf0bc9353ec29a9969
parent8af37a343946ee904b421cb6353ea294e31804df (diff)
make score file and winner file names configurable.
-rw-r--r--internal/config/config.go10
-rw-r--r--internal/quorum/quorum.go4
-rw-r--r--internal/server/server.go1
-rw-r--r--test/gorum-earth.json2
-rw-r--r--test/gorum-mars.json2
-rw-r--r--test/gorum-uranus.json2
6 files changed, 16 insertions, 5 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index 988315a..a882268 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -13,6 +13,8 @@ import (
type Config struct {
StateDir string
+ ScoreFile string
+ WinnerFile string
Address string
Nodes []string
LoopIntervalS int64 `json:"LoopIntervalS,omitempty"`
@@ -87,10 +89,15 @@ func WithRelaxedMode() func(*Config) {
}
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
}
-
if conf.MyID == "" {
hostname, err := os.Hostname()
if err != nil {
@@ -103,7 +110,6 @@ func (conf Config) setDefaults() (Config, error) {
for i, node := range conf.Nodes {
conf.nodeNumberCache[utils.StripPort(node)] = i
}
-
return conf, nil
}
diff --git a/internal/quorum/quorum.go b/internal/quorum/quorum.go
index b29b428..9bce682 100644
--- a/internal/quorum/quorum.go
+++ b/internal/quorum/quorum.go
@@ -185,11 +185,11 @@ func (quo *Quorum) persist(changed bool) error {
return err
}
- return writeFileViaTmp(fmt.Sprintf("%s/scores", quo.conf.StateDir), scoresStr)
+ return writeFileViaTmp(fmt.Sprintf("%s/%s", quo.conf.StateDir, quo.conf.ScoreFile), scoresStr)
}
func (quo *Quorum) persistWinner(winnerStr string) error {
- winnerFile := fmt.Sprintf("%s/is_winner", quo.conf.StateDir)
+ winnerFile := fmt.Sprintf("%s/%s", quo.conf.StateDir, quo.conf.WinnerFile)
if winnerStr == "" {
if _, err := os.Stat(winnerFile); err != nil {
return os.Remove(winnerFile)
diff --git a/internal/server/server.go b/internal/server/server.go
index c3e9e05..806d3a1 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -32,7 +32,6 @@ func runServer(ctx context.Context, conf config.Config, quo quorum.Quorum) error
defer cancel()
ch := make(chan vote.Vote)
-
go func() {
for {
select {
diff --git a/test/gorum-earth.json b/test/gorum-earth.json
index 2909ddb..5183e29 100644
--- a/test/gorum-earth.json
+++ b/test/gorum-earth.json
@@ -1,5 +1,7 @@
{
"StateDir": "./",
+ "ScoreFile": "scores.earth",
+ "WinnerFile": "is_winner.earth",
"MyID": "earth",
"RelaxedMode": true,
"Address": ":1234",
diff --git a/test/gorum-mars.json b/test/gorum-mars.json
index d4e2538..adecedf 100644
--- a/test/gorum-mars.json
+++ b/test/gorum-mars.json
@@ -1,5 +1,7 @@
{
"StateDir": "./",
+ "ScoreFile": "scores.mars",
+ "WinnerFile": "is_winner.mars",
"MyID": "mars",
"RelaxedMode": true,
"Address": ":2341",
diff --git a/test/gorum-uranus.json b/test/gorum-uranus.json
index a19d73c..bc00a7f 100644
--- a/test/gorum-uranus.json
+++ b/test/gorum-uranus.json
@@ -1,5 +1,7 @@
{
"StateDir": "./",
+ "ScoreFile": "scores.uranus",
+ "WinnerFile": "is_winner.uranus",
"MyID": "uranus",
"RelaxedMode": true,
"Address": ":3412",