ClickHouse / ClickHouse/clickhouse-go
ConnOpenStrategy should trigger on every query and between life connections, to implement load balance
- Dominant language
- Go
- Stars
- 3.3k
- Forks
- 680
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 14
Description
### Describe the bug
ConnOpenStrategy should trigger on every query and between life connections,this my expect,but now i can only set the ConnMaxLifetime in a smaller interval,such as 3 seconds,and after 3 seconds,the connection idle,and trigger dialStrategy. i wish clickhouse-go should choose connections between the life and good connections. by th way, it should classify the connections by the Addr array. for example, my Addr= [127.0.0.1:29100,127.0.0.2:29100], when ConnOpenStrategy=ConnOpenRoundRobin and 127.0.0.1 and 127.0.0.2 is all good, every time i call connection to exec sql, it should round between 127.0.0.1 and 127.0.0.2.
maybe in the clickhouse-go inside, 127.0.0.1 and 127.0.0.2 has one more connection instance because of MaxOpenConns, but to the caller, he also can round between 127.0.0.1 and 127.0.0.2.
on the whole,i wish clickhouse-go can matain good addrs and good connections pool inside, it shoud clean bad or idle connections inside periodly. ConnOpenStrategy trigger on every query instead of dia.
### Code example
```go
conn, err := clickhouse.Open(&clickhouse.Options{
Addr: []string{
"127.0.0.1:29100",
"127.0.0.2:29100",
},
ConnOpenStrategy: clickhouse.ConnOpenRoundRobin,
Debug: true,
Auth: clickhouse.Auth{
Database: "default",
Username: "xx",
Password: "xx",
},
ConnMaxLifetime: 3 * time.Second,
})
if err != nil {
t.Log(err)
}
t.Log("=====================")
for i := 0; i < 3; i++ {
v, err := conn.ServerVersion()
if err != nil {
t.Log(err)
}
t.Log(v.String())
}
t.Log("=====================")
for i := 0; i < 3; i++ {
v, err := conn.ServerVersion()
if err != nil {
t.Log(err)
}
t.Log(v.String())
t.Log("sleep 5 seconds")
time.Sleep(5 * time.Second)
}
```
### log
```
main_test.go:191: =====================
[clickhouse][conn=1][127.0.0.1:29100][handshake] -> 0.0.0
[clickhouse][conn=1][127.0.0.1:29100][handshake] downgrade client proto
[clickhouse][conn=1][127.0.0.1:29100][handshake] <- ClickHouse (127.0.0.1) server version 22.3.3 revision 54455 (timezone Asia/Shanghai)
main_test.go:197: ClickHouse (127.0.0.1) server version 22.3.3 revision 54455 (timezone Asia/Shanghai)
main_test.go:197: ClickHouse (127.0.0.1) server version 22.3.3 revision 54455 (timezone Asia/Shanghai)
main_test.go:197: ClickHouse (127.0.0.1) server version 22.3.3 revision 54455 (timezone Asia/Shanghai)
main_test.go:199: =====================
main_test.go:205: ClickHouse (127.0.0.1) server version 22.3.3 revision 54455 (timezone Asia/Shanghai)
main_test.go:206: sleep 5 seconds
[clickhouse][conn=2][127.0.0.2:29100][handshake] -> 0.0.0
[clickhouse][conn=2][127.0.0.2:29100][handshake] downgrade client proto
[clickhouse][conn=2][127.0.0.2:29100][handshake] <- ClickHouse (127.0.0.2) server version 22.3.3 revision 54455 (timezone Asia/Shanghai)
main_test.go:205: ClickHouse (127.0.0.2) server version 22.3.3 revision 54455 (timezone Asia/Shanghai)
main_test.go:206: sleep 5 seconds
[clickhouse][conn=3][127.0.0.1:29100][handshake] -> 0.0.0
[clickhouse][conn=3][127.0.0.1:29100][handshake] downgrade client proto
[clickhouse][conn=3][127.0.0.1:29100][handshake] <- ClickHouse (127.0.0.1) server version 22.3.3 revision 54455 (timezone Asia/Shanghai)
main_test.go:205: ClickHouse (127.0.0.1) server version 22.3.3 revision 54455 (timezone Asia/Shanghai)
main_test.go:206: sleep 5 seconds
```
### Expected behaviour
every time call conn.ServerVersion()
it should print different ip from last time
Contributor guide
Research direction
Start at clickhouse.Open and trace how ConnOpenStrategy and ConnOpenRoundRobin affect conn.ServerVersion connections. The issue names no source files or tests; done should mean repeated ServerVersion calls rotate between healthy addresses while bad or idle connections are handled as requested.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100