Skip to content

feat(chpool): add healthcheck function#1088

Open
nmiculinic wants to merge 2 commits intoClickHouse:mainfrom
nmiculinic:add_pool_healhchecking
Open

feat(chpool): add healthcheck function#1088
nmiculinic wants to merge 2 commits intoClickHouse:mainfrom
nmiculinic:add_pool_healhchecking

Conversation

@nmiculinic
Copy link

@nmiculinic nmiculinic commented Aug 28, 2025

Summary

Adding chpool healthchecking option.

Defaulting to Ping

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added

@CLAassistant
Copy link

CLAassistant commented Aug 28, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ kavirajk
❌ Neven Miculinic


Neven Miculinic seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@nmiculinic nmiculinic force-pushed the add_pool_healhchecking branch 2 times, most recently from 901e513 to 5833ddf Compare August 28, 2025 10:48
@nmiculinic nmiculinic changed the title Add ch-pool healthchecking function feat(chpool healthcheck): Adding healthcheck function to chpool Aug 28, 2025
@nmiculinic nmiculinic force-pushed the add_pool_healhchecking branch from 5833ddf to f6bed41 Compare August 28, 2025 10:53
@nmiculinic nmiculinic changed the title feat(chpool healthcheck): Adding healthcheck function to chpool feat(chpool): Add health-check function Aug 28, 2025
@nmiculinic nmiculinic force-pushed the add_pool_healhchecking branch 2 times, most recently from e664181 to c8638bb Compare August 28, 2025 10:54
@nmiculinic nmiculinic changed the title feat(chpool): Add health-check function feat(chpool): add healthcheck function Aug 28, 2025
}
}

func (p *Pool) connIsHealthy(res *puddle.Resource[*connResource]) bool {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to change this name to something better

o.HealthCheckTimeout = DefaultHealthCheckTimeout
}
if o.ClientOptions.Logger == nil {
o.ClientOptions.Logger = zap.NewNop()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To prevent any nil-ptr exception later

@nmiculinic nmiculinic force-pushed the add_pool_healhchecking branch 8 times, most recently from 68dfbb1 to 50d4213 Compare August 28, 2025 11:56
@nmiculinic nmiculinic marked this pull request as ready for review August 28, 2025 11:57
@nmiculinic nmiculinic force-pushed the add_pool_healhchecking branch from 50d4213 to 10694d0 Compare August 28, 2025 12:24
@nmiculinic
Copy link
Author

@SpencerTorres @ernado mind having a look at this PR?

@SpencerTorres
Copy link
Member

@ernado perhaps you're more familiar with this pooling code?

@ernado
Copy link
Collaborator

ernado commented Sep 16, 2025

This code was contributed + I'm not using pools, so I'm familiar in same degree as you.

@nmiculinic
Copy link
Author

@SpencerTorres @ernado any movement on this? What would make you happy to accept this PR

@SpencerTorres
Copy link
Member

@kavirajk Hey this one has been open for a while, would you be able to take a look?

@SpencerTorres
Copy link
Member

@nmiculinic apologies for the delay, could you sign the CLA? It's the first comment in this thread

@kavirajk kavirajk self-assigned this Jan 9, 2026
}

c.res.Release()
// calling async since connIsHealthy may block
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm failing to understand why move this to non-async. From the user POV, when I call c.Release() I would expect to release the connection to the pool immediately (not eventually).

assert.Equal(t, int64(0), atomic.LoadInt64(&healthCheckCnt))

conn.Release()
waitForReleaseToComplete()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would just make the test more fragile IMHO. Again I understand this is the result of making the release async. See my above comment.

c.res.Release()
// calling async since connIsHealthy may block
go func() {
if c.p.connIsHealthy(c.res) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also curious why is just client.IsClosed() is not good enough here? why introduce connIsHealthy based on ping() that connection?

To me it looks like your use case is not properly handled with just simple check client.IsClosed(). May I know why?

My understanding is, if the health check is passing on the given connection, it should return correct status on client.IsClosed() no? why introduce another layer of additional checks?

res.ReleaseUnused()
}
}()
wg.Wait()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I don't think calling wg.Wait() here inside the loop will do what you expected to do. Usually you start all the goroutines (inside the for loop here). Then call wg.Wait() once all the go-routines are spawned (basically outside the loop here)

Calling inside the loop just forces each go-routine to finish before starting the another (sequential not concurrent).

May be I'm missing something here?

assert.GreaterOrEqual(t, int64(1), atomic.LoadInt64(&healthCheckCnt))

hc := atomic.LoadInt64(&healthCheckCnt)
time.Sleep(750 * time.Millisecond)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This random sleep going to make the tests only more fragile IMHO

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

Successfully merging this pull request may close these issues.

5 participants