feat(db): honor an optional init_command on every connection pool - #228
Open
raghav-reglobe wants to merge 1 commit into
Open
feat(db): honor an optional init_command on every connection pool#228raghav-reglobe wants to merge 1 commit into
raghav-reglobe wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Add an optional
init_commandtoDatabaseConfig(global and token-bound), carry it inDatabasePoolConfigas aNotRequiredkey, and pass it toaiomysql.create_poolin_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
SETof session variables, a workload-group pin. aiomysql'sinit_commandis the right hook (it runs once per new connection), but the pool factory builds every pool without it. Today a host has to subclassDorisConnectionManagerand 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
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.