Skip to content

Commit

Permalink
kvserver: simplify proposal encoding in tests
Browse files Browse the repository at this point in the history
Replace a code snippet with a drop-in solution that exists now.
  • Loading branch information
tbg committed Jul 4, 2023
1 parent e24cafd commit 3d1760f
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions pkg/kv/kvserver/replica_proposal_buf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,11 @@ func (pc proposalCreator) newProposal(ba *kvpb.BatchRequest) *ProposalData {
}

func (pc proposalCreator) encodeProposal(p *ProposalData) []byte {
cmdLen := p.command.Size()
needed := raftlog.RaftCommandPrefixLen + cmdLen + kvserverpb.MaxRaftCommandFooterSize()
data := make([]byte, raftlog.RaftCommandPrefixLen, needed)
raftlog.EncodeRaftCommandPrefix(data, raftlog.EntryEncodingStandardWithoutAC, p.idKey)
data = data[:raftlog.RaftCommandPrefixLen+p.command.Size()]
if _, err := protoutil.MarshalToSizedBuffer(p.command, data[raftlog.RaftCommandPrefixLen:]); err != nil {
b, err := raftlog.EncodeCommand(context.Background(), p.command, p.idKey, nil /* raftAdmissionMeta */)
if err != nil {
panic(err)
}
return data
return b
}

// TestProposalBuffer tests the basic behavior of the Raft proposal buffer.
Expand Down

0 comments on commit 3d1760f

Please sign in to comment.