From 45390b9fb8b05dfae14bc9b0bd2b5ff7d39143f3 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Thu, 3 Sep 2015 12:57:59 -0400 Subject: [PATCH] *: regenerate proto to use local import path Using Go-style import paths in protos is not idiomatic. Normally, this detail would be internal to etcd, but the path from which gogoproto is imported affects downstream consumers (e.g. cockroachdb). In cockroach, we want to avoid including `$GOPATH/src` in our protoc include path for various reasons. This patch puts etcd on the same convention, which allows this for cockroach. More information: https://github.com/cockroachdb/cockroach/pull/2339#discussion_r38663417 This commit also regenerates all the protos, which seem to have drifted a tiny bit. --- etcdserver/etcdserverpb/etcdserver.pb.go | 2 +- etcdserver/etcdserverpb/etcdserver.proto | 2 +- etcdserver/etcdserverpb/raft_internal.pb.go | 2 +- etcdserver/etcdserverpb/raft_internal.proto | 2 +- etcdserver/etcdserverpb/rpc.pb.go | 38 ++++++++++++++++++++- etcdserver/etcdserverpb/rpc.proto | 16 ++++----- raft/raftpb/raft.pb.go | 2 +- raft/raftpb/raft.proto | 2 +- scripts/genproto.sh | 13 +++++-- snap/snappb/snap.pb.go | 2 +- snap/snappb/snap.proto | 2 +- storage/storagepb/kv.pb.go | 8 ++--- storage/storagepb/kv.proto | 2 +- wal/walpb/record.pb.go | 2 +- wal/walpb/record.proto | 2 +- 15 files changed, 70 insertions(+), 27 deletions(-) diff --git a/etcdserver/etcdserverpb/etcdserver.pb.go b/etcdserver/etcdserverpb/etcdserver.pb.go index 6626e706e..305adcd8c 100644 --- a/etcdserver/etcdserverpb/etcdserver.pb.go +++ b/etcdserver/etcdserverpb/etcdserver.pb.go @@ -19,7 +19,7 @@ package etcdserverpb import proto "github.com/coreos/etcd/Godeps/_workspace/src/github.com/gogo/protobuf/proto" import math "math" -// discarding unused import gogoproto "github.com/gogo/protobuf/gogoproto/gogo.pb" +// discarding unused import gogoproto "github.com/coreos/etcd/Godeps/_workspace/src/gogoproto/gogo.pb" import io "io" import fmt "fmt" diff --git a/etcdserver/etcdserverpb/etcdserver.proto b/etcdserver/etcdserverpb/etcdserver.proto index bfc29625c..024c3037f 100644 --- a/etcdserver/etcdserverpb/etcdserver.proto +++ b/etcdserver/etcdserverpb/etcdserver.proto @@ -1,7 +1,7 @@ syntax = "proto2"; package etcdserverpb; -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "gogoproto/gogo.proto"; option (gogoproto.marshaler_all) = true; option (gogoproto.sizer_all) = true; diff --git a/etcdserver/etcdserverpb/raft_internal.pb.go b/etcdserver/etcdserverpb/raft_internal.pb.go index c3073178a..cf949d9f2 100644 --- a/etcdserver/etcdserverpb/raft_internal.pb.go +++ b/etcdserver/etcdserverpb/raft_internal.pb.go @@ -6,7 +6,7 @@ package etcdserverpb import proto "github.com/coreos/etcd/Godeps/_workspace/src/github.com/gogo/protobuf/proto" -// discarding unused import gogoproto "github.com/gogo/protobuf/gogoproto/gogo.pb" +// discarding unused import gogoproto "github.com/coreos/etcd/Godeps/_workspace/src/gogoproto/gogo.pb" import io "io" import fmt "fmt" diff --git a/etcdserver/etcdserverpb/raft_internal.proto b/etcdserver/etcdserverpb/raft_internal.proto index 4fb496bfd..7cf7b67d0 100644 --- a/etcdserver/etcdserverpb/raft_internal.proto +++ b/etcdserver/etcdserverpb/raft_internal.proto @@ -1,7 +1,7 @@ syntax = "proto3"; package etcdserverpb; -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "gogoproto/gogo.proto"; import "etcdserver.proto"; import "rpc.proto"; diff --git a/etcdserver/etcdserverpb/rpc.pb.go b/etcdserver/etcdserverpb/rpc.pb.go index fa208a30c..32c4c845e 100644 --- a/etcdserver/etcdserverpb/rpc.pb.go +++ b/etcdserver/etcdserverpb/rpc.pb.go @@ -6,7 +6,7 @@ package etcdserverpb import proto "github.com/coreos/etcd/Godeps/_workspace/src/github.com/gogo/protobuf/proto" -// discarding unused import gogoproto "github.com/gogo/protobuf/gogoproto/gogo.pb" +// discarding unused import gogoproto "github.com/coreos/etcd/Godeps/_workspace/src/gogoproto/gogo.pb" import storagepb "github.com/coreos/etcd/storage/storagepb" import io "io" @@ -108,6 +108,8 @@ type RangeResponse struct { Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` Kvs []*storagepb.KeyValue `protobuf:"bytes,2,rep,name=kvs" json:"kvs,omitempty"` ConsistentToken []byte `protobuf:"bytes,3,opt,name=consistent_token,proto3" json:"consistent_token,omitempty"` + // more indicates if there are more keys to return in the requested range. + More bool `protobuf:"varint,4,opt,name=more,proto3" json:"more,omitempty"` } func (m *RangeResponse) Reset() { *m = RangeResponse{} } @@ -329,6 +331,10 @@ func (m *TxnResponse) GetResponses() []*ResponseUnion { return nil } +// Compaction compacts the kv store upto the given index (including). +// It removes the old versions of a key. It keeps the newest version of +// the key even if its latest modification index is smaller than the given +// index. type CompactionRequest struct { Index int64 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"` } @@ -696,6 +702,23 @@ func (m *RangeResponse) Unmarshal(data []byte) error { } m.ConsistentToken = append([]byte{}, data[iNdEx:postIndex]...) iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field More", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + v |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + m.More = bool(v != 0) default: var sizeOfWire int for { @@ -1942,6 +1965,9 @@ func (m *RangeResponse) Size() (n int) { n += 1 + l + sovRpc(uint64(l)) } } + if m.More { + n += 2 + } return n } @@ -2281,6 +2307,16 @@ func (m *RangeResponse) MarshalTo(data []byte) (n int, err error) { i += copy(data[i:], m.ConsistentToken) } } + if m.More { + data[i] = 0x20 + i++ + if m.More { + data[i] = 1 + } else { + data[i] = 0 + } + i++ + } return i, nil } diff --git a/etcdserver/etcdserverpb/rpc.proto b/etcdserver/etcdserverpb/rpc.proto index a079df004..abe8bcb15 100644 --- a/etcdserver/etcdserverpb/rpc.proto +++ b/etcdserver/etcdserverpb/rpc.proto @@ -1,8 +1,8 @@ syntax = "proto3"; package etcdserverpb; -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; -import "github.com/coreos/etcd/storage/storagepb/kv.proto"; +import "gogoproto/gogo.proto"; +import "etcd/storage/storagepb/kv.proto"; option (gogoproto.marshaler_all) = true; option (gogoproto.unmarshaler_all) = true; @@ -50,7 +50,7 @@ message RangeRequest { bytes range_end = 2; // limit the number of keys returned. int64 limit = 3; - // the response will be consistent with previous request with same token if the token is + // the response will be consistent with previous request with same token if the token is // given and is valid. bytes consistent_token = 4; } @@ -127,9 +127,9 @@ message Compare { } } -// If the comparisons succeed, then the success requests will be processed in order, +// If the comparisons succeed, then the success requests will be processed in order, // and the response will contain their respective responses in order. -// If the comparisons fail, then the failure requests will be processed in order, +// If the comparisons fail, then the failure requests will be processed in order, // and the response will contain their respective responses in order. // From google paxosdb paper: @@ -159,9 +159,9 @@ message TxnResponse { repeated ResponseUnion responses = 3; } -// Compaction compacts the kv store upto the given index (including). -// It removes the old versions of a key. It keeps the newest version of -// the key even if its latest modification index is smaller than the given +// Compaction compacts the kv store upto the given index (including). +// It removes the old versions of a key. It keeps the newest version of +// the key even if its latest modification index is smaller than the given // index. message CompactionRequest { int64 index = 1; diff --git a/raft/raftpb/raft.pb.go b/raft/raftpb/raft.pb.go index 26a4eb6bc..24cd8f160 100644 --- a/raft/raftpb/raft.pb.go +++ b/raft/raftpb/raft.pb.go @@ -22,7 +22,7 @@ package raftpb import proto "github.com/coreos/etcd/Godeps/_workspace/src/github.com/gogo/protobuf/proto" import math "math" -// discarding unused import gogoproto "github.com/gogo/protobuf/gogoproto/gogo.pb" +// discarding unused import gogoproto "github.com/coreos/etcd/Godeps/_workspace/src/gogoproto/gogo.pb" import io "io" import fmt "fmt" diff --git a/raft/raftpb/raft.proto b/raft/raftpb/raft.proto index bdf7a504e..1da4fc008 100644 --- a/raft/raftpb/raft.proto +++ b/raft/raftpb/raft.proto @@ -1,7 +1,7 @@ syntax = "proto2"; package raftpb; -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "gogoproto/gogo.proto"; option (gogoproto.marshaler_all) = true; option (gogoproto.sizer_all) = true; diff --git a/scripts/genproto.sh b/scripts/genproto.sh index 1245bc922..8af3cbdb4 100755 --- a/scripts/genproto.sh +++ b/scripts/genproto.sh @@ -22,7 +22,7 @@ export GOBIN=${PWD}/bin go get github.com/gogo/protobuf/{proto,protoc-gen-gogo,gogoproto} pushd ${GOPATH}/src/github.com/gogo/protobuf/ git reset --hard ${SHA} - make + make install popd export PATH="${GOBIN}:${PATH}" @@ -35,10 +35,17 @@ for dir in ${DIRS}; do popd done +COREOS_ROOT="${GOPATH}/src/github.com/coreos" +GOGOPROTO_ROOT="${GOPATH}/src/github.com/gogo/protobuf" +GOGOPROTO_PATH="${GOGOPROTO_ROOT}:${GOGOPROTO_ROOT}/protobuf" + +ESCAPED_PREFIX=$(echo $PREFIX | sed -e 's/[\/&]/\\&/g') + for dir in ${DIRS}; do pushd ${dir} - protoc --gogofast_out=plugins=grpc:. -I=.:${GOPATH}/src/github.com/gogo/protobuf/protobuf:${GOPATH}/src *.proto - sed -i".bak" -e "s|github.com/gogo/protobuf/proto|${PREFIX}/github.com/gogo/protobuf/proto|" *.go + protoc --gogofast_out=plugins=grpc,import_prefix=github.com/coreos/:. -I=.:"${GOGOPROTO_PATH}":"${COREOS_ROOT}" *.proto + sed -i.bak -E "s/github\.com\/coreos\/(gogoproto|github\.com|golang\.org|google\.golang\.org)/${ESCAPED_PREFIX}\/\1/g" *.pb.go + sed -i.bak -E 's/github\.com\/coreos\/(errors|fmt|io)/\1/g' *.pb.go rm -f *.bak popd done diff --git a/snap/snappb/snap.pb.go b/snap/snappb/snap.pb.go index ea8e3e59d..e680fa7ce 100644 --- a/snap/snappb/snap.pb.go +++ b/snap/snappb/snap.pb.go @@ -16,7 +16,7 @@ package snappb import proto "github.com/coreos/etcd/Godeps/_workspace/src/github.com/gogo/protobuf/proto" import math "math" -// discarding unused import gogoproto "github.com/gogo/protobuf/gogoproto/gogo.pb" +// discarding unused import gogoproto "github.com/coreos/etcd/Godeps/_workspace/src/gogoproto/gogo.pb" import io "io" import fmt "fmt" diff --git a/snap/snappb/snap.proto b/snap/snappb/snap.proto index caebcbee0..cd3d21d0e 100644 --- a/snap/snappb/snap.proto +++ b/snap/snappb/snap.proto @@ -1,7 +1,7 @@ syntax = "proto2"; package snappb; -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "gogoproto/gogo.proto"; option (gogoproto.marshaler_all) = true; option (gogoproto.sizer_all) = true; diff --git a/storage/storagepb/kv.pb.go b/storage/storagepb/kv.pb.go index 8f54cca03..7cd5c6405 100644 --- a/storage/storagepb/kv.pb.go +++ b/storage/storagepb/kv.pb.go @@ -16,7 +16,7 @@ package storagepb import proto "github.com/coreos/etcd/Godeps/_workspace/src/github.com/gogo/protobuf/proto" -// discarding unused import gogoproto "github.com/gogo/protobuf/gogoproto/gogo.pb" +// discarding unused import gogoproto "github.com/coreos/etcd/Godeps/_workspace/src/gogoproto/gogo.pb" import io "io" import fmt "fmt" @@ -48,10 +48,10 @@ func (x Event_EventType) String() string { } type KeyValue struct { - Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + CreateIndex int64 `protobuf:"varint,2,opt,name=create_index,proto3" json:"create_index,omitempty"` // mod_index is the last modified index of the key. - CreateIndex int64 `protobuf:"varint,2,opt,name=create_index,proto3" json:"create_index,omitempty"` - ModIndex int64 `protobuf:"varint,3,opt,name=mod_index,proto3" json:"mod_index,omitempty"` + ModIndex int64 `protobuf:"varint,3,opt,name=mod_index,proto3" json:"mod_index,omitempty"` // version is the version of the key. A deletion resets // the version to zero and any modification of the key // increases its version. diff --git a/storage/storagepb/kv.proto b/storage/storagepb/kv.proto index 6f4bf950f..4a4464685 100644 --- a/storage/storagepb/kv.proto +++ b/storage/storagepb/kv.proto @@ -1,7 +1,7 @@ syntax = "proto3"; package storagepb; -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "gogoproto/gogo.proto"; option (gogoproto.marshaler_all) = true; option (gogoproto.sizer_all) = true; diff --git a/wal/walpb/record.pb.go b/wal/walpb/record.pb.go index 599a5095f..c1208463a 100644 --- a/wal/walpb/record.pb.go +++ b/wal/walpb/record.pb.go @@ -17,7 +17,7 @@ package walpb import proto "github.com/coreos/etcd/Godeps/_workspace/src/github.com/gogo/protobuf/proto" import math "math" -// discarding unused import gogoproto "github.com/gogo/protobuf/gogoproto/gogo.pb" +// discarding unused import gogoproto "github.com/coreos/etcd/Godeps/_workspace/src/gogoproto/gogo.pb" import io "io" import fmt "fmt" diff --git a/wal/walpb/record.proto b/wal/walpb/record.proto index b70b54a7c..b694cb233 100644 --- a/wal/walpb/record.proto +++ b/wal/walpb/record.proto @@ -1,7 +1,7 @@ syntax = "proto2"; package walpb; -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "gogoproto/gogo.proto"; option (gogoproto.marshaler_all) = true; option (gogoproto.sizer_all) = true;