Skip to content

Commit

Permalink
Merge pull request #14705 from serathius/raftapi
Browse files Browse the repository at this point in the history
raft: Remove dependency on etcd api
  • Loading branch information
serathius authored Nov 8, 2022
2 parents 3e903d0 + 2a1055c commit f482f7b
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 162 deletions.
5 changes: 3 additions & 2 deletions raft/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.5.2
github.com/pkg/errors v0.9.1 // indirect
go.etcd.io/etcd/api/v3 v3.6.0-alpha.0
)

require (
Expand All @@ -27,4 +26,6 @@ replace go.etcd.io/etcd => ./FORBIDDEN_DEPENDENCY

replace go.etcd.io/etcd/v3 => ./FORBIDDEN_DEPENDENCY

replace go.etcd.io/etcd/api/v3 => ../api
replace go.etcd.io/etcd/client/pkg/v3 => ./FORBIDDEN_DEPENDENCY

replace go.etcd.io/etcd/api/v3 => ./FORBIDDEN_DEPENDENCY
136 changes: 66 additions & 70 deletions raft/raftpb/raft.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions raft/raftpb/raft.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ syntax = "proto2";
package raftpb;

import "gogoproto/gogo.proto";
import "etcd/api/versionpb/version.proto";

option (gogoproto.marshaler_all) = true;
option (gogoproto.sizer_all) = true;
Expand All @@ -14,15 +13,13 @@ option (gogoproto.goproto_unrecognized_all) = false;
option (gogoproto.goproto_sizecache_all) = false;

enum EntryType {
option (versionpb.etcd_version_enum) = "3.0";

EntryNormal = 0;
EntryConfChange = 1; // corresponds to pb.ConfChange
EntryConfChangeV2 = 2 [(versionpb.etcd_version_enum_value)="3.4"]; // corresponds to pb.ConfChangeV2
EntryConfChangeV2 = 2; // corresponds to pb.ConfChangeV2
}

message Entry {
option (versionpb.etcd_version_msg) = "3.0";

optional uint64 Term = 2 [(gogoproto.nullable) = false]; // must be 64-bit aligned for atomic operations
optional uint64 Index = 3 [(gogoproto.nullable) = false]; // must be 64-bit aligned for atomic operations
Expand Down Expand Up @@ -94,7 +91,6 @@ message HardState {
// ConfChangeTransition specifies the behavior of a configuration change with
// respect to joint consensus.
enum ConfChangeTransition {
option (versionpb.etcd_version_enum) = "3.4";
// Automatically use the simple protocol if possible, otherwise fall back
// to ConfChangeJointImplicit. Most applications will want to use this.
ConfChangeTransitionAuto = 0;
Expand Down Expand Up @@ -137,8 +133,6 @@ enum ConfChangeType {
}

message ConfChange {
option (versionpb.etcd_version_msg) = "3.0";

optional ConfChangeType type = 2 [(gogoproto.nullable) = false];
optional uint64 node_id = 3 [(gogoproto.nullable) = false, (gogoproto.customname) = "NodeID"];
optional bytes context = 4;
Expand Down Expand Up @@ -189,7 +183,6 @@ message ConfChangeSingle {
//
// [1]: https://github.com/ongardie/dissertation/blob/master/online-trim.pdf
message ConfChangeV2 {
option (versionpb.etcd_version_msg) = "3.4";

optional ConfChangeTransition transition = 1 [(gogoproto.nullable) = false];
repeated ConfChangeSingle changes = 2 [(gogoproto.nullable) = false];
Expand Down
80 changes: 0 additions & 80 deletions scripts/etcd_version_annotations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -454,86 +454,6 @@ mvccpb.KeyValue.lease: ""
mvccpb.KeyValue.mod_revision: ""
mvccpb.KeyValue.value: ""
mvccpb.KeyValue.version: ""
raftpb.ConfChange: "3.0"
raftpb.ConfChange.context: ""
raftpb.ConfChange.id: ""
raftpb.ConfChange.node_id: ""
raftpb.ConfChange.type: ""
raftpb.ConfChangeAddLearnerNode: ""
raftpb.ConfChangeAddNode: ""
raftpb.ConfChangeRemoveNode: ""
raftpb.ConfChangeSingle: ""
raftpb.ConfChangeSingle.node_id: ""
raftpb.ConfChangeSingle.type: ""
raftpb.ConfChangeTransition: "3.4"
raftpb.ConfChangeTransitionAuto: ""
raftpb.ConfChangeTransitionJointExplicit: ""
raftpb.ConfChangeTransitionJointImplicit: ""
raftpb.ConfChangeType: ""
raftpb.ConfChangeUpdateNode: ""
raftpb.ConfChangeV2: "3.4"
raftpb.ConfChangeV2.changes: ""
raftpb.ConfChangeV2.context: ""
raftpb.ConfChangeV2.transition: ""
raftpb.ConfState: ""
raftpb.ConfState.auto_leave: ""
raftpb.ConfState.learners: ""
raftpb.ConfState.learners_next: ""
raftpb.ConfState.voters: ""
raftpb.ConfState.voters_outgoing: ""
raftpb.Entry: "3.0"
raftpb.Entry.Data: ""
raftpb.Entry.Index: ""
raftpb.Entry.Term: ""
raftpb.Entry.Type: ""
raftpb.EntryConfChange: ""
raftpb.EntryConfChangeV2: "3.4"
raftpb.EntryNormal: ""
raftpb.EntryType: "3.0"
raftpb.HardState: ""
raftpb.HardState.commit: ""
raftpb.HardState.term: ""
raftpb.HardState.vote: ""
raftpb.Message: ""
raftpb.Message.commit: ""
raftpb.Message.context: ""
raftpb.Message.entries: ""
raftpb.Message.from: ""
raftpb.Message.index: ""
raftpb.Message.logTerm: ""
raftpb.Message.reject: ""
raftpb.Message.rejectHint: ""
raftpb.Message.snapshot: ""
raftpb.Message.term: ""
raftpb.Message.to: ""
raftpb.Message.type: ""
raftpb.MessageType: ""
raftpb.MsgApp: ""
raftpb.MsgAppResp: ""
raftpb.MsgBeat: ""
raftpb.MsgCheckQuorum: ""
raftpb.MsgHeartbeat: ""
raftpb.MsgHeartbeatResp: ""
raftpb.MsgHup: ""
raftpb.MsgPreVote: ""
raftpb.MsgPreVoteResp: ""
raftpb.MsgProp: ""
raftpb.MsgReadIndex: ""
raftpb.MsgReadIndexResp: ""
raftpb.MsgSnap: ""
raftpb.MsgSnapStatus: ""
raftpb.MsgTimeoutNow: ""
raftpb.MsgTransferLeader: ""
raftpb.MsgUnreachable: ""
raftpb.MsgVote: ""
raftpb.MsgVoteResp: ""
raftpb.Snapshot: ""
raftpb.Snapshot.data: ""
raftpb.Snapshot.metadata: ""
raftpb.SnapshotMetadata: ""
raftpb.SnapshotMetadata.conf_state: ""
raftpb.SnapshotMetadata.index: ""
raftpb.SnapshotMetadata.term: ""
walpb.Record: ""
walpb.Record.crc: ""
walpb.Record.data: ""
Expand Down
3 changes: 3 additions & 0 deletions server/storage/wal/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/coreos/go-semver/semver"
"github.com/golang/protobuf/proto"
"go.etcd.io/etcd/api/v3/version"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/descriptorpb"

Expand Down Expand Up @@ -128,13 +129,15 @@ func visitEntryData(entryType raftpb.EntryType, data []byte, visitor Visitor) er
return nil
}
msg = proto.MessageReflect(&confChange)
return visitor(msg.Descriptor().FullName(), &version.V3_0)
case raftpb.EntryConfChangeV2:
var confChange raftpb.ConfChangeV2
err := pbutil.Unmarshaler(&confChange).Unmarshal(data)
if err != nil {
return nil
}
msg = proto.MessageReflect(&confChange)
return visitor(msg.Descriptor().FullName(), &version.V3_4)
default:
panic("unhandled")
}
Expand Down
2 changes: 1 addition & 1 deletion server/storage/wal/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestEtcdVersionFromEntry(t *testing.T) {
expect: &version.V3_6,
},
{
name: "Using ConfigChange implies v3.4",
name: "Using ConfigChange implies v3.0",
input: raftpb.Entry{
Term: 1,
Index: 2,
Expand Down
2 changes: 1 addition & 1 deletion tools/proto-annotations/cmd/etcd_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

var (
// externalPackages that are not expected to have etcd version annotation.
externalPackages = []string{"io.prometheus.client", "grpc.binarylog.v1", "google.protobuf", "google.rpc", "google.api"}
externalPackages = []string{"io.prometheus.client", "grpc.binarylog.v1", "google.protobuf", "google.rpc", "google.api", "raftpb"}
)

// printEtcdVersion writes etcd_version proto annotation to stdout and returns any errors encountered when reading annotation.
Expand Down

0 comments on commit f482f7b

Please sign in to comment.