Blame SOURCES/0001-update-grpc-go-version-to-v1.32.0.patch

62780e
From 2859e9f94608b44c9c351c7ccfcff21665573627 Mon Sep 17 00:00:00 2001
62780e
From: Sky Ao <aoxiaojian@gmail.com>
62780e
Date: Thu, 15 Oct 2020 15:34:16 +0800
62780e
Subject: [PATCH 1/4] update grpc-go version to v1.32.0 which has some breaking
62780e
 api changes in naming and loadbalancer package
62780e
62780e
---
62780e
 clientv3/balancer/balancer.go                 |  39 ++-
62780e
 clientv3/balancer/picker/err.go               |   6 +-
62780e
 .../balancer/picker/roundrobin_balanced.go    |   7 +-
62780e
 clientv3/naming/grpc.go                       |  27 +-
62780e
 clientv3/naming/grpcnaming/naming.go          |  73 +++++
62780e
 proxy/grpcproxy/cluster.go                    |   2 +-
62780e
 proxy/grpcproxy/register.go                   |   2 +-
62780e
 7 files changed, 424 insertions(+), 46 deletions(-)
62780e
 create mode 100644 clientv3/naming/grpcnaming/naming.go
62780e
62780e
diff --git a/clientv3/balancer/balancer.go b/clientv3/balancer/balancer.go
62780e
index 3eecb9d1d2..d3e672c632 100644
62780e
--- a/clientv3/balancer/balancer.go
62780e
+++ b/clientv3/balancer/balancer.go
62780e
@@ -136,15 +136,34 @@ type baseBalancer struct {
62780e
 	connectivityRecorder connectivity.Recorder
62780e
 
62780e
 	picker picker.Picker
62780e
+
62780e
+	resolverErr error // the last error reported by the resolver; cleared on successful resolution
62780e
 }
62780e
 
62780e
-// HandleResolvedAddrs implements "grpc/balancer.Balancer" interface.
62780e
-// gRPC sends initial or updated resolved addresses from "Build".
62780e
-func (bb *baseBalancer) HandleResolvedAddrs(addrs []resolver.Address, err error) {
62780e
-	if err != nil {
62780e
-		bb.lg.Warn("HandleResolvedAddrs called with error", zap.String("balancer-id", bb.id), zap.Error(err))
62780e
+func (bb *baseBalancer) ResolverError(err error) {
62780e
+	bb.resolverErr = err
62780e
+	if len(bb.addrToSc) == 0 {
62780e
+		bb.connectivityRecorder.RecordTransition(bb.connectivityRecorder.GetCurrentState(), grpcconnectivity.TransientFailure)
62780e
+	}
62780e
+
62780e
+	if bb.connectivityRecorder.GetCurrentState() != grpcconnectivity.TransientFailure {
62780e
+		// The picker will not change since the balancer does not currently
62780e
+		// report an error.
62780e
 		return
62780e
 	}
62780e
+	bb.updatePicker()
62780e
+	bb.currentConn.UpdateState(balancer.State{
62780e
+		ConnectivityState: bb.connectivityRecorder.GetCurrentState(),
62780e
+		Picker:            bb.picker,
62780e
+	})
62780e
+}
62780e
+
62780e
+// UpdateClientConnState implements "grpc/balancer.Balancer" interface.
62780e
+func (bb *baseBalancer) UpdateClientConnState(state balancer.ClientConnState) error {
62780e
+	addrs := state.ResolverState.Addresses
62780e
+	// Successful resolution; clear resolver error and ensure we return nil.
62780e
+	bb.resolverErr = nil
62780e
+
62780e
 	bb.lg.Info("resolved",
62780e
 		zap.String("picker", bb.picker.String()),
62780e
 		zap.String("balancer-id", bb.id),
62780e
@@ -191,10 +210,14 @@ func (bb *baseBalancer) HandleResolvedAddrs(addrs []resolver.Address, err error)
62780e
 			// (DO NOT) delete(bb.scToSt, sc)
62780e
 		}
62780e
 	}
62780e
+
62780e
+	return nil
62780e
 }
62780e
 
62780e
-// HandleSubConnStateChange implements "grpc/balancer.Balancer" interface.
62780e
-func (bb *baseBalancer) HandleSubConnStateChange(sc balancer.SubConn, s grpcconnectivity.State) {
62780e
+// UpdateSubConnState implements "grpc/balancer.Balancer" interface.
62780e
+func (bb *baseBalancer) UpdateSubConnState(sc balancer.SubConn, state balancer.SubConnState) {
62780e
+	s := state.ConnectivityState
62780e
+
62780e
 	bb.mu.Lock()
62780e
 	defer bb.mu.Unlock()
62780e
 
62780e
@@ -247,7 +270,7 @@ func (bb *baseBalancer) HandleSubConnStateChange(sc balancer.SubConn, s grpcconn
62780e
 		bb.updatePicker()
62780e
 	}
62780e
 
62780e
-	bb.currentConn.UpdateBalancerState(bb.connectivityRecorder.GetCurrentState(), bb.picker)
62780e
+	bb.currentConn.UpdateState(balancer.State{ConnectivityState: bb.connectivityRecorder.GetCurrentState(), Picker: bb.picker})
62780e
 }
62780e
 
62780e
 func (bb *baseBalancer) updatePicker() {
62780e
diff --git a/clientv3/balancer/picker/err.go b/clientv3/balancer/picker/err.go
62780e
index f4b941d652..a37baa7bd2 100644
62780e
--- a/clientv3/balancer/picker/err.go
62780e
+++ b/clientv3/balancer/picker/err.go
62780e
@@ -15,8 +15,6 @@
62780e
 package picker
62780e
 
62780e
 import (
62780e
-	"context"
62780e
-
62780e
 	"google.golang.org/grpc/balancer"
62780e
 )
62780e
 
62780e
@@ -34,6 +32,6 @@ func (ep *errPicker) String() string {
62780e
 	return ep.p.String()
62780e
 }
62780e
 
62780e
-func (ep *errPicker) Pick(context.Context, balancer.PickInfo) (balancer.SubConn, func(balancer.DoneInfo), error) {
62780e
-	return nil, nil, ep.err
62780e
+func (ep *errPicker) Pick(balancer.PickInfo) (balancer.PickResult, error) {
62780e
+	return balancer.PickResult{}, ep.err
62780e
 }
62780e
diff --git a/clientv3/balancer/picker/roundrobin_balanced.go b/clientv3/balancer/picker/roundrobin_balanced.go
62780e
index e3971ecc42..993c05ec13 100644
62780e
--- a/clientv3/balancer/picker/roundrobin_balanced.go
62780e
+++ b/clientv3/balancer/picker/roundrobin_balanced.go
62780e
@@ -15,7 +15,6 @@
62780e
 package picker
62780e
 
62780e
 import (
62780e
-	"context"
62780e
 	"sync"
62780e
 
62780e
 	"go.uber.org/zap"
62780e
@@ -52,12 +51,12 @@ type rrBalanced struct {
62780e
 func (rb *rrBalanced) String() string { return rb.p.String() }
62780e
 
62780e
 // Pick is called for every client request.
62780e
-func (rb *rrBalanced) Pick(ctx context.Context, opts balancer.PickInfo) (balancer.SubConn, func(balancer.DoneInfo), error) {
62780e
+func (rb *rrBalanced) Pick(opts balancer.PickInfo) (balancer.PickResult, error) {
62780e
 	rb.mu.RLock()
62780e
 	n := len(rb.scs)
62780e
 	rb.mu.RUnlock()
62780e
 	if n == 0 {
62780e
-		return nil, nil, balancer.ErrNoSubConnAvailable
62780e
+		return balancer.PickResult{}, balancer.ErrNoSubConnAvailable
62780e
 	}
62780e
 
62780e
 	rb.mu.Lock()
62780e
@@ -91,5 +90,5 @@ func (rb *rrBalanced) Pick(ctx context.Context, opts balancer.PickInfo) (balance
62780e
 			rb.lg.Warn("balancer failed", fss...)
62780e
 		}
62780e
 	}
62780e
-	return sc, doneFunc, nil
62780e
+	return balancer.PickResult{SubConn: sc, Done: doneFunc}, nil
62780e
 }
62780e
diff --git a/clientv3/naming/grpc.go b/clientv3/naming/grpc.go
62780e
index b680274bb3..f7cd2bd8a6 100644
62780e
--- a/clientv3/naming/grpc.go
62780e
+++ b/clientv3/naming/grpc.go
62780e
@@ -20,9 +20,9 @@ import (
62780e
 	"fmt"
62780e
62780e
 	etcd "go.etcd.io/etcd/clientv3"
62780e
+	gnaming "go.etcd.io/etcd/clientv3/naming/grpcnaming"
62780e
62780e
 	"google.golang.org/grpc/codes"
62780e
-	"google.golang.org/grpc/naming"
62780e
 	"google.golang.org/grpc/status"
62780e
 )
62780e
62780e
@@ -34,15 +33,15 @@ type GRPCResolver struct {
62780e
 	Client *etcd.Client
62780e
 }
62780e
 
62780e
-func (gr *GRPCResolver) Update(ctx context.Context, target string, nm naming.Update, opts ...etcd.OpOption) (err error) {
62780e
+func (gr *GRPCResolver) Update(ctx context.Context, target string, nm gnaming.Update, opts ...etcd.OpOption) (err error) {
62780e
 	switch nm.Op {
62780e
-	case naming.Add:
62780e
+	case gnaming.Add:
62780e
 		var v []byte
62780e
 		if v, err = json.Marshal(nm); err != nil {
62780e
 			return status.Error(codes.InvalidArgument, err.Error())
62780e
 		}
62780e
 		_, err = gr.Client.KV.Put(ctx, target+"/"+nm.Addr, string(v), opts...)
62780e
-	case naming.Delete:
62780e
+	case gnaming.Delete:
62780e
 		_, err = gr.Client.Delete(ctx, target+"/"+nm.Addr, opts...)
62780e
 	default:
62780e
 		return status.Error(codes.InvalidArgument, "naming: bad naming op")
62780e
@@ -50,7 +49,7 @@ func (gr *GRPCResolver) Update(ctx context.Context, target string, nm naming.Upd
62780e
 	return err
62780e
 }
62780e
 
62780e
-func (gr *GRPCResolver) Resolve(target string) (naming.Watcher, error) {
62780e
+func (gr *GRPCResolver) Resolve(target string) (gnaming.Watcher, error) {
62780e
 	ctx, cancel := context.WithCancel(context.Background())
62780e
 	w := &gRPCWatcher{c: gr.Client, target: target + "/", ctx: ctx, cancel: cancel}
62780e
 	return w, nil
62780e
@@ -68,7 +67,7 @@ type gRPCWatcher struct {
62780e
 // Next gets the next set of updates from the etcd resolver.
62780e
 // Calls to Next should be serialized; concurrent calls are not safe since
62780e
 // there is no way to reconcile the update ordering.
62780e
-func (gw *gRPCWatcher) Next() ([]*naming.Update, error) {
62780e
+func (gw *gRPCWatcher) Next() ([]*gnaming.Update, error) {
62780e
 	if gw.wch == nil {
62780e
 		// first Next() returns all addresses
62780e
 		return gw.firstNext()
62780e
@@ -87,17 +86,17 @@ func (gw *gRPCWatcher) Next() ([]*naming.Update, error) {
62780e
 		return nil, gw.err
62780e
 	}
62780e
 
62780e
-	updates := make([]*naming.Update, 0, len(wr.Events))
62780e
+	updates := make([]*gnaming.Update, 0, len(wr.Events))
62780e
 	for _, e := range wr.Events {
62780e
-		var jupdate naming.Update
62780e
+		var jupdate gnaming.Update
62780e
 		var err error
62780e
 		switch e.Type {
62780e
 		case etcd.EventTypePut:
62780e
 			err = json.Unmarshal(e.Kv.Value, &jupdate)
62780e
-			jupdate.Op = naming.Add
62780e
+			jupdate.Op = gnaming.Add
62780e
 		case etcd.EventTypeDelete:
62780e
 			err = json.Unmarshal(e.PrevKv.Value, &jupdate)
62780e
-			jupdate.Op = naming.Delete
62780e
+			jupdate.Op = gnaming.Delete
62780e
 		default:
62780e
 			continue
62780e
 		}
62780e
@@ -108,7 +107,7 @@ func (gw *gRPCWatcher) Next() ([]*naming.Update, error) {
62780e
 	return updates, nil
62780e
 }
62780e
 
62780e
-func (gw *gRPCWatcher) firstNext() ([]*naming.Update, error) {
62780e
+func (gw *gRPCWatcher) firstNext() ([]*gnaming.Update, error) {
62780e
 	// Use serialized request so resolution still works if the target etcd
62780e
 	// server is partitioned away from the quorum.
62780e
 	resp, err := gw.c.Get(gw.ctx, gw.target, etcd.WithPrefix(), etcd.WithSerializable())
62780e
@@ -116,9 +115,9 @@ func (gw *gRPCWatcher) firstNext() ([]*naming.Update, error) {
62780e
 		return nil, err
62780e
 	}
62780e
 
62780e
-	updates := make([]*naming.Update, 0, len(resp.Kvs))
62780e
+	updates := make([]*gnaming.Update, 0, len(resp.Kvs))
62780e
 	for _, kv := range resp.Kvs {
62780e
-		var jupdate naming.Update
62780e
+		var jupdate gnaming.Update
62780e
 		if err := json.Unmarshal(kv.Value, &jupdate); err != nil {
62780e
 			continue
62780e
 		}
62780e
diff --git a/clientv3/naming/grpcnaming/naming.go b/clientv3/naming/grpcnaming/naming.go
62780e
new file mode 100644
62780e
index 0000000000..9b1f20cc61
62780e
--- /dev/null
62780e
+++ b/clientv3/naming/grpcnaming/naming.go
62780e
@@ -0,0 +1,73 @@
62780e
+/*
62780e
+ *
62780e
+ * Copyright 2014 gRPC authors.
62780e
+ *
62780e
+ * Licensed under the Apache License, Version 2.0 (the "License");
62780e
+ * you may not use this file except in compliance with the License.
62780e
+ * You may obtain a copy of the License at
62780e
+ *
62780e
+ *     http://www.apache.org/licenses/LICENSE-2.0
62780e
+ *
62780e
+ * Unless required by applicable law or agreed to in writing, software
62780e
+ * distributed under the License is distributed on an "AS IS" BASIS,
62780e
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
62780e
+ * See the License for the specific language governing permissions and
62780e
+ * limitations under the License.
62780e
+ *
62780e
+ */
62780e
+
62780e
+// Package naming defines the naming API and related data structures for gRPC.
62780e
+//
62780e
+// This package is deprecated: please use package resolver instead.
62780e
+
62780e
+
62780e
+// Notice: this file is a copy of naming/naming.go from grpc-go v1.29.1.
62780e
+// The package of grpc naming is removed since grpc-go v1.30.0.
62780e
+// This is a work around to make etcd work with grpc new version (>=v1.30.0) without too many code change.
62780e
+package grpcnaming
62780e
+
62780e
+// Operation defines the corresponding operations for a name resolution change.
62780e
+//
62780e
+// Deprecated: please use package resolver.
62780e
+type Operation uint8
62780e
+
62780e
+const (
62780e
+	// Add indicates a new address is added.
62780e
+	Add Operation = iota
62780e
+	// Delete indicates an existing address is deleted.
62780e
+	Delete
62780e
+)
62780e
+
62780e
+// Update defines a name resolution update. Notice that it is not valid having both
62780e
+// empty string Addr and nil Metadata in an Update.
62780e
+//
62780e
+// Deprecated: please use package resolver.
62780e
+type Update struct {
62780e
+	// Op indicates the operation of the update.
62780e
+	Op Operation
62780e
+	// Addr is the updated address. It is empty string if there is no address update.
62780e
+	Addr string
62780e
+	// Metadata is the updated metadata. It is nil if there is no metadata update.
62780e
+	// Metadata is not required for a custom naming implementation.
62780e
+	Metadata interface{}
62780e
+}
62780e
+
62780e
+// Resolver creates a Watcher for a target to track its resolution changes.
62780e
+//
62780e
+// Deprecated: please use package resolver.
62780e
+type Resolver interface {
62780e
+	// Resolve creates a Watcher for target.
62780e
+	Resolve(target string) (Watcher, error)
62780e
+}
62780e
+
62780e
+// Watcher watches for the updates on the specified target.
62780e
+//
62780e
+// Deprecated: please use package resolver.
62780e
+type Watcher interface {
62780e
+	// Next blocks until an update or error happens. It may return one or more
62780e
+	// updates. The first call should get the full set of the results. It should
62780e
+	// return an error if and only if Watcher cannot recover.
62780e
+	Next() ([]*Update, error)
62780e
+	// Close closes the Watcher.
62780e
+	Close()
62780e
+}
62780e
\ No newline at end of file
62780e
diff --git a/proxy/grpcproxy/cluster.go b/proxy/grpcproxy/cluster.go
62780e
index 5f3ab76584..a786457a6a 100644
62780e
--- a/proxy/grpcproxy/cluster.go
62780e
+++ b/proxy/grpcproxy/cluster.go
62780e
@@ -18,6 +18,7 @@ import (
62780e
 	"context"
62780e
 	"errors"
62780e
 	"fmt"
62780e
+	gnaming "go.etcd.io/etcd/clientv3/naming/grpcnaming"
62780e
 	"os"
62780e
 	"sync"
62780e
62780e
@@ -27,7 +28,6 @@ import (
62780e
 	pb "go.etcd.io/etcd/etcdserver/etcdserverpb"
62780e
62780e
 	"golang.org/x/time/rate"
62780e
-	gnaming "google.golang.org/grpc/naming"
62780e
 )
62780e
62780e
 // allow maximum 1 retry per second
62780e
diff --git a/proxy/grpcproxy/register.go b/proxy/grpcproxy/register.go
62780e
index e74cd5ca90..912e147d77 100644
62780e
--- a/proxy/grpcproxy/register.go
62780e
+++ b/proxy/grpcproxy/register.go
62780e
@@ -16,6 +16,7 @@ package grpcproxy
62780e
62780e
 import (
62780e
 	"encoding/json"
62780e
+	gnaming "go.etcd.io/etcd/clientv3/naming/grpcnaming"
62780e
 	"os"
62780e
62780e
 	"go.etcd.io/etcd/clientv3"
62780e
@@ -23,7 +24,6 @@ import (
62780e
 	"go.etcd.io/etcd/clientv3/naming"
62780e
62780e
 	"golang.org/x/time/rate"
62780e
-	gnaming "google.golang.org/grpc/naming"
62780e
 )
62780e
62780e
 // allow maximum 1 retry per second
62780e
From b1d600ee05737adf6fc2ba3a5c3d92c1037bb6a6 Mon Sep 17 00:00:00 2001
62780e
From: Sky Ao <aoxiaojian@gmail.com>
62780e
Date: Thu, 22 Oct 2020 11:20:17 +0800
62780e
Subject: [PATCH 3/4] add doc for method ResolveError()
62780e
62780e
---
62780e
 clientv3/balancer/balancer.go | 1 +
62780e
 1 file changed, 1 insertion(+)
62780e
62780e
diff --git a/clientv3/balancer/balancer.go b/clientv3/balancer/balancer.go
62780e
index d3e672c632..1488580331 100644
62780e
--- a/clientv3/balancer/balancer.go
62780e
+++ b/clientv3/balancer/balancer.go
62780e
@@ -140,6 +140,7 @@ type baseBalancer struct {
62780e
 	resolverErr error // the last error reported by the resolver; cleared on successful resolution
62780e
 }
62780e
 
62780e
+// ResolverError implements "grpc/balancer.Balancer" interface.
62780e
 func (bb *baseBalancer) ResolverError(err error) {
62780e
 	bb.resolverErr = err
62780e
 	if len(bb.addrToSc) == 0 {
62780e
62780e
From 5ba58f2283eda7247f51b4e9dd07c367c4d77235 Mon Sep 17 00:00:00 2001
62780e
From: Sky Ao <aoxiaojian@gmail.com>
62780e
Date: Thu, 22 Oct 2020 11:36:03 +0800
62780e
Subject: [PATCH 4/4] update to pass fmt checking
62780e
62780e
---
62780e
 clientv3/naming/grpcnaming/naming.go | 7 +------
62780e
 1 file changed, 1 insertion(+), 6 deletions(-)
62780e
62780e
diff --git a/clientv3/naming/grpcnaming/naming.go b/clientv3/naming/grpcnaming/naming.go
62780e
index 9b1f20cc61..a4415a6541 100644
62780e
--- a/clientv3/naming/grpcnaming/naming.go
62780e
+++ b/clientv3/naming/grpcnaming/naming.go
62780e
@@ -19,11 +19,6 @@
62780e
 // Package naming defines the naming API and related data structures for gRPC.
62780e
 //
62780e
 // This package is deprecated: please use package resolver instead.
62780e
-
62780e
-
62780e
-// Notice: this file is a copy of naming/naming.go from grpc-go v1.29.1.
62780e
-// The package of grpc naming is removed since grpc-go v1.30.0.
62780e
-// This is a work around to make etcd work with grpc new version (>=v1.30.0) without too many code change.
62780e
 package grpcnaming
62780e
 
62780e
 // Operation defines the corresponding operations for a name resolution change.
62780e
@@ -70,4 +65,4 @@ type Watcher interface {
62780e
 	Next() ([]*Update, error)
62780e
 	// Close closes the Watcher.
62780e
 	Close()
62780e
-}
62780e
\ No newline at end of file
62780e
+}