diff --git a/pkg/cli/debug_recover_loss_of_quorum_test.go b/pkg/cli/debug_recover_loss_of_quorum_test.go index 863738a36136..d59314b6b669 100644 --- a/pkg/cli/debug_recover_loss_of_quorum_test.go +++ b/pkg/cli/debug_recover_loss_of_quorum_test.go @@ -265,3 +265,52 @@ func createIntentOnRangeDescriptor( t.Fatal(err) } } + +// TestJsonSerialization verifies that all fields serialized in JSON could be +// read back. This specific test addresses issues where default naming scheme +// may not work in combination with other tags correctly. e.g. repeated used +// with omitempty seem to use camelcase unless explicitly specified. +func TestJsonSerialization(t *testing.T) { + defer leaktest.AfterTest(t)() + + rt := roachpb.VOTER_INCOMING + nr := loqrecoverypb.NodeReplicaInfo{ + Replicas: []loqrecoverypb.ReplicaInfo{ + { + NodeID: 1, + StoreID: 2, + Desc: roachpb.RangeDescriptor{ + RangeID: 3, + StartKey: roachpb.RKey(keys.MetaMin), + EndKey: roachpb.RKey(keys.MetaMax), + InternalReplicas: []roachpb.ReplicaDescriptor{ + { + NodeID: 1, + StoreID: 2, + ReplicaID: 3, + Type: &rt, + }, + }, + NextReplicaID: 4, + Generation: 7, + }, + RaftAppliedIndex: 13, + RaftCommittedIndex: 19, + RaftLogDescriptorChanges: []loqrecoverypb.DescriptorChangeInfo{ + { + ChangeType: 1, + Desc: &roachpb.RangeDescriptor{}, + OtherDesc: &roachpb.RangeDescriptor{}, + }, + }, + }, + }, + } + jsonpb := protoutil.JSONPb{Indent: " "} + data, err := jsonpb.Marshal(nr) + require.NoError(t, err) + + var nrFromJSON loqrecoverypb.NodeReplicaInfo + require.NoError(t, jsonpb.Unmarshal(data, &nrFromJSON)) + require.Equal(t, nr, nrFromJSON, "objects before and after serialization") +} diff --git a/pkg/kv/kvserver/loqrecovery/loqrecoverypb/recovery.proto b/pkg/kv/kvserver/loqrecovery/loqrecoverypb/recovery.proto index fe0427288a3e..0ec526207714 100644 --- a/pkg/kv/kvserver/loqrecovery/loqrecoverypb/recovery.proto +++ b/pkg/kv/kvserver/loqrecovery/loqrecoverypb/recovery.proto @@ -47,7 +47,7 @@ message ReplicaInfo { uint64 raft_applied_index = 4; uint64 raft_committed_index = 5; repeated DescriptorChangeInfo raft_log_descriptor_changes = 6 [(gogoproto.nullable) = false, - (gogoproto.jsontag) = ",omitempty"]; + (gogoproto.jsontag) = "raft_log_descriptor_changes,omitempty"]; } // Collection of replica information gathered from a collect-info run on a single node.