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

feat: create a pool without test connect #247

Merged
merged 1 commit into from
Feb 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions chpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,18 @@ func (o *Options) setDefaults() {
}

// Dial returns a pool of connections to ClickHouse.
// Checks if ClickHouse is available, fails if not.
func Dial(ctx context.Context, opt Options) (*Pool, error) {
opt.setDefaults()
return new(ctx, opt, true)
}

// New returns a pool of connections to ClickHouse.
func New(ctx context.Context, opt Options) (*Pool, error) {
return new(ctx, opt, false)
}

func new(ctx context.Context, opt Options, dial bool) (*Pool, error) {
opt.setDefaults()
p := &Pool{
options: opt,
closeChan: make(chan struct{}),
Expand Down Expand Up @@ -89,12 +98,14 @@ func Dial(ctx context.Context, opt Options) (*Pool, error) {
return nil, err
}

res, err := p.pool.Acquire(ctx)
if err != nil {
p.Close()
return nil, err
if dial {
res, err := p.pool.Acquire(ctx)
if err != nil {
p.Close()
return nil, err
}
res.Release()
}
res.Release()

go p.backgroundHealthCheck()

Expand Down