fix(cluster): name the sharding-state shard the way the server sends it - #622
Open
dudanogueira wants to merge 1 commit into
Open
fix(cluster): name the sharding-state shard the way the server sends it#622dudanogueira wants to merge 1 commit into
dudanogueira wants to merge 1 commit into
Conversation
ShardReplica carried no @SerializedName, so Gson looked for the field's own name, shardName. The server sends "shard" (entities/models/replication_shard_replicas.go), so the component was null on every server version and a sharding-state response could not identify its shards. The client installs its own field-naming strategy (JSON.java:74 -> PropertyFieldNamingStrategy -> PojoDescriptor.propertyName), which honours only the ORM @Property annotation and otherwise returns the field name -- so the expected key really was "shardName". "replicas" matched by coincidence, the field name and the wire name agreeing; it is annotated here too so the record no longer depends on that. The Java component keeps its name: @SerializedName bridges it without a breaking rename. No alternate spelling -- nothing was ever stored or sent as "shardName". Closes #621 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HNeKV7TAYZGDyT9agqJwUf
There was a problem hiding this comment.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Infrastructure as Code | View in Orca | ||
| SAST | View in Orca | ||
| Secrets | View in Orca | ||
| Vulnerabilities | View in Orca |
Collaborator
|
Please remove all comments from this PR and trim the PR description to what is strictly relevant. |
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.
Motivation
ShardReplicahas no@SerializedNameon either component, so Gson looks for the field's own name —shardName— while the server sendsshard:The result is
nullon every server version, so a sharding-state response cannot say which shard each replica set belongs to.This is not Gson's default
FIELDpolicy doing something surprising — the client installs its own strategy (JSON.java:74), andPojoDescriptor.propertyNamehonours only the ORM@Propertyannotation before falling back to the field name.replicasmatches purely because the field name and the wire name coincide.ClusterITest#test_shardingStatenever noticed because it only asserts that two shard lists differ; nothing reads the name.Approach
Annotate both components explicitly, matching the sibling records in this package (
Shard,ShardingState,Replication), which annotate every component.The Java component keeps the name
shardName—@SerializedNamebridges it, so there is no reason to make this a breaking rename.replicasis annotated too: it is a no-op today, but it stops the record depending on a coincidence between the field name and the wire name.Rejected: renaming the component to
shard. It would break callers to no benefit, andshardNameis the clearer Java name.No
alternatespelling — nothing was ever stored or sent asshardName, so this is the #612 case rather than the #610 one.Key areas for review
replicasis defensive rather than a fix. Say if you would rather this PR touched only the broken component.ShardingStateandListShardsResponsewere already fully annotated, so the fix is confined to this one record.Testing
Unit — one round-trip row in
JSONTest.testCases()covering aShardingStatecarrying oneShardReplica, which drives bothtest_serializeandtest_deserialize.Verified the test fails without the fix, in both directions — the read side being the one that matters:
No integration test:
GET /replication/sharding-stateanswers501on a single-node server, so an assertion on the name needs the multi-node harness.ClusterITest#test_shardingStatealready runs there and would be the place for one — happy to add.extracting(ShardReplica::shardName).doesNotContainNull()if you would like it covered end to end.Locally green: 384 unit tests.
Breaking changes
None. The Java component name and the accessor are unchanged; only the wire key the record asks for changes, and the old key never matched anything the server sends.
Conflict note
Adds a row at the end of
JSONTest.testCases(); #620 adds one in the same place. Whichever merges second wants a trivial rebase — same file, adjacent rows, no shared lines otherwise.Closes #621
🤖 Generated with Claude Code
https://claude.ai/code/session_01HNeKV7TAYZGDyT9agqJwUf