diff options
| author | Paul Buetow <paul@buetow.org> | 2023-06-20 02:06:22 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-06-20 02:06:22 +0300 |
| commit | 84e5a4ae93eed6397a6cbf6091a0f5b3eacc78e2 (patch) | |
| tree | 4f0eec662496e9e420bc7c9f4c9743bbe2369d60 /internal | |
| parent | ffb4f2dd193f631ac85c4c650163491b41eefefd (diff) | |
add expiry log
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/config/config.go | 7 | ||||
| -rw-r--r-- | internal/quorum/quorum.go | 7 |
2 files changed, 10 insertions, 4 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index ff8d452..ec4ea67 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -83,7 +83,8 @@ func (conf Config) NodeNumber(node string) int { return nodeNumber } - log.Println("config:", fmt.Errorf("node %s not found - it will affect it's score!", node)) + log.Println("config:", + fmt.Errorf("node %s not found - it will affect it's score!", node)) return 0 } @@ -99,7 +100,9 @@ func (conf Config) IsNode(remoteAddr string) bool { return false } -func (conf Config) IsNodeWithLookup(remoteAddr string, lookupIP func(string) ([]net.IP, error)) bool { +func (conf Config) IsNodeWithLookup(remoteAddr string, + lookupIP func(string) ([]net.IP, error)) bool { + remoteAddr = utils.StripPort(remoteAddr) for _, node := range conf.Nodes { diff --git a/internal/quorum/quorum.go b/internal/quorum/quorum.go index 25852b2..d33db56 100644 --- a/internal/quorum/quorum.go +++ b/internal/quorum/quorum.go @@ -42,6 +42,7 @@ func (quo Quorum) Start(ctx context.Context) <-chan vote.Vote { interval := time.Second * time.Duration(quo.conf.LoopIntervalS) if vote.Expiry <= interval { + // TODO: When to use log.Fatal and when to use panic? log.Fatal("quorum: LoopIntervalS ", quo.conf.LoopIntervalS, " should be less than the vote expiry of ", vote.Expiry) } @@ -64,7 +65,7 @@ func (quo Quorum) Start(ctx context.Context) <-chan vote.Vote { case <-ctx.Done(): return } - if err := quo.persistScores(); err != nil { + if err := quo.persist(); err != nil { log.Println("quorum:", err) } } @@ -108,7 +109,7 @@ func (quo Quorum) scores() (scores []Score) { return } -func (quo *Quorum) persistScores() error { +func (quo *Quorum) persist() error { scores := quo.scores() log.Println("quorum scores:", scores) @@ -121,6 +122,7 @@ func (quo *Quorum) persistScores() error { stateFile := fmt.Sprintf("%s/scores", quo.conf.StateDir) stateTmpFile := fmt.Sprintf("%s.tmp", stateFile) + // TODO: Also create a "is_leader" marker file in the fs! fd, err := os.Create(stateTmpFile) if err != nil { return err @@ -179,6 +181,7 @@ func (quo Quorum) pruneVotes() (vote.Vote, error) { for fromNode, vote := range quo.votes { if vote.Expired() { + log.Println("quorum: vote", vote, "from node", fromNode, "expired!") expired = append(expired, fromNode) continue } |
