Skip to content

Commit

Permalink
simple round robin selection of slave nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
mhkarimi1383 committed Feb 20, 2022
1 parent 6a6f5eb commit 7e4f3db
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/proxy/cmd/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd
import (
"context"
"fmt"
"math/rand"
"net"
"net/http"
"sync"
Expand Down Expand Up @@ -249,14 +250,19 @@ func (c *ClusterChecker) Check() error {

db, ok := cd.DBs[proxy.Spec.MasterDBUID]
if cfg.slaveNode {
var slaveNodes []*cluster.DB
log.Infow("you want slave node kaastolon is here to help you")
ok = false
for k, v := range cd.DBs {
if k != proxy.Spec.MasterDBUID && v.Status.Healthy {
ok = true
db = v
log.Debugf("adding node %v to healthy node list", v.UID)
slaveNodes = append(slaveNodes, v)
}
}
randNum := rand.Intn(len(slaveNodes))
log.Infof("currently selected node is %v", slaveNodes[randNum].UID)
db = slaveNodes[randNum]
}
if !ok {
log.Infow("no db object available, closing connections to node", "db", proxy.Spec.MasterDBUID)
Expand Down

0 comments on commit 7e4f3db

Please sign in to comment.