go-clickhouse icon indicating copy to clipboard operation
go-clickhouse copied to clipboard

Multihost configuration for CH clusters

Open Termina1 opened this issue 2 years ago • 2 comments

Hi, official Clickhouse API support multiple hosts connection. It helps to evenly distribute load in cluster setup. As I understood this is no such option in this library. Do you plan on support it?

Termina1 avatar Feb 21 '23 15:02 Termina1

Hey,

In Uptrace we have a set of utility functions that pick up a random CH node, e.g.

func randCH() *ch.DB {}

randCH().NewSelect().Model(...).Scan(ctx)

I would recommend doing the same if you need to balance the load.

vmihailenco avatar Feb 24 '23 07:02 vmihailenco

where can i find this in code? i didn't find randCH() method of db .

Addr is single host in the struct. Cluster is using for only auto migrating tools.

type Config struct {
	chpool.Config

	Compression bool

	Addr     string
	User     string
	Password string
	Database string
	Cluster  string

	DialTimeout   time.Duration
	TLSConfig     *tls.Config
	QuerySettings map[string]any

	ReadTimeout  time.Duration
	WriteTimeout time.Duration

	MaxRetries      int
	MinRetryBackoff time.Duration
	MaxRetryBackoff time.Duration
}`

vortex14 avatar Sep 20 '24 08:09 vortex14