Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Cluster IP #69

Open
gangtao opened this issue Jul 8, 2024 · 1 comment
Open

Support Cluster IP #69

gangtao opened this issue Jul 8, 2024 · 1 comment

Comments

@gangtao
Copy link
Collaborator

gangtao commented Jul 8, 2024

For proton cluster, need to support cluster ip addresses

  1. make sure cluster ip works
conn := proton.OpenDB(&proton.Options{
		Addr: []string{"ip1:8463","ip2:8463,"ip3:8463"},
		Auth: proton.Auth{
			Username: "default",
			Password: "",
		},
	})
	var value int
	conn.QueryRow("SELECT 300").Scan(&value)
	fmt.Println(value)
  1. client level load balancer

implement a round robin based query load balancing

@Yibo-Chen13
Copy link
Collaborator

Go driver does poll all cluster IP and select the first IP that connects successfully.

func (ch *proton) dial(ctx context.Context) (conn *connect, err error) {
	connID := int(atomic.AddInt64(&ch.connID, 1))
	for num := range ch.opt.Addr {
		if ch.opt.ConnOpenStrategy == ConnOpenRoundRobin {
			num = int(connID) % len(ch.opt.Addr)
		}
		if conn, err = dial(ctx, ch.opt.Addr[num], connID, ch.opt); err == nil {
			return conn, nil
		}
	}
	return nil, err
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants