diff options
| author | Paul Buetow <paul@buetow.org> | 2023-06-19 21:19:48 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-06-19 21:19:48 +0300 |
| commit | dbf23cb423b15fd94930b042f402dfa8d8a76a17 (patch) | |
| tree | c859072fcd9270a04e3cfa325624cdbb28c8e860 | |
| parent | 1e970356767588ee309681cc7afbed798f108500 (diff) | |
use higher scores - update todos
| -rw-r--r-- | README.md | 7 | ||||
| -rw-r--r-- | internal/quorum/quorum.go | 19 | ||||
| -rw-r--r-- | internal/quorum/quorum_test.go | 12 |
3 files changed, 22 insertions, 16 deletions
@@ -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 |
