Skip to content

Commit bbb9f42

Browse files
committed
refactor(proto)!: move grpc service definition in protodb/v1alpha1
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
1 parent 56168d4 commit bbb9f42

26 files changed

Lines changed: 471 additions & 416 deletions

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ bin:
5252
@go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2
5353
@go install github.com/alta/protopatch/cmd/protoc-gen-go-patch
5454
@go install github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto
55+
@go install github.com/bufbuild/buf/cmd/buf@v1.45.0
5556

5657
clean:
5758
@rm -rf .bin
@@ -63,7 +64,8 @@ proto: gen-proto lint
6364

6465
.PHONY: gen-proto
6566
gen-proto: protoc-gen-protodb
66-
@find $(PROTO_BASE_PATH) -name '*.proto' -type f -exec \
67+
@buf generate
68+
@find $(PROTO_BASE_PATH)/tests -name '*.proto' -type f -exec \
6769
protoc $(INCLUDE_PROTO_PATH) \
6870
--go-patch_out=plugin=go,$(PROTO_OPTS):. \
6971
--go-patch_out=plugin=go-grpc,$(PROTO_OPTS):. \

buf.gen.yaml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
version: v2
22
plugins:
3-
- local: protoc-gen-go
3+
- local: protoc-gen-go-patch
44
out: .
55
opt:
6+
- plugin=go
67
- paths=source_relative
8+
- local: protoc-gen-go-patch
9+
out: .
10+
opt:
11+
- plugin=go-grpc
12+
- paths=source_relative
13+
- local: protoc-gen-go-patch
14+
out: .
15+
opt:
16+
- plugin=defaults
17+
- paths=source_relative
18+
- local: protoc-gen-go-patch
19+
out: .
20+
opt:
21+
- plugin=go-fields
22+
- paths=source_relative
23+
- local: protoc-gen-go-patch
24+
out: .
25+
opt:
26+
- plugin=proxy
27+
- paths=source_relative
28+
- local: protoc-gen-go-patch
29+
out: .
30+
opt:
31+
- plugin=go-vtproto
32+
- paths=source_relative
33+
- features=marshal+unmarshal+size+clone+equal
34+
- local: protoc-gen-go-patch
35+
out: .
36+
opt:
37+
- plugin=validate
38+
- paths=source_relative
39+
- lang=go

buf.lock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Generated by buf. DO NOT EDIT.
2+
version: v2
3+
deps:
4+
- name: buf.build/envoyproxy/protoc-gen-validate
5+
commit: daf171c6cdb54629b5f51e345a79e4dd
6+
digest: b5:c745e1521879f43740230b1df673d0729f55704efefdcfc489d4a0a2d40c92a26cacfeab62813403040a8b180142d53b398c7ca784a065e43823605ee49681de
7+
- name: buf.build/linka-cloud/protodb
8+
commit: bb18e34411f948f69750580fb9d83c8f
9+
digest: b5:99edeb77ff47c9001444240f677e4f6ac68a293325a13996e9d91ad5df02838a40503ad38493f1087d3941bd353a23a1788cedfa085c35e7fff80a51ed027783
10+
- name: buf.build/linka-cloud/protofilters
11+
commit: 5bf1a419b8964a539fe28cb1191c4a98
12+
digest: b5:2fae1db1ae748f1a84df3ec74164d546b731ffbeb73d20fba4a56ca69a595ba74d11db79c4b1155a2fedd7513823836fce252e0c69e799fcb39579d86e60e9e4
13+
- name: buf.build/linka-cloud/protopatch
14+
commit: b5f63439229a460e92dfb918d306f5bf
15+
digest: b5:2445ff476340c613ee0fa0ad12a178b6f9d1ad45319c07142839e500d875cc9a652bf9b9529961d3e6ae2282367aa94ad663786cd9fe94c6099690776843f19c

buf.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ lint:
1111
breaking:
1212
use:
1313
- FILE
14+
deps:
15+
- buf.build/envoyproxy/protoc-gen-validate
16+
- buf.build/linka-cloud/protopatch
17+
- buf.build/linka-cloud/protodb
18+
- buf.build/linka-cloud/protofilters

cmp.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import (
2323
"google.golang.org/protobuf/reflect/protoreflect"
2424
"google.golang.org/protobuf/types/known/structpb"
2525

26-
"go.linka.cloud/protodb/pb"
26+
"go.linka.cloud/protodb/protodb/v1alpha1"
2727
)
2828

29-
func cmpField(f protoreflect.FieldDescriptor, v1, v2 protoreflect.Value, prefix string, diffs map[string]*pb.FieldDiff) {
30-
diff := &pb.FieldDiff{}
29+
func cmpField(f protoreflect.FieldDescriptor, v1, v2 protoreflect.Value, prefix string, diffs map[string]*v1alpha1.FieldDiff) {
30+
diff := &v1alpha1.FieldDiff{}
3131
equals := false
3232
switch f.Kind() {
3333
case protoreflect.BoolKind:
@@ -114,7 +114,7 @@ func cmpField(f protoreflect.FieldDescriptor, v1, v2 protoreflect.Value, prefix
114114
if !f.IsList() {
115115
p += string(f.Name())
116116
}
117-
var mdiff map[string]*pb.FieldDiff
117+
var mdiff map[string]*v1alpha1.FieldDiff
118118
switch {
119119
case v1.IsValid() && v2.IsValid():
120120
mdiff = cmp(v1.Message().Interface(), v2.Message().Interface(), p)
@@ -134,11 +134,11 @@ func cmpField(f protoreflect.FieldDescriptor, v1, v2 protoreflect.Value, prefix
134134
}
135135
}
136136

137-
func cmp(m1, m2 proto.Message, prefix string) map[string]*pb.FieldDiff {
137+
func cmp(m1, m2 proto.Message, prefix string) map[string]*v1alpha1.FieldDiff {
138138
if prefix != "" {
139139
prefix += "."
140140
}
141-
diffs := make(map[string]*pb.FieldDiff)
141+
diffs := make(map[string]*v1alpha1.FieldDiff)
142142
var m proto.Message
143143
switch {
144144
case m1 != nil:
@@ -217,12 +217,12 @@ func cmp(m1, m2 proto.Message, prefix string) map[string]*pb.FieldDiff {
217217
return diffs
218218
}
219219

220-
func Cmp(m1, m2 proto.Message) (*pb.MessageDiff, error) {
220+
func Cmp(m1, m2 proto.Message) (*v1alpha1.MessageDiff, error) {
221221
if m1 != nil && m2 != nil {
222222
if n1, n2 := m1.ProtoReflect().Descriptor().FullName(), m2.ProtoReflect().Descriptor().FullName(); n1 != n2 {
223223
return nil, fmt.Errorf("cannot compare two different types: %s and %s", n1, n2)
224224
}
225225
}
226226
diffs := cmp(m1, m2, "")
227-
return &pb.MessageDiff{Fields: diffs}, nil
227+
return &v1alpha1.MessageDiff{Fields: diffs}, nil
228228
}

internal/badgerd/replication/gossip/gossip.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737
"go.linka.cloud/protodb/internal/badgerd/dns"
3838
"go.linka.cloud/protodb/internal/badgerd/replication"
3939
pb2 "go.linka.cloud/protodb/internal/badgerd/replication/gossip/pb"
40-
"go.linka.cloud/protodb/pb"
40+
"go.linka.cloud/protodb/protodb/v1alpha1"
4141
)
4242

4343
var (
@@ -54,7 +54,7 @@ var defaultOptions = replication.Options{
5454

5555
type Gossip struct {
5656
pb2.UnsafeReplicationServiceServer
57-
pb.UnsafeProtoDBServer
57+
v1alpha1.UnsafeProtoDBServer
5858

5959
ctx context.Context
6060
cancel context.CancelFunc
@@ -73,7 +73,7 @@ type Gossip struct {
7373
nodes Map[*node]
7474

7575
svc service.Service
76-
h pb.ProtoDBServer
76+
h v1alpha1.ProtoDBServer
7777
events chan memberlist.NodeEvent
7878
once sync.Once
7979
ready chan struct{}

internal/badgerd/replication/gossip/nodes.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
"google.golang.org/grpc/credentials/insecure"
3333

3434
pb2 "go.linka.cloud/protodb/internal/badgerd/replication/gossip/pb"
35-
"go.linka.cloud/protodb/pb"
35+
"go.linka.cloud/protodb/protodb/v1alpha1"
3636
)
3737

3838
type node struct {
@@ -41,7 +41,7 @@ type node struct {
4141
addr net.IP
4242
cc *grpc.ClientConn
4343
repl pb2.ReplicationServiceClient
44-
proxy pb.ProtoDBServer
44+
proxy v1alpha1.ProtoDBServer
4545
// elect pb2.ReplicationService_ElectionClient
4646
}
4747

@@ -145,7 +145,7 @@ func (r *Gossip) handleEvent(ctx context.Context, e memberlist.NodeEvent) {
145145
meta: m,
146146
cc: c,
147147
repl: cs,
148-
proxy: pb.NewProtoDBProxy(pb.NewProtoDBClient(c)),
148+
proxy: v1alpha1.NewProtoDBProxy(v1alpha1.NewProtoDBClient(c)),
149149
})
150150
log.Infof("connected to %s", e.Node.Name)
151151
if e.Node.Name == r.leaderName.Load() {

internal/client/client.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636

3737
"go.linka.cloud/protodb/internal/anypb"
3838
"go.linka.cloud/protodb/internal/protodb"
39-
"go.linka.cloud/protodb/pb"
39+
"go.linka.cloud/protodb/protodb/v1alpha1"
4040
)
4141

4242
type Client interface {
@@ -51,35 +51,35 @@ type Client interface {
5151
}
5252

5353
func NewClient(cc grpc.ClientConnInterface) (Client, error) {
54-
return &client{c: pb.NewProtoDBClient(cc)}, nil
54+
return &client{c: v1alpha1.NewProtoDBClient(cc)}, nil
5555
}
5656

5757
type client struct {
58-
c pb.ProtoDBClient
59-
locks map[string]grpc.ServerStreamingClient[pb.LockResponse]
58+
c v1alpha1.ProtoDBClient
59+
locks map[string]grpc.ServerStreamingClient[v1alpha1.LockResponse]
6060
mu sync.Mutex
6161
}
6262

6363
func (c *client) RegisterProto(ctx context.Context, file *descriptorpb.FileDescriptorProto) error {
64-
_, err := c.c.Register(ctx, &pb.RegisterRequest{File: file})
64+
_, err := c.c.Register(ctx, &v1alpha1.RegisterRequest{File: file})
6565
return err
6666
}
6767

6868
func (c *client) Register(ctx context.Context, file protoreflect.FileDescriptor) error {
69-
_, err := c.c.Register(ctx, &pb.RegisterRequest{File: protodesc.ToFileDescriptorProto(file)})
69+
_, err := c.c.Register(ctx, &v1alpha1.RegisterRequest{File: protodesc.ToFileDescriptorProto(file)})
7070
return err
7171
}
7272

7373
func (c *client) Descriptors(ctx context.Context) ([]*descriptorpb.DescriptorProto, error) {
74-
res, err := c.c.Descriptors(ctx, &pb.DescriptorsRequest{})
74+
res, err := c.c.Descriptors(ctx, &v1alpha1.DescriptorsRequest{})
7575
if err != nil {
7676
return nil, err
7777
}
7878
return res.Results, nil
7979
}
8080

8181
func (c *client) FileDescriptors(ctx context.Context) ([]*descriptorpb.FileDescriptorProto, error) {
82-
res, err := c.c.FileDescriptors(ctx, &pb.FileDescriptorsRequest{})
82+
res, err := c.c.FileDescriptors(ctx, &v1alpha1.FileDescriptorsRequest{})
8383
if err != nil {
8484
return nil, err
8585
}
@@ -96,7 +96,7 @@ func (c *client) Get(ctx context.Context, m proto.Message, opts ...protodb.GetOp
9696
if o.Filter != nil {
9797
f = o.Filter.Expr()
9898
}
99-
res, err := c.c.Get(ctx, &pb.GetRequest{Search: a, Filter: f, Paging: o.Paging, FieldMask: o.FieldMask, Reverse: o.Reverse, One: o.One, OrderBy: o.OrderBy})
99+
res, err := c.c.Get(ctx, &v1alpha1.GetRequest{Search: a, Filter: f, Paging: o.Paging, FieldMask: o.FieldMask, Reverse: o.Reverse, One: o.One, OrderBy: o.OrderBy})
100100
if err != nil {
101101
return nil, nil, err
102102
}
@@ -125,7 +125,7 @@ func (c *client) Set(ctx context.Context, m proto.Message, opts ...protodb.SetOp
125125
if o.TTL != 0 {
126126
ttl = durationpb.New(o.TTL)
127127
}
128-
res, err := c.c.Set(ctx, &pb.SetRequest{Payload: a, TTL: ttl, FieldMask: o.FieldMask})
128+
res, err := c.c.Set(ctx, &v1alpha1.SetRequest{Payload: a, TTL: ttl, FieldMask: o.FieldMask})
129129
if err != nil {
130130
return nil, err
131131
}
@@ -141,12 +141,12 @@ func (c *client) Delete(ctx context.Context, m proto.Message) error {
141141
if err != nil {
142142
return err
143143
}
144-
_, err = c.c.Delete(ctx, &pb.DeleteRequest{Payload: a})
144+
_, err = c.c.Delete(ctx, &v1alpha1.DeleteRequest{Payload: a})
145145
return err
146146
}
147147

148148
func (c *client) NextSeq(ctx context.Context, name string) (uint64, error) {
149-
res, err := c.c.NextSeq(ctx, &pb.NextSeqRequest{Key: name})
149+
res, err := c.c.NextSeq(ctx, &v1alpha1.NextSeqRequest{Key: name})
150150
if err != nil {
151151
return 0, err
152152
}
@@ -158,7 +158,7 @@ func (c *client) Lock(ctx context.Context, key string) error {
158158
if err != nil {
159159
return err
160160
}
161-
if err := s.Send(&pb.LockRequest{Key: key}); err != nil {
161+
if err := s.Send(&v1alpha1.LockRequest{Key: key}); err != nil {
162162
return err
163163
}
164164
if _, err := s.Recv(); err != nil {
@@ -199,7 +199,7 @@ func (c *client) Watch(ctx context.Context, m proto.Message, opts ...protodb.Get
199199
if o.Filter != nil {
200200
f = o.Filter.Expr()
201201
}
202-
w, err := c.c.Watch(ctx, &pb.WatchRequest{Search: a, Filter: f})
202+
w, err := c.c.Watch(ctx, &v1alpha1.WatchRequest{Search: a, Filter: f})
203203
if err != nil {
204204
return nil, err
205205
}
@@ -238,7 +238,7 @@ func (c *client) newTx(ctx context.Context, opts ...protodb.TxOption) (protodb.T
238238
opt(&o)
239239
}
240240
if o.ReadOnly {
241-
ctx = metadata.AppendToOutgoingContext(ctx, pb.ReadOnlyTxKey, "true")
241+
ctx = metadata.AppendToOutgoingContext(ctx, v1alpha1.ReadOnlyTxKey, "true")
242242
}
243243
txn, err := c.c.Tx(ctx)
244244
if err != nil {
@@ -249,7 +249,7 @@ func (c *client) newTx(ctx context.Context, opts ...protodb.TxOption) (protodb.T
249249

250250
type txc struct {
251251
ctx context.Context
252-
txn pb.ProtoDB_TxClient
252+
txn v1alpha1.ProtoDB_TxClient
253253
}
254254

255255
func (t *txc) Get(ctx context.Context, m proto.Message, opts ...protodb.GetOption) ([]proto.Message, *protodb.PagingInfo, error) {
@@ -262,9 +262,9 @@ func (t *txc) Get(ctx context.Context, m proto.Message, opts ...protodb.GetOptio
262262
if o.Filter != nil {
263263
f = o.Filter.Expr()
264264
}
265-
if err := t.txn.Send(&pb.TxRequest{
266-
Request: &pb.TxRequest_Get{
267-
Get: &pb.GetRequest{Search: a, Filter: f, Paging: o.Paging, FieldMask: o.FieldMask, Reverse: o.Reverse, One: o.One, OrderBy: o.OrderBy},
265+
if err := t.txn.Send(&v1alpha1.TxRequest{
266+
Request: &v1alpha1.TxRequest_Get{
267+
Get: &v1alpha1.GetRequest{Search: a, Filter: f, Paging: o.Paging, FieldMask: o.FieldMask, Reverse: o.Reverse, One: o.One, OrderBy: o.OrderBy},
268268
},
269269
}); err != nil {
270270
return nil, nil, err
@@ -301,9 +301,9 @@ func (t *txc) Set(ctx context.Context, m proto.Message, opts ...protodb.SetOptio
301301
if o.TTL != 0 {
302302
ttl = durationpb.New(o.TTL)
303303
}
304-
if err := t.txn.Send(&pb.TxRequest{
305-
Request: &pb.TxRequest_Set{
306-
Set: &pb.SetRequest{Payload: a, TTL: ttl, FieldMask: o.FieldMask},
304+
if err := t.txn.Send(&v1alpha1.TxRequest{
305+
Request: &v1alpha1.TxRequest_Set{
306+
Set: &v1alpha1.SetRequest{Payload: a, TTL: ttl, FieldMask: o.FieldMask},
307307
},
308308
}); err != nil {
309309
return nil, err
@@ -327,9 +327,9 @@ func (t *txc) Delete(ctx context.Context, m proto.Message) error {
327327
if err != nil {
328328
return err
329329
}
330-
if err := t.txn.Send(&pb.TxRequest{
331-
Request: &pb.TxRequest_Delete{
332-
Delete: &pb.DeleteRequest{Payload: a},
330+
if err := t.txn.Send(&v1alpha1.TxRequest{
331+
Request: &v1alpha1.TxRequest_Delete{
332+
Delete: &v1alpha1.DeleteRequest{Payload: a},
333333
},
334334
}); err != nil {
335335
return err
@@ -345,7 +345,7 @@ func (t *txc) Delete(ctx context.Context, m proto.Message) error {
345345
}
346346

347347
func (t *txc) Commit(ctx context.Context) error {
348-
if err := t.txn.Send(&pb.TxRequest{Request: &pb.TxRequest_Commit{Commit: wrapperspb.Bool(true)}}); err != nil {
348+
if err := t.txn.Send(&v1alpha1.TxRequest{Request: &v1alpha1.TxRequest_Commit{Commit: wrapperspb.Bool(true)}}); err != nil {
349349
return err
350350
}
351351
res, err := t.txn.Recv()
@@ -374,7 +374,7 @@ type eventc struct {
374374
err error
375375
}
376376

377-
func newEvent(e *pb.WatchEvent, err error) *eventc {
377+
func newEvent(e *v1alpha1.WatchEvent, err error) *eventc {
378378
ev := &eventc{typ: e.Type, err: err}
379379
if e.Old != nil {
380380
m, err := anypb.UnmarshalNew(e.Old)

0 commit comments

Comments
 (0)