Skip to content

Commit 020666a

Browse files
author
Ian Pye
committed
Going to floats for weights
1 parent da9a61f commit 020666a

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

cluster/era.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,19 @@ func (s *WeightedEra) GetNode(posit int) *WeightedNode {
5050
}
5151

5252
func (s *WeightedEra) NormalizeAndPopulateMap() {
53-
total := uint32(0)
54-
scalar := uint32(1)
53+
total := float32(0)
54+
scalar := float32(1)
5555
for _, n := range s.nodes {
5656
wn := n.(*WeightedNode)
57-
total += wn.weight
57+
total += float32(wn.weight)
5858
}
5959

6060
if total == 0 {
61-
slog.Logf(logger.Levels.Error, "Total Node Wieght 0")
61+
slog.Logf(logger.Levels.Error, "Total Node Weight 0")
6262
return
6363
}
6464

65+
slog.Logf(logger.Levels.Debug, "Total Node Weight %f", total)
6566
if total < MAX_WEIGHT {
6667
// Scale weights up
6768
scalar = MAX_WEIGHT / total
@@ -71,7 +72,7 @@ func (s *WeightedEra) NormalizeAndPopulateMap() {
7172
lastPosit := 0
7273
for _, n := range s.nodes {
7374
wn := n.(*WeightedNode)
74-
wn.weight = ((wn.weight * scalar) / total) * MAX_WEIGHT
75+
wn.weight = uint32(((float32(wn.weight) * scalar) / total) * MAX_WEIGHT)
7576
slog.Logf(logger.Levels.Debug, "New Weight %d", wn.weight)
7677
for i := lastPosit; uint32(i) < wn.weight && i < MAX_WEIGHT; i++ {
7778
s.nodeMap[i] = wn

transport/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ func (src *Client) connect() error {
200200
}
201201
sendData(sndChData, bytes, seq)
202202
writesNotCompleted += 1
203-
slog.Gm.Event(&opName) // These are bactched
203+
slog.Gm.Event(&opName) // These are batched
204+
//slog.Logf(logger.Levels.Debug, "Sent batch -- length %d seq %d", len(bytes), seq)
204205
}
205206
case cnt := <-writeNotifier.NotificationChannel():
206207
writesNotCompleted -= cnt

0 commit comments

Comments
 (0)