From dbf23cb423b15fd94930b042f402dfa8d8a76a17 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 19 Jun 2023 21:19:48 +0300 Subject: use higher scores - update todos --- README.md | 7 +++++++ internal/quorum/quorum.go | 19 +++++++++---------- internal/quorum/quorum_test.go | 12 ++++++------ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0af0a57..eda378c 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,10 @@ Gogios is a minimalistic quorum manager. This project is still under development! + +## TODO + +* Finish this TODO +* Add `notify.go` from Gogios, to notify on state changes. +* Release Gorum +* Write a blog post diff --git a/internal/quorum/quorum.go b/internal/quorum/quorum.go index 19f4283..37b351c 100644 --- a/internal/quorum/quorum.go +++ b/internal/quorum/quorum.go @@ -92,7 +92,7 @@ func (quo Quorum) scores() (scores []Score) { } for _, id := range vote.IDs { score := scoreMap[id] - scoreMap[id] = score + 1 + scoreMap[id] = score + 100 } } @@ -106,7 +106,6 @@ func (quo Quorum) scores() (scores []Score) { } // Score tie, use node number. - // TODO: Don't do based on NodeNumber, but based on a priority i_, _ := quo.conf.NodeNumber(scores[i].ID) j_, _ := quo.conf.NodeNumber(scores[j].ID) return i_ < j_ @@ -135,20 +134,20 @@ func (quo *Quorum) persistScores() error { defer fd.Close() var sb strings.Builder - sb.WriteString("current pos id score\n") - for i, score := range scores { + sb.WriteString("At position ") + sb.WriteString(strconv.Itoa(i + 1)) + if score.ID == quo.conf.MyID { - sb.WriteString("yes") + sb.WriteString(" is current node ") } else { - sb.WriteString("no") + sb.WriteString(" is partner node ") } - sb.WriteString(" ") - sb.WriteString(strconv.Itoa(i)) - sb.WriteString(" ") sb.WriteString(score.ID) - sb.WriteString(" ") + + sb.WriteString(" with score of ") sb.WriteString(strconv.Itoa(score.Value)) + sb.WriteString("\n") } diff --git a/internal/quorum/quorum_test.go b/internal/quorum/quorum_test.go index 17d9789..169fd33 100644 --- a/internal/quorum/quorum_test.go +++ b/internal/quorum/quorum_test.go @@ -42,8 +42,8 @@ func TestScore(t *testing.T) { t.Errorf("Expected scores to be of length 3: %v", scores) } - if scores[0].ID != "bar" || scores[0].Value != 3 { - t.Errorf("Expected score[0] to be {bar,3}: %v", scores[0]) + if scores[0].ID != "bar" || scores[0].Value != 300 { + t.Errorf("Expected score[0] to be {bar,300}: %v", scores[0]) } } @@ -78,8 +78,8 @@ func TestTieScore(t *testing.T) { if len(scores) != 3 { t.Errorf("Expected scores to be of length 3: %v", scores) } - if scores[0].ID != "foo" || scores[0].Value != 3 { - t.Errorf("Expected score[0] to be {foo,3}: %v", scores[0]) + if scores[0].ID != "foo" || scores[0].Value != 300 { + t.Errorf("Expected score[0] to be {foo,300}: %v", scores[0]) } winner := scores[0].ID @@ -101,8 +101,8 @@ func TestTieScore(t *testing.T) { if len(scores) != 3 { t.Errorf("Expected scores to be of length 3: %v", scores) } - if scores[0].ID != "bar" || scores[0].Value != 3 { - t.Errorf("Expected score[0] to be {bar,3}: %v", scores[0]) + if scores[0].ID != "bar" || scores[0].Value != 300 { + t.Errorf("Expected score[0] to be {bar,300}: %v", scores[0]) } winner := scores[0].ID -- cgit v1.2.3