Skip to content
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

raft: introduce non-protobuf structs #131511

Conversation

andrewbaptist
Copy link
Collaborator

<what was there before: Previously, ...>
<why it needed to change: This was inadequate because ...>
<what you did about it: To address this, this patch ...>

Copy link

blathers-crl bot commented Sep 27, 2024

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

<what was there before: Previously, ...>
<why it needed to change: This was inadequate because ...>
<what you did about it: To address this, this patch ...>
```

names=$(grep '^type' raft/rafttype/types.go  | awk '{print $2}')

for x in $(grep -l -r raftpb raft kv raftpb); do
	echo $x
        sed -i '' 's/pb "github.com\/cockroachdb\/cockroach\/pkg\/raft\/raftpb"/rt "github\.com\/cockroachdb\/cockroach\/pkg\/raft\/rafttype"/' $x
        sed -i '' 's/"github.com\/cockroachdb\/cockroach\/pkg\/raft\/raftpb"/"github\.com\/cockroachdb\/cockroach\/pkg\/raft\/rafttype"/' $x

        for name in $names Conf Msg; do
                sed -i '' "s/raftpb.$name/rafttype.$name/g" $x
                sed -i '' "s/pb.$name/rt.$name/g" $x
        done
done
```
@andrewbaptist andrewbaptist force-pushed the 2024-09-27-remove-protobuf-in-raft branch from 2a99d6d to c29c32a Compare September 27, 2024 22:16
Copy link

blathers-crl bot commented Sep 27, 2024

Your pull request contains more than 1000 changes. It is strongly encouraged to split big PRs into smaller chunks.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Copy link
Collaborator

@pav-kv pav-kv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks interesting. I don't know if we would want rafttype.Message to be a "union" of all the message types in the end, but seems like some starting point.

It would be nice to explore having a strong type for each message instead of a "union". Then, instead of Step(Message), do something like: StepMsgApp(MsgApp), StepMsgAppResp(MsgAppResp) - these would give the caller some error or introspection specific to this step rather than a generic error. This introspection would be useful to the upper layer, e.g. RACv2 would benefit knowing which range of entries got appended (an append can be partial).

There are some performance concerns here: conversions need to copy all the fields, and allocate in some cases (e.g. when there are Entries in the message). The copies aren't too bad, but the allocations can probably be worked around in some way.

The scope of this change can probably be reduced for the moment. What are we trying to achieve? If we are trying to annotate pb.Entry with in-memory information (trace context, etc), then we could probably do this with a smaller API change, or outside raft.

Comment on lines +89 to +97
result := make([]Entry, len(entries))
for i, entry := range entries {
result[i] = Entry{
Term: entry.Term,
Index: entry.Index,
Type: EntryType(entry.Type),
Data: entry.Data,
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes an extra allocation on every message containing entries (MsgProp, MsgApp, etc)? Also, the convertSnapshot.

We would probably want to make these messages iterable or zero-copy somehow, so that they could be stepped into raft without an extra allocation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants