raft: make the entries encoding maintainable #131561
Labels
A-kv-replication
Relating to Raft, consensus, and coordination.
C-cleanup
Tech debt, refactors, loose ends, etc. Solution not expected to significantly change behavior.
C-enhancement
Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
Entries in
raft
contain the user-defined commands in a[]byte
slice, which our application layer has freedom to define. Today, we have the ever-growing encodings list + ad-hoc entryentry.Data
parsing sprinkled in random places. This gets harder to maintain and reason about.The pattern is that the first byte of
Data
contains the "encoding", and we then parse the entry differently, depending on this byte. We often want to sneak peek into the entry's "header" without parsing it entirely, because in most cases it is a protobuf with non-zero unmarshaling cost.It would be great to replace this ad-hoc encoding with a clean/maintainable solution that allows:
One approach to this is replacing the ad-hoc encoding with flatbuffers. We would treat the
raftpb.Entry.Data
field as a flatbuffer, with a well-defined / maintainable schema. It would be composed of “header” + data. The header would contain things like:Then all the header checks (like “do we have a RACv2 header?”) would be cheap. As a bonus, we would have no allocations in the entries unmarshaling stack.
As a flip-side, this doesn’t integrate super well with protos, so maybe we would need some wrappers around these flatbuffers to convert to custom types or protos. Though at the scale of just one entries type this doesn’t sound too bad, and is probably better anyway than all the bug-prone parsing we have today. Another flip-side is that this requires a one-time migration that overwrites all raft logs.
However, this logs scan/migration is an opportunity to:
Jira issue: CRDB-42604
The text was updated successfully, but these errors were encountered: