-
Notifications
You must be signed in to change notification settings - Fork 764
utils: use ShardIdentity
in postgres_client.rs
for improved type safety
#12806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lmcrean
wants to merge
9
commits into
neondatabase:main
Choose a base branch
from
lmcrean:improvement/9823-shard-identity-refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
utils: use ShardIdentity
in postgres_client.rs
for improved type safety
#12806
lmcrean
wants to merge
9
commits into
neondatabase:main
from
lmcrean:improvement/9823-shard-identity-refactor
Conversation
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
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.
@erikgrinaker @VladLazar @arpad-m it's ready |
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. |
Sure makes sense! |
ShardIdentity
in postgres_client.rs
ShardIdentity
in postgres_client.rs
for improved type safety
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.rs
to use the existingShardIdentity
type instead of individual primitive shard fields, improving type safety and reducing code duplication.Fixes #9823
Problem
The
ConnectionConfigArgs
struct inutils/postgres_client.rs
was manually tracking shard information using individual primitive fields:This approach had several issues:
ShardIdentity
typeOption<T>
fields instead of one cohesive parameterSolution
Phase 1: Move
ShardIdentity
toutils
ShardIdentity
struct frompageserver_api/shard.rs
toutils/shard.rs
ShardLayout
,ShardConfigError
,DEFAULT_STRIPE_SIZE
pageserver_api
to re-export fromutils
for backward compatibilitypageserver_api
Phase 2: Refactor
ConnectionConfigArgs
shard: Option<ShardIdentity>
fieldoptions()
method to extract values fromShardIdentity
Changes Made
Core Infrastructure
libs/utils/src/shard.rs
: AddedShardIdentity
struct 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
: UpdatedConnectionConfigArgs
constructorpageserver/src/tenant/timeline/walreceiver/connection_manager.rs
: Updated constructorBenefits
Type Safety
Simplified API
Code Consistency
ShardIdentity
type 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
ShardIdentity
continue to work via re-exportsConnectionConfigArgs
Related
ShardIdentity
toutils
to avoid circular dependencies utils: useShardIdentity
in `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.