From 4fbb56c1b57fc2a65644fdfcf47e22ce9e06cc41 Mon Sep 17 00:00:00 2001 From: lauranooooo Date: Tue, 4 Jun 2024 16:02:25 +0100 Subject: [PATCH] tidying --- projects/raft-otel/raft/README.md | 2 +- projects/raft-otel/raft/client.go | 60 -- projects/raft-otel/raft/main.go | 113 --- projects/raft-otel/raft/raft.pb.go | 871 ------------------------ projects/raft-otel/raft/raft.proto | 70 -- projects/raft-otel/raft/raft_grpc.pb.go | 263 ------- projects/raft-otel/raft/testharness.go | 2 - 7 files changed, 1 insertion(+), 1380 deletions(-) delete mode 100644 projects/raft-otel/raft/client.go delete mode 100644 projects/raft-otel/raft/main.go delete mode 100644 projects/raft-otel/raft/raft.pb.go delete mode 100644 projects/raft-otel/raft/raft.proto delete mode 100644 projects/raft-otel/raft/raft_grpc.pb.go diff --git a/projects/raft-otel/raft/README.md b/projects/raft-otel/raft/README.md index 4a378daf..431648c5 100644 --- a/projects/raft-otel/raft/README.md +++ b/projects/raft-otel/raft/README.md @@ -1,4 +1,4 @@ -# Sample Raft implementation - Incomplete Version +# Sample Raft implementation This is based on Eli Bendersky's [https://eli.thegreenplace.net] RAFT demo code. diff --git a/projects/raft-otel/raft/client.go b/projects/raft-otel/raft/client.go deleted file mode 100644 index 08a5d57b..00000000 --- a/projects/raft-otel/raft/client.go +++ /dev/null @@ -1,60 +0,0 @@ -package main - -import ( - "context" - "flag" - "fmt" - "log" - "net" - "os" - "raft/raft_proto" - "time" - - "google.golang.org/grpc" - "google.golang.org/grpc/credentials/insecure" -) - -const port = 7600 - -func main() { - addr := flag.String("dns", "raft", "dns address for raft cluster") - - if addr == nil || *addr == "" { - fmt.Printf("Must supply dns address of cluster\n") - os.Exit(1) - } - - time.Sleep(time.Second * 5) // wait for raft servers to come up - - ips, err := net.LookupIP(*addr) - if err != nil { - fmt.Printf("Could not get IPs: %v\n", err) - os.Exit(1) - } - - clients := make([]raft_proto.RaftKVServiceClient, 0) - - for _, ip := range ips { - fmt.Printf("Connecting to %s\n", ip.String()) - conn, err := grpc.Dial(fmt.Sprintf("%s:%d", ip.String(), port), grpc.WithTransportCredentials(insecure.NewCredentials())) - if err != nil { - log.Fatalf("%v", err) - } - client := raft_proto.NewRaftKVServiceClient(conn) - clients = append(clients, client) - } - - for { - for _, c := range clients { - n := time.Now().Second() - res, err := c.Set(context.TODO(), &raft_proto.SetRequest{Keyname: "cursec", Value: fmt.Sprintf("%d", n)}) - fmt.Printf("Called set cursec %d, got %v, %v\n", n, res, err) - - time.Sleep(1 * time.Second) // allow consensus to happen - - getres, err := c.Get(context.TODO(), &raft_proto.GetRequest{Keyname: "cursec"}) - fmt.Printf("Called get cursec, got %v, %v\n", getres, err) - } - time.Sleep(5 * time.Second) - } -} diff --git a/projects/raft-otel/raft/main.go b/projects/raft-otel/raft/main.go deleted file mode 100644 index 45dfe47f..00000000 --- a/projects/raft-otel/raft/main.go +++ /dev/null @@ -1,113 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "net" - "os" - "os/signal" - "raft" - "strings" - "syscall" - "time" -) - -const port = 7600 - -func main() { - addr := flag.String("dns", "raft", "dns address for raft cluster") - if_addr := flag.String("if", "eth0", "use IPV4 address of this interface") // eth0 works on docker, may vary for other platforms - - if addr == nil || *addr == "" { - fmt.Printf("Must supply dns address of cluster\n") - os.Exit(1) - } - - id := getOwnAddr(*if_addr) - fmt.Printf("My address/node ID is %s\n", id) - - ready := make(chan interface{}) - storage := raft.NewMapStorage() - commitChan := make(chan raft.CommitEntry) - server := raft.NewServer(id, id, storage, ready, commitChan, port) - server.Serve(raft.NewKV()) - - ips, err := net.LookupIP(*addr) - if err != nil { - fmt.Printf("Could not get IPs: %v\n", err) - os.Exit(1) - } - - // Connect to all peers with appropriate waits - // TODO: we only do this once, on startup - we really should periodically check to see if the DNS listing for peers has changed - for _, ip := range ips { - // if not own IP - if !ownAddr(ip, id) { - peerAddr := fmt.Sprintf("%s:%d", ip.String(), port) - - connected := false - for rt := 0; rt <= 3 && !connected; rt++ { - fmt.Printf("Connecting to peer %s\n", peerAddr) - err = server.ConnectToPeer(peerAddr, peerAddr) - if err == nil { - connected = true - } else { // probably just not started up yet, retry - fmt.Printf("Error connecting to peer: %+v", err) - time.Sleep(time.Duration(rt+1) * time.Second) - } - } - if err != nil { - fmt.Printf("Exhausted retries connecting to peer %s", peerAddr) - os.Exit(1) - } - } - } - - close(ready) // start raft server, peers are connected - - gracefulShutdown := make(chan os.Signal, 1) - signal.Notify(gracefulShutdown, syscall.SIGINT, syscall.SIGTERM) - <-gracefulShutdown - server.DisconnectAll() - server.Shutdown() -} - -func getOwnAddr(intf string) string { - ifs, err := net.Interfaces() - if err != nil { - fmt.Printf("Could not get intf: %v\n", err) - os.Exit(1) - } - - for _, cif := range ifs { - if cif.Name == intf { - ads, _ := cif.Addrs() - for _, addr := range ads { - if isIPV4(addr.String()) { - ip := getIP(addr.String()) - return ip.String() - } - - } - } - } - - fmt.Printf("Could not find intf: %s\n", intf) - os.Exit(1) - return "" -} - -func isIPV4(addr string) bool { - parts := strings.Split(addr, "::") - return len(parts) == 1 -} - -func getIP(addr string) net.IP { - parts := strings.Split(addr, "/") - return net.ParseIP(parts[0]) -} - -func ownAddr(ip net.IP, myAddr string) bool { - res := ip.String() == myAddr - return res -} diff --git a/projects/raft-otel/raft/raft.pb.go b/projects/raft-otel/raft/raft.pb.go deleted file mode 100644 index 38eec3b6..00000000 --- a/projects/raft-otel/raft/raft.pb.go +++ /dev/null @@ -1,871 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.31.0 -// protoc v4.24.4 -// source: raft.proto - -package raft_proto - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type SetRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Keyname string `protobuf:"bytes,1,opt,name=keyname,proto3" json:"keyname,omitempty"` - Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` -} - -func (x *SetRequest) Reset() { - *x = SetRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_raft_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *SetRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*SetRequest) ProtoMessage() {} - -func (x *SetRequest) ProtoReflect() protoreflect.Message { - mi := &file_raft_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use SetRequest.ProtoReflect.Descriptor instead. -func (*SetRequest) Descriptor() ([]byte, []int) { - return file_raft_proto_rawDescGZIP(), []int{0} -} - -func (x *SetRequest) GetKeyname() string { - if x != nil { - return x.Keyname - } - return "" -} - -func (x *SetRequest) GetValue() string { - if x != nil { - return x.Value - } - return "" -} - -type SetResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields -} - -func (x *SetResponse) Reset() { - *x = SetResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_raft_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *SetResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*SetResponse) ProtoMessage() {} - -func (x *SetResponse) ProtoReflect() protoreflect.Message { - mi := &file_raft_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use SetResponse.ProtoReflect.Descriptor instead. -func (*SetResponse) Descriptor() ([]byte, []int) { - return file_raft_proto_rawDescGZIP(), []int{1} -} - -type GetRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Keyname string `protobuf:"bytes,1,opt,name=keyname,proto3" json:"keyname,omitempty"` -} - -func (x *GetRequest) Reset() { - *x = GetRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_raft_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *GetRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetRequest) ProtoMessage() {} - -func (x *GetRequest) ProtoReflect() protoreflect.Message { - mi := &file_raft_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetRequest.ProtoReflect.Descriptor instead. -func (*GetRequest) Descriptor() ([]byte, []int) { - return file_raft_proto_rawDescGZIP(), []int{2} -} - -func (x *GetRequest) GetKeyname() string { - if x != nil { - return x.Keyname - } - return "" -} - -type GetResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` -} - -func (x *GetResponse) Reset() { - *x = GetResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_raft_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *GetResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetResponse) ProtoMessage() {} - -func (x *GetResponse) ProtoReflect() protoreflect.Message { - mi := &file_raft_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetResponse.ProtoReflect.Descriptor instead. -func (*GetResponse) Descriptor() ([]byte, []int) { - return file_raft_proto_rawDescGZIP(), []int{3} -} - -func (x *GetResponse) GetValue() string { - if x != nil { - return x.Value - } - return "" -} - -type RequestVoteRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Term int64 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"` - CandidateId string `protobuf:"bytes,2,opt,name=candidateId,proto3" json:"candidateId,omitempty"` - LastLogIndex int64 `protobuf:"varint,3,opt,name=lastLogIndex,proto3" json:"lastLogIndex,omitempty"` - LastLogTerm int64 `protobuf:"varint,4,opt,name=lastLogTerm,proto3" json:"lastLogTerm,omitempty"` -} - -func (x *RequestVoteRequest) Reset() { - *x = RequestVoteRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_raft_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *RequestVoteRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*RequestVoteRequest) ProtoMessage() {} - -func (x *RequestVoteRequest) ProtoReflect() protoreflect.Message { - mi := &file_raft_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use RequestVoteRequest.ProtoReflect.Descriptor instead. -func (*RequestVoteRequest) Descriptor() ([]byte, []int) { - return file_raft_proto_rawDescGZIP(), []int{4} -} - -func (x *RequestVoteRequest) GetTerm() int64 { - if x != nil { - return x.Term - } - return 0 -} - -func (x *RequestVoteRequest) GetCandidateId() string { - if x != nil { - return x.CandidateId - } - return "" -} - -func (x *RequestVoteRequest) GetLastLogIndex() int64 { - if x != nil { - return x.LastLogIndex - } - return 0 -} - -func (x *RequestVoteRequest) GetLastLogTerm() int64 { - if x != nil { - return x.LastLogTerm - } - return 0 -} - -type RequestVoteResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Term int64 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"` - VoteGranted bool `protobuf:"varint,2,opt,name=voteGranted,proto3" json:"voteGranted,omitempty"` -} - -func (x *RequestVoteResponse) Reset() { - *x = RequestVoteResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_raft_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *RequestVoteResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*RequestVoteResponse) ProtoMessage() {} - -func (x *RequestVoteResponse) ProtoReflect() protoreflect.Message { - mi := &file_raft_proto_msgTypes[5] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use RequestVoteResponse.ProtoReflect.Descriptor instead. -func (*RequestVoteResponse) Descriptor() ([]byte, []int) { - return file_raft_proto_rawDescGZIP(), []int{5} -} - -func (x *RequestVoteResponse) GetTerm() int64 { - if x != nil { - return x.Term - } - return 0 -} - -func (x *RequestVoteResponse) GetVoteGranted() bool { - if x != nil { - return x.VoteGranted - } - return false -} - -type AppendEntriesRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Term int64 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"` - Leader string `protobuf:"bytes,2,opt,name=leader,proto3" json:"leader,omitempty"` - PrevLogIndex int64 `protobuf:"varint,3,opt,name=prevLogIndex,proto3" json:"prevLogIndex,omitempty"` - PrevLogTerm int64 `protobuf:"varint,4,opt,name=prevLogTerm,proto3" json:"prevLogTerm,omitempty"` - Entries []*LogEntry `protobuf:"bytes,5,rep,name=entries,proto3" json:"entries,omitempty"` - LeaderCommit int64 `protobuf:"varint,6,opt,name=leaderCommit,proto3" json:"leaderCommit,omitempty"` -} - -func (x *AppendEntriesRequest) Reset() { - *x = AppendEntriesRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_raft_proto_msgTypes[6] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *AppendEntriesRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*AppendEntriesRequest) ProtoMessage() {} - -func (x *AppendEntriesRequest) ProtoReflect() protoreflect.Message { - mi := &file_raft_proto_msgTypes[6] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use AppendEntriesRequest.ProtoReflect.Descriptor instead. -func (*AppendEntriesRequest) Descriptor() ([]byte, []int) { - return file_raft_proto_rawDescGZIP(), []int{6} -} - -func (x *AppendEntriesRequest) GetTerm() int64 { - if x != nil { - return x.Term - } - return 0 -} - -func (x *AppendEntriesRequest) GetLeader() string { - if x != nil { - return x.Leader - } - return "" -} - -func (x *AppendEntriesRequest) GetPrevLogIndex() int64 { - if x != nil { - return x.PrevLogIndex - } - return 0 -} - -func (x *AppendEntriesRequest) GetPrevLogTerm() int64 { - if x != nil { - return x.PrevLogTerm - } - return 0 -} - -func (x *AppendEntriesRequest) GetEntries() []*LogEntry { - if x != nil { - return x.Entries - } - return nil -} - -func (x *AppendEntriesRequest) GetLeaderCommit() int64 { - if x != nil { - return x.LeaderCommit - } - return 0 -} - -type LogEntry struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Term int64 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"` - Command *Command `protobuf:"bytes,2,opt,name=command,proto3" json:"command,omitempty"` -} - -func (x *LogEntry) Reset() { - *x = LogEntry{} - if protoimpl.UnsafeEnabled { - mi := &file_raft_proto_msgTypes[7] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *LogEntry) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*LogEntry) ProtoMessage() {} - -func (x *LogEntry) ProtoReflect() protoreflect.Message { - mi := &file_raft_proto_msgTypes[7] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use LogEntry.ProtoReflect.Descriptor instead. -func (*LogEntry) Descriptor() ([]byte, []int) { - return file_raft_proto_rawDescGZIP(), []int{7} -} - -func (x *LogEntry) GetTerm() int64 { - if x != nil { - return x.Term - } - return 0 -} - -func (x *LogEntry) GetCommand() *Command { - if x != nil { - return x.Command - } - return nil -} - -type Command struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Command string `protobuf:"bytes,1,opt,name=Command,proto3" json:"Command,omitempty"` - Args []string `protobuf:"bytes,2,rep,name=Args,proto3" json:"Args,omitempty"` -} - -func (x *Command) Reset() { - *x = Command{} - if protoimpl.UnsafeEnabled { - mi := &file_raft_proto_msgTypes[8] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Command) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Command) ProtoMessage() {} - -func (x *Command) ProtoReflect() protoreflect.Message { - mi := &file_raft_proto_msgTypes[8] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Command.ProtoReflect.Descriptor instead. -func (*Command) Descriptor() ([]byte, []int) { - return file_raft_proto_rawDescGZIP(), []int{8} -} - -func (x *Command) GetCommand() string { - if x != nil { - return x.Command - } - return "" -} - -func (x *Command) GetArgs() []string { - if x != nil { - return x.Args - } - return nil -} - -type AppendEntriesResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Term int64 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"` - Success bool `protobuf:"varint,2,opt,name=success,proto3" json:"success,omitempty"` - ConflictIndex int64 `protobuf:"varint,3,opt,name=conflictIndex,proto3" json:"conflictIndex,omitempty"` - ConflictTerm int64 `protobuf:"varint,4,opt,name=conflictTerm,proto3" json:"conflictTerm,omitempty"` -} - -func (x *AppendEntriesResponse) Reset() { - *x = AppendEntriesResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_raft_proto_msgTypes[9] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *AppendEntriesResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*AppendEntriesResponse) ProtoMessage() {} - -func (x *AppendEntriesResponse) ProtoReflect() protoreflect.Message { - mi := &file_raft_proto_msgTypes[9] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use AppendEntriesResponse.ProtoReflect.Descriptor instead. -func (*AppendEntriesResponse) Descriptor() ([]byte, []int) { - return file_raft_proto_rawDescGZIP(), []int{9} -} - -func (x *AppendEntriesResponse) GetTerm() int64 { - if x != nil { - return x.Term - } - return 0 -} - -func (x *AppendEntriesResponse) GetSuccess() bool { - if x != nil { - return x.Success - } - return false -} - -func (x *AppendEntriesResponse) GetConflictIndex() int64 { - if x != nil { - return x.ConflictIndex - } - return 0 -} - -func (x *AppendEntriesResponse) GetConflictTerm() int64 { - if x != nil { - return x.ConflictTerm - } - return 0 -} - -var File_raft_proto protoreflect.FileDescriptor - -var file_raft_proto_rawDesc = []byte{ - 0x0a, 0x0a, 0x72, 0x61, 0x66, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x72, 0x61, - 0x66, 0x74, 0x22, 0x3c, 0x0a, 0x0a, 0x53, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x18, 0x0a, 0x07, 0x6b, 0x65, 0x79, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x07, 0x6b, 0x65, 0x79, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x22, 0x0d, 0x0a, 0x0b, 0x53, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x26, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, - 0x07, 0x6b, 0x65, 0x79, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, - 0x6b, 0x65, 0x79, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x23, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x90, 0x01, 0x0a, - 0x12, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x56, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x72, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x03, 0x52, 0x04, 0x74, 0x65, 0x72, 0x6d, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x61, 0x6e, 0x64, 0x69, - 0x64, 0x61, 0x74, 0x65, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, 0x61, - 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, 0x49, 0x64, 0x12, 0x22, 0x0a, 0x0c, 0x6c, 0x61, 0x73, - 0x74, 0x4c, 0x6f, 0x67, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, - 0x0c, 0x6c, 0x61, 0x73, 0x74, 0x4c, 0x6f, 0x67, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x12, 0x20, 0x0a, - 0x0b, 0x6c, 0x61, 0x73, 0x74, 0x4c, 0x6f, 0x67, 0x54, 0x65, 0x72, 0x6d, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x03, 0x52, 0x0b, 0x6c, 0x61, 0x73, 0x74, 0x4c, 0x6f, 0x67, 0x54, 0x65, 0x72, 0x6d, 0x22, - 0x4b, 0x0a, 0x13, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x56, 0x6f, 0x74, 0x65, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x72, 0x6d, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x65, 0x72, 0x6d, 0x12, 0x20, 0x0a, 0x0b, 0x76, 0x6f, - 0x74, 0x65, 0x47, 0x72, 0x61, 0x6e, 0x74, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, - 0x0b, 0x76, 0x6f, 0x74, 0x65, 0x47, 0x72, 0x61, 0x6e, 0x74, 0x65, 0x64, 0x22, 0xd6, 0x01, 0x0a, - 0x14, 0x41, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x45, 0x6e, 0x74, 0x72, 0x69, 0x65, 0x73, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x72, 0x6d, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x65, 0x72, 0x6d, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x65, 0x61, - 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6c, 0x65, 0x61, 0x64, 0x65, - 0x72, 0x12, 0x22, 0x0a, 0x0c, 0x70, 0x72, 0x65, 0x76, 0x4c, 0x6f, 0x67, 0x49, 0x6e, 0x64, 0x65, - 0x78, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x70, 0x72, 0x65, 0x76, 0x4c, 0x6f, 0x67, - 0x49, 0x6e, 0x64, 0x65, 0x78, 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x72, 0x65, 0x76, 0x4c, 0x6f, 0x67, - 0x54, 0x65, 0x72, 0x6d, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x70, 0x72, 0x65, 0x76, - 0x4c, 0x6f, 0x67, 0x54, 0x65, 0x72, 0x6d, 0x12, 0x28, 0x0a, 0x07, 0x65, 0x6e, 0x74, 0x72, 0x69, - 0x65, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x72, 0x61, 0x66, 0x74, 0x2e, - 0x4c, 0x6f, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x07, 0x65, 0x6e, 0x74, 0x72, 0x69, 0x65, - 0x73, 0x12, 0x22, 0x0a, 0x0c, 0x6c, 0x65, 0x61, 0x64, 0x65, 0x72, 0x43, 0x6f, 0x6d, 0x6d, 0x69, - 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x6c, 0x65, 0x61, 0x64, 0x65, 0x72, 0x43, - 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x22, 0x47, 0x0a, 0x08, 0x4c, 0x6f, 0x67, 0x45, 0x6e, 0x74, 0x72, - 0x79, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x72, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, - 0x04, 0x74, 0x65, 0x72, 0x6d, 0x12, 0x27, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x72, 0x61, 0x66, 0x74, 0x2e, 0x43, 0x6f, - 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x22, 0x37, - 0x0a, 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x43, 0x6f, 0x6d, - 0x6d, 0x61, 0x6e, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x43, 0x6f, 0x6d, 0x6d, - 0x61, 0x6e, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x41, 0x72, 0x67, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, - 0x09, 0x52, 0x04, 0x41, 0x72, 0x67, 0x73, 0x22, 0x8f, 0x01, 0x0a, 0x15, 0x41, 0x70, 0x70, 0x65, - 0x6e, 0x64, 0x45, 0x6e, 0x74, 0x72, 0x69, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x72, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, - 0x04, 0x74, 0x65, 0x72, 0x6d, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x12, - 0x24, 0x0a, 0x0d, 0x63, 0x6f, 0x6e, 0x66, 0x6c, 0x69, 0x63, 0x74, 0x49, 0x6e, 0x64, 0x65, 0x78, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0d, 0x63, 0x6f, 0x6e, 0x66, 0x6c, 0x69, 0x63, 0x74, - 0x49, 0x6e, 0x64, 0x65, 0x78, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x66, 0x6c, 0x69, 0x63, - 0x74, 0x54, 0x65, 0x72, 0x6d, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x63, 0x6f, 0x6e, - 0x66, 0x6c, 0x69, 0x63, 0x74, 0x54, 0x65, 0x72, 0x6d, 0x32, 0x6b, 0x0a, 0x0d, 0x52, 0x61, 0x66, - 0x74, 0x4b, 0x56, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x2c, 0x0a, 0x03, 0x53, 0x65, - 0x74, 0x12, 0x10, 0x2e, 0x72, 0x61, 0x66, 0x74, 0x2e, 0x53, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x72, 0x61, 0x66, 0x74, 0x2e, 0x53, 0x65, 0x74, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x2c, 0x0a, 0x03, 0x47, 0x65, 0x74, 0x12, - 0x10, 0x2e, 0x72, 0x61, 0x66, 0x74, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x11, 0x2e, 0x72, 0x61, 0x66, 0x74, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x32, 0x9f, 0x01, 0x0a, 0x0b, 0x52, 0x61, 0x66, 0x74, 0x53, - 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x44, 0x0a, 0x0b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x56, 0x6f, 0x74, 0x65, 0x12, 0x18, 0x2e, 0x72, 0x61, 0x66, 0x74, 0x2e, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x56, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x19, 0x2e, 0x72, 0x61, 0x66, 0x74, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x56, 0x6f, - 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4a, 0x0a, 0x0d, - 0x41, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x45, 0x6e, 0x74, 0x72, 0x69, 0x65, 0x73, 0x12, 0x1a, 0x2e, - 0x72, 0x61, 0x66, 0x74, 0x2e, 0x41, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x45, 0x6e, 0x74, 0x72, 0x69, - 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x72, 0x61, 0x66, 0x74, - 0x2e, 0x41, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x45, 0x6e, 0x74, 0x72, 0x69, 0x65, 0x73, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0d, 0x5a, 0x0b, 0x2f, 0x72, 0x61, 0x66, - 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_raft_proto_rawDescOnce sync.Once - file_raft_proto_rawDescData = file_raft_proto_rawDesc -) - -func file_raft_proto_rawDescGZIP() []byte { - file_raft_proto_rawDescOnce.Do(func() { - file_raft_proto_rawDescData = protoimpl.X.CompressGZIP(file_raft_proto_rawDescData) - }) - return file_raft_proto_rawDescData -} - -var file_raft_proto_msgTypes = make([]protoimpl.MessageInfo, 10) -var file_raft_proto_goTypes = []interface{}{ - (*SetRequest)(nil), // 0: raft.SetRequest - (*SetResponse)(nil), // 1: raft.SetResponse - (*GetRequest)(nil), // 2: raft.GetRequest - (*GetResponse)(nil), // 3: raft.GetResponse - (*RequestVoteRequest)(nil), // 4: raft.RequestVoteRequest - (*RequestVoteResponse)(nil), // 5: raft.RequestVoteResponse - (*AppendEntriesRequest)(nil), // 6: raft.AppendEntriesRequest - (*LogEntry)(nil), // 7: raft.LogEntry - (*Command)(nil), // 8: raft.Command - (*AppendEntriesResponse)(nil), // 9: raft.AppendEntriesResponse -} -var file_raft_proto_depIdxs = []int32{ - 7, // 0: raft.AppendEntriesRequest.entries:type_name -> raft.LogEntry - 8, // 1: raft.LogEntry.command:type_name -> raft.Command - 0, // 2: raft.RaftKVService.Set:input_type -> raft.SetRequest - 2, // 3: raft.RaftKVService.Get:input_type -> raft.GetRequest - 4, // 4: raft.RaftService.RequestVote:input_type -> raft.RequestVoteRequest - 6, // 5: raft.RaftService.AppendEntries:input_type -> raft.AppendEntriesRequest - 1, // 6: raft.RaftKVService.Set:output_type -> raft.SetResponse - 3, // 7: raft.RaftKVService.Get:output_type -> raft.GetResponse - 5, // 8: raft.RaftService.RequestVote:output_type -> raft.RequestVoteResponse - 9, // 9: raft.RaftService.AppendEntries:output_type -> raft.AppendEntriesResponse - 6, // [6:10] is the sub-list for method output_type - 2, // [2:6] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name -} - -func init() { file_raft_proto_init() } -func file_raft_proto_init() { - if File_raft_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_raft_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*SetRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_raft_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*SetResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_raft_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_raft_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_raft_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*RequestVoteRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_raft_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*RequestVoteResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_raft_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AppendEntriesRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_raft_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*LogEntry); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_raft_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Command); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_raft_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AppendEntriesResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_raft_proto_rawDesc, - NumEnums: 0, - NumMessages: 10, - NumExtensions: 0, - NumServices: 2, - }, - GoTypes: file_raft_proto_goTypes, - DependencyIndexes: file_raft_proto_depIdxs, - MessageInfos: file_raft_proto_msgTypes, - }.Build() - File_raft_proto = out.File - file_raft_proto_rawDesc = nil - file_raft_proto_goTypes = nil - file_raft_proto_depIdxs = nil -} diff --git a/projects/raft-otel/raft/raft.proto b/projects/raft-otel/raft/raft.proto deleted file mode 100644 index c9a89abb..00000000 --- a/projects/raft-otel/raft/raft.proto +++ /dev/null @@ -1,70 +0,0 @@ -syntax = "proto3"; -package raft; -option go_package = "/raft_proto"; - -service RaftKVService { - rpc Set(SetRequest) returns (SetResponse) {} - rpc Get(GetRequest) returns (GetResponse) {} -} - -message SetRequest { - string keyname = 1; - string value = 2; -} - -message SetResponse { -} - -message GetRequest { - string keyname = 1; -} - -message GetResponse { - string value = 1; -} - -service RaftService { - rpc RequestVote(RequestVoteRequest) returns (RequestVoteResponse) {} - rpc AppendEntries(AppendEntriesRequest) returns (AppendEntriesResponse) {} -} - -message RequestVoteRequest { - int64 term = 1; - string candidateId = 2; - int64 lastLogIndex = 3; - int64 lastLogTerm = 4; -} - -message RequestVoteResponse { - int64 term = 1; - bool voteGranted = 2; -} - -message AppendEntriesRequest { - int64 term = 1; - string leader = 2; - int64 prevLogIndex = 3; - int64 prevLogTerm = 4; - repeated LogEntry entries = 5; - int64 leaderCommit = 6; -} - - -message LogEntry { - int64 term = 1; - Command command = 2; -} - -message Command { - string Command = 1; - repeated string Args = 2; -} - - -message AppendEntriesResponse { - int64 term = 1; - bool success = 2; - int64 conflictIndex = 3; - int64 conflictTerm = 4; -} - diff --git a/projects/raft-otel/raft/raft_grpc.pb.go b/projects/raft-otel/raft/raft_grpc.pb.go deleted file mode 100644 index d4299e88..00000000 --- a/projects/raft-otel/raft/raft_grpc.pb.go +++ /dev/null @@ -1,263 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. -// versions: -// - protoc-gen-go-grpc v1.2.0 -// - protoc v4.24.4 -// source: raft.proto - -package raft_proto - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 - -// RaftKVServiceClient is the client API for RaftKVService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type RaftKVServiceClient interface { - Set(ctx context.Context, in *SetRequest, opts ...grpc.CallOption) (*SetResponse, error) - Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) -} - -type raftKVServiceClient struct { - cc grpc.ClientConnInterface -} - -func NewRaftKVServiceClient(cc grpc.ClientConnInterface) RaftKVServiceClient { - return &raftKVServiceClient{cc} -} - -func (c *raftKVServiceClient) Set(ctx context.Context, in *SetRequest, opts ...grpc.CallOption) (*SetResponse, error) { - out := new(SetResponse) - err := c.cc.Invoke(ctx, "/raft.RaftKVService/Set", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *raftKVServiceClient) Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) { - out := new(GetResponse) - err := c.cc.Invoke(ctx, "/raft.RaftKVService/Get", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// RaftKVServiceServer is the server API for RaftKVService service. -// All implementations must embed UnimplementedRaftKVServiceServer -// for forward compatibility -type RaftKVServiceServer interface { - Set(context.Context, *SetRequest) (*SetResponse, error) - Get(context.Context, *GetRequest) (*GetResponse, error) - mustEmbedUnimplementedRaftKVServiceServer() -} - -// UnimplementedRaftKVServiceServer must be embedded to have forward compatible implementations. -type UnimplementedRaftKVServiceServer struct { -} - -func (UnimplementedRaftKVServiceServer) Set(context.Context, *SetRequest) (*SetResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Set not implemented") -} -func (UnimplementedRaftKVServiceServer) Get(context.Context, *GetRequest) (*GetResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Get not implemented") -} -func (UnimplementedRaftKVServiceServer) mustEmbedUnimplementedRaftKVServiceServer() {} - -// UnsafeRaftKVServiceServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to RaftKVServiceServer will -// result in compilation errors. -type UnsafeRaftKVServiceServer interface { - mustEmbedUnimplementedRaftKVServiceServer() -} - -func RegisterRaftKVServiceServer(s grpc.ServiceRegistrar, srv RaftKVServiceServer) { - s.RegisterService(&RaftKVService_ServiceDesc, srv) -} - -func _RaftKVService_Set_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(SetRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RaftKVServiceServer).Set(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/raft.RaftKVService/Set", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RaftKVServiceServer).Set(ctx, req.(*SetRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _RaftKVService_Get_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GetRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RaftKVServiceServer).Get(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/raft.RaftKVService/Get", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RaftKVServiceServer).Get(ctx, req.(*GetRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// RaftKVService_ServiceDesc is the grpc.ServiceDesc for RaftKVService service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var RaftKVService_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "raft.RaftKVService", - HandlerType: (*RaftKVServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Set", - Handler: _RaftKVService_Set_Handler, - }, - { - MethodName: "Get", - Handler: _RaftKVService_Get_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "raft.proto", -} - -// RaftServiceClient is the client API for RaftService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type RaftServiceClient interface { - RequestVote(ctx context.Context, in *RequestVoteRequest, opts ...grpc.CallOption) (*RequestVoteResponse, error) - AppendEntries(ctx context.Context, in *AppendEntriesRequest, opts ...grpc.CallOption) (*AppendEntriesResponse, error) -} - -type raftServiceClient struct { - cc grpc.ClientConnInterface -} - -func NewRaftServiceClient(cc grpc.ClientConnInterface) RaftServiceClient { - return &raftServiceClient{cc} -} - -func (c *raftServiceClient) RequestVote(ctx context.Context, in *RequestVoteRequest, opts ...grpc.CallOption) (*RequestVoteResponse, error) { - out := new(RequestVoteResponse) - err := c.cc.Invoke(ctx, "/raft.RaftService/RequestVote", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *raftServiceClient) AppendEntries(ctx context.Context, in *AppendEntriesRequest, opts ...grpc.CallOption) (*AppendEntriesResponse, error) { - out := new(AppendEntriesResponse) - err := c.cc.Invoke(ctx, "/raft.RaftService/AppendEntries", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// RaftServiceServer is the server API for RaftService service. -// All implementations must embed UnimplementedRaftServiceServer -// for forward compatibility -type RaftServiceServer interface { - RequestVote(context.Context, *RequestVoteRequest) (*RequestVoteResponse, error) - AppendEntries(context.Context, *AppendEntriesRequest) (*AppendEntriesResponse, error) - mustEmbedUnimplementedRaftServiceServer() -} - -// UnimplementedRaftServiceServer must be embedded to have forward compatible implementations. -type UnimplementedRaftServiceServer struct { -} - -func (UnimplementedRaftServiceServer) RequestVote(context.Context, *RequestVoteRequest) (*RequestVoteResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method RequestVote not implemented") -} -func (UnimplementedRaftServiceServer) AppendEntries(context.Context, *AppendEntriesRequest) (*AppendEntriesResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method AppendEntries not implemented") -} -func (UnimplementedRaftServiceServer) mustEmbedUnimplementedRaftServiceServer() {} - -// UnsafeRaftServiceServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to RaftServiceServer will -// result in compilation errors. -type UnsafeRaftServiceServer interface { - mustEmbedUnimplementedRaftServiceServer() -} - -func RegisterRaftServiceServer(s grpc.ServiceRegistrar, srv RaftServiceServer) { - s.RegisterService(&RaftService_ServiceDesc, srv) -} - -func _RaftService_RequestVote_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(RequestVoteRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RaftServiceServer).RequestVote(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/raft.RaftService/RequestVote", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RaftServiceServer).RequestVote(ctx, req.(*RequestVoteRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _RaftService_AppendEntries_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AppendEntriesRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RaftServiceServer).AppendEntries(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/raft.RaftService/AppendEntries", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RaftServiceServer).AppendEntries(ctx, req.(*AppendEntriesRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// RaftService_ServiceDesc is the grpc.ServiceDesc for RaftService service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var RaftService_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "raft.RaftService", - HandlerType: (*RaftServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "RequestVote", - Handler: _RaftService_RequestVote_Handler, - }, - { - MethodName: "AppendEntries", - Handler: _RaftService_AppendEntries_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "raft.proto", -} diff --git a/projects/raft-otel/raft/testharness.go b/projects/raft-otel/raft/testharness.go index 0622833b..77e97c23 100644 --- a/projects/raft-otel/raft/testharness.go +++ b/projects/raft-otel/raft/testharness.go @@ -253,8 +253,6 @@ func (h *Harness) CheckCommitted(cmdNum int) (nc int, index int) { h.mu.Lock() defer h.mu.Unlock() - h.printCommits() - // Find the length of the commits slice for connected servers. commitsLen := -1 for i := 0; i < h.n; i++ {