Skip to content

Commit

Permalink
Merge pull request #209 from ClickHouse/feat/chpool-update-puddle
Browse files Browse the repository at this point in the history
feat(chpool): update jackc/puddle to v2.1.2
  • Loading branch information
ernado authored Nov 19, 2022
2 parents a0bf192 + b76df2a commit f6415c5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion chpool/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"time"

puddle "github.com/jackc/puddle/puddleg"
"github.com/jackc/puddle/v2"

"github.com/ClickHouse/ch-go"
)
Expand Down
2 changes: 1 addition & 1 deletion chpool/conn.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package chpool

import (
puddle "github.com/jackc/puddle/puddleg"
"github.com/jackc/puddle/v2"

"github.com/ClickHouse/ch-go"
)
Expand Down
19 changes: 13 additions & 6 deletions chpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/ClickHouse/ch-go"

puddle "github.com/jackc/puddle/puddleg"
"github.com/jackc/puddle/v2"
)

// Pool of connections to ClickHouse.
Expand Down Expand Up @@ -60,9 +60,8 @@ func Dial(ctx context.Context, opt Options) (*Pool, error) {
options: opt,
closeChan: make(chan struct{}),
}

p.pool = puddle.NewPool(
func(ctx context.Context) (*connResource, error) {
puddleConfig := &puddle.Config[*connResource]{
Constructor: func(ctx context.Context) (*connResource, error) {
c, err := ch.Dial(ctx, p.options.ClientOptions)
if err != nil {
return nil, err
Expand All @@ -73,9 +72,17 @@ func Dial(ctx context.Context, opt Options) (*Pool, error) {
clients: make([]Client, 64),
}, nil
},
func(c *connResource) {
Destructor: func(c *connResource) {
_ = c.client.Close()
}, opt.MaxConns)
},
MaxSize: opt.MaxConns,
}

pool, err := puddle.NewPool[*connResource](puddleConfig)
if err != nil {
return nil, err
}
p.pool = pool

if err := p.createIdleResources(ctx, int(p.options.MinConns)); err != nil {
p.Close()
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/go-faster/errors v0.6.1
github.com/google/uuid v1.3.0
github.com/hashicorp/go-version v1.6.0
github.com/jackc/puddle v1.2.2-0.20220404125616-4e959849469a
github.com/jackc/puddle/v2 v2.1.2
github.com/klauspost/compress v1.15.12
github.com/pierrec/lz4/v4 v4.1.17
github.com/segmentio/asm v1.2.0
Expand All @@ -22,7 +22,7 @@ require (
go.uber.org/atomic v1.10.0
go.uber.org/multierr v1.8.0
go.uber.org/zap v1.23.0
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
golang.org/x/sync v0.0.0-20220923202941-7f9b1623fab7
)

require (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/jackc/puddle v1.2.2-0.20220404125616-4e959849469a h1:oH7y/b+q2BEerCnARr/HZc1NxOYbKSJor4MqQXlhh+s=
github.com/jackc/puddle v1.2.2-0.20220404125616-4e959849469a/go.mod h1:ZQuO1Un86Xpe1ShKl08ERTzYhzWq+OvrvotbpeE3XO0=
github.com/jackc/puddle/v2 v2.1.2 h1:0f7vaaXINONKTsxYDn4otOAiJanX/BMeAtY//BXqzlg=
github.com/jackc/puddle/v2 v2.1.2/go.mod h1:2lpufsF5mRHO6SuZkm0fNYxM6SWHfvyFj62KwNzgels=
github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM=
github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
github.com/pascaldekloe/name v1.0.1 h1:9lnXOHeqeHHnWLbKfH6X98+4+ETVqFqxN09UXSjcMb0=
Expand Down Expand Up @@ -63,8 +63,8 @@ go.uber.org/zap v1.23.0 h1:OjGQ5KQDEUawVHxNwQgPpiypGHOxo2mNZsOqTak4fFY=
go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220923202941-7f9b1623fab7 h1:ZrnxWX62AgTKOSagEqxvb3ffipvEDX2pl7E1TdqLqIc=
golang.org/x/sync v0.0.0-20220923202941-7f9b1623fab7/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 h1:h+EGohizhe9XlX18rfpa8k8RAc5XyaeamM+0VHRd4lc=
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
Expand Down

0 comments on commit f6415c5

Please sign in to comment.