From 198ccb8b7b1d083af054f22ace6a7e992fc34db4 Mon Sep 17 00:00:00 2001 From: Jared Hulbert Date: Fri, 8 Jul 2016 11:13:53 -0700 Subject: [PATCH] raftpb: atomic access alignment The Entry struct has misaligned fields that are accessed atomically. The misalignment is caused by the EntryType enum which the Protocol Buffers spec forces to be a 32bit int. Moving the order of the fields without renumbering them in the .proto file seems to align the go structure without changing the wire format. --- raft/raftpb/raft.pb.go | 2 +- raft/raftpb/raft.proto | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/raft/raftpb/raft.pb.go b/raft/raftpb/raft.pb.go index 6199ee816..cd997daec 100644 --- a/raft/raftpb/raft.pb.go +++ b/raft/raftpb/raft.pb.go @@ -183,9 +183,9 @@ func (x *ConfChangeType) UnmarshalJSON(data []byte) error { func (ConfChangeType) EnumDescriptor() ([]byte, []int) { return fileDescriptorRaft, []int{2} } type Entry struct { - Type EntryType `protobuf:"varint,1,opt,name=Type,json=type,enum=raftpb.EntryType" json:"Type"` Term uint64 `protobuf:"varint,2,opt,name=Term,json=term" json:"Term"` Index uint64 `protobuf:"varint,3,opt,name=Index,json=index" json:"Index"` + Type EntryType `protobuf:"varint,1,opt,name=Type,json=type,enum=raftpb.EntryType" json:"Type"` Data []byte `protobuf:"bytes,4,opt,name=Data,json=data" json:"Data,omitempty"` XXX_unrecognized []byte `json:"-"` } diff --git a/raft/raftpb/raft.proto b/raft/raftpb/raft.proto index 42f10d269..8cd630046 100644 --- a/raft/raftpb/raft.proto +++ b/raft/raftpb/raft.proto @@ -15,9 +15,9 @@ enum EntryType { } message Entry { + 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 optional EntryType Type = 1 [(gogoproto.nullable) = false]; - optional uint64 Term = 2 [(gogoproto.nullable) = false]; - optional uint64 Index = 3 [(gogoproto.nullable) = false]; optional bytes Data = 4; }