utils: use ShardIdentity in postgres_client.rs for improved type safety#12806
Open
lmcrean wants to merge 9 commits intoneondatabase:mainfrom
Open
utils: use ShardIdentity in postgres_client.rs for improved type safety#12806lmcrean wants to merge 9 commits intoneondatabase:mainfrom
ShardIdentity in postgres_client.rs for improved type safety#12806lmcrean wants to merge 9 commits intoneondatabase:mainfrom
Conversation
This is an empty commit to set up the branch for issue neondatabase#9823. The goal is to refactor ConnectionConfigArgs to use ShardIdentity instead of individual shard-related fields. Related to: neondatabase#9823
…th ShardIdentity in ConnectionConfigArgs
ShardIdentity in postgres_client.rs
…onnectionConfigArgs
…ld in recovery_stream
…ents Clarify PostgreSQL connection parameter format requirements and explain design decisions around shard field access patterns and JSON serialization.
Author
|
@erikgrinaker @VladLazar @arpad-m it's ready |
Contributor
|
Thanks for the cleanup! We're not merging refactors at the moment to avoid code churn with ongoing integration efforts, but we'll revisit this later. |
Author
Sure makes sense! |
ShardIdentity in postgres_client.rsShardIdentity in postgres_client.rs for improved type safety
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.
Summary
This PR refactors
postgres_client.rsto use the existingShardIdentitytype instead of individual primitive shard fields, improving type safety and reducing code duplication.Fixes #9823
Problem
The
ConnectionConfigArgsstruct inutils/postgres_client.rswas manually tracking shard information using individual primitive fields:This approach had several issues:
ShardIdentitytypeOption<T>fields instead of one cohesive parameterSolution
Phase 1: Move
ShardIdentitytoutilsShardIdentitystruct frompageserver_api/shard.rstoutils/shard.rsShardLayout,ShardConfigError,DEFAULT_STRIPE_SIZEpageserver_apito re-export fromutilsfor backward compatibilitypageserver_apiPhase 2: Refactor
ConnectionConfigArgsshard: Option<ShardIdentity>fieldoptions()method to extract values fromShardIdentityChanges Made
Core Infrastructure
libs/utils/src/shard.rs: AddedShardIdentitystruct with all core methodslibs/pageserver_api/src/shard.rs: Now re-exports from utils with pageserver-specific extensionslibs/utils/src/postgres_client.rs: Refactored to useOption<ShardIdentity>Updated Files
safekeeper/src/recovery.rs: UpdatedConnectionConfigArgsconstructorpageserver/src/tenant/timeline/walreceiver/connection_manager.rs: Updated constructorBenefits
Type Safety
Simplified API
Code Consistency
ShardIdentitytype as the rest of the codebaseTesting
Performance Impact
None - this is a purely structural refactoring with no runtime performance implications. The generated connection options remain identical.
Migration Guide
For code outside this repository using
ConnectionConfigArgs:Or for unsharded connections:
Backward Compatibility
ShardIdentitycontinue to work via re-exportsConnectionConfigArgsRelated
ShardIdentitytoutilsto avoid circular dependencies utils: useShardIdentityin `postgres_client.rs #9823Review Notes
This refactoring demonstrates several Rust best practices:
The changes are purely structural with no behavioral modifications, making this a safe refactoring that improves code quality without affecting functionality.