mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: use Equal in example
This commit is contained in:
parent
92bdb1390d
commit
c312d6efad
@ -10,7 +10,6 @@ func applyToStore(ents []Entry) {}
|
||||
func sendMessages(msgs []Message) {}
|
||||
func saveStateToDisk(st State) {}
|
||||
func saveToDisk(ents []Entry) {}
|
||||
func stateChanged(prev, st State) bool { return false }
|
||||
|
||||
func Example_Node() {
|
||||
n := Start(context.Background(), "", 0, 0)
|
||||
@ -26,7 +25,7 @@ func Example_Node() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if stateChanged(prev, st) {
|
||||
if prev.Equal(st) {
|
||||
saveStateToDisk(st)
|
||||
prev = st
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ import math "math"
|
||||
import io "io"
|
||||
import code_google_com_p_gogoprotobuf_proto "code.google.com/p/gogoprotobuf/proto"
|
||||
|
||||
import bytes "bytes"
|
||||
|
||||
// Reference proto, json, and math imports to suppress error if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = &json.SyntaxError{}
|
||||
@ -228,3 +230,40 @@ func encodeVarintState(data []byte, offset int, v uint64) int {
|
||||
data[offset] = uint8(v)
|
||||
return offset + 1
|
||||
}
|
||||
func (this *State) Equal(that interface{}) bool {
|
||||
if that == nil {
|
||||
if this == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
that1, ok := that.(*State)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if that1 == nil {
|
||||
if this == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
} else if this == nil {
|
||||
return false
|
||||
}
|
||||
if this.Term != that1.Term {
|
||||
return false
|
||||
}
|
||||
if this.Vote != that1.Vote {
|
||||
return false
|
||||
}
|
||||
if this.Commit != that1.Commit {
|
||||
return false
|
||||
}
|
||||
if this.LastIndex != that1.LastIndex {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ option (gogoproto.marshaler_all) = true;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = true;
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
option (gogoproto.equal_all) = true;
|
||||
|
||||
message State {
|
||||
required int64 term = 1 [(gogoproto.nullable) = false];
|
||||
|
Loading…
x
Reference in New Issue
Block a user