Skip to content

fix: rebalance over recycle on only tenant config conn change#1140

Merged
ferhatelmas merged 1 commit into
masterfrom
ferhat/rebalance-better
Jun 8, 2026
Merged

fix: rebalance over recycle on only tenant config conn change#1140
ferhatelmas merged 1 commit into
masterfrom
ferhat/rebalance-better

Conversation

@ferhatelmas

@ferhatelmas ferhatelmas commented Jun 8, 2026

Copy link
Copy Markdown
Member

What kind of change does this PR introduce?

Bug fix (performance improvement)

What is the current behavior?

On only max connections change for tenant config, pool is recycled which creates unnecessary connection/socket churn.

What is the new behavior?

Mutates the pool in place, increases are immediate and decreases are handled by idle timeout.

Additional context

Related to #1125 - prior approach
Related to #1096 - already has this approach

@ferhatelmas ferhatelmas requested a review from a team as a code owner June 8, 2026 11:20
Copilot AI review requested due to automatic review settings June 8, 2026 11:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts multitenant DB pool handling so that tenant config changes affecting only maxConnections no longer recycle (destroy/recreate) the cached pool, but instead rebalance it in place to reduce connection/socket churn while still applying increases immediately and letting decreases drain via normal idle behavior.

Changes:

  • Update onTenantConfigChange to call PoolManager.rebalance(...) when only maxConnections changes (and still destroy(...) on endpoint/pool-mode changes).
  • Add a targeted PoolManager.rebalance(tenantId, options) API and remove the previous recycle(...) API.
  • Update/add tests to validate rebalance behavior and the removal of recycle.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/test/tenant.test.ts Updates tenant-config change tests to expect rebalance (not recycle) on maxConnections changes.
src/internal/database/tenant.ts Switches max-connection-change handling from pool recycle to in-place rebalance; removes unused recycle settings builder.
src/internal/database/pool.ts Adds PoolManager.rebalance forwarding method and removes PoolManager.recycle.
src/internal/database/pool.test.ts Adds coverage for PoolManager.rebalance forwarding and asserts recycle is no longer part of the API.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/test/tenant.test.ts Outdated
Comment thread src/test/tenant.test.ts Outdated
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
@ferhatelmas ferhatelmas force-pushed the ferhat/rebalance-better branch from 0959b5b to adfdc93 Compare June 8, 2026 11:25
@coveralls

coveralls commented Jun 8, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 27134423353

Coverage decreased (-0.009%) to 76.438%

Details

  • Coverage decreased (-0.009%) from the base build.
  • Patch coverage: 4 of 4 lines across 2 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 11030
Covered Lines: 8861
Line Coverage: 80.34%
Relevant Branches: 6460
Covered Branches: 4508
Branch Coverage: 69.78%
Branches in Coverage %: Yes
Coverage Strength: 369.09 hits per line

💛 - Coveralls

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@ferhatelmas ferhatelmas merged commit 2d0a421 into master Jun 8, 2026
38 of 40 checks passed
@ferhatelmas ferhatelmas deleted the ferhat/rebalance-better branch June 8, 2026 11:33
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.

4 participants