Skip to content

feat(db): honor an optional init_command on every connection pool - #228

Open
raghav-reglobe wants to merge 1 commit into
apache:masterfrom
raghav-reglobe:feat/pool-init-command
Open

feat(db): honor an optional init_command on every connection pool#228
raghav-reglobe wants to merge 1 commit into
apache:masterfrom
raghav-reglobe:feat/pool-init-command

Conversation

@raghav-reglobe

Copy link
Copy Markdown

What

Add an optional init_command to DatabaseConfig (global and token-bound), carry it in DatabasePoolConfig as a NotRequired key, and pass it to aiomysql.create_pool in _create_pool_with_candidates.

Why

Hosts that front Doris with a service account often need every pooled connection to start in a prepared session state: a session-narrowing switch, a SET of session variables, a workload-group pin. aiomysql's init_command is the right hook (it runs once per new connection), but the pool factory builds every pool without it. Today a host has to subclass DorisConnectionManager and re-implement pool creation just to add one statement, and then keep that subclass in lockstep with every refactor of the factory. On 0.6.1, where pool creation lived in six methods, such a subclass silently missed paths; 1.0.0 collapsed the factory into one method, which makes a config field the durable seam.

Behaviour

  • Unset (default): the key is omitted from the pool config, so existing pool configs stay byte-identical for equality-based callers and serialized configs.
  • Set on the global config: applies to the global pool; per-user pools inherit it.
  • Set on a token's database_config: applies to that token's pool.

Tests

test/utils/test_pool_init_command.py: global and token-bound paths pass the statement through, the default omits the key, an explicit pool config takes precedence. Existing pool tests unchanged.

Hosts that front Doris with a service account often need each pooled
connection to start in a prepared session state: a session-narrowing
switch, a SET of session variables, a workload-group pin. aiomysql's
init_command is the right hook (it runs once per new connection), but
_create_pool_with_candidates builds every pool without it, so a host has to
subclass DorisConnectionManager and re-implement pool creation just to add
one statement, and keep that subclass in lockstep with every refactor of the
factory. On 0.6.1, where pool creation lived in six methods, that subclass
silently missed paths.

Add an optional init_command to DatabaseConfig (global and token-bound),
carry it in DatabasePoolConfig as a NotRequired key, and pass it to
aiomysql.create_pool in the single pool factory. When unset the key is
omitted, so pool configs stay byte-identical for equality-based callers and
serialized configs. Per-user pools inherit the global value.

Tests cover the global and token-bound paths, the omitted default, and an
explicit pool config taking precedence.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Raghvendra Singh <raghav@cashify.in>
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.

1 participant