Upgrade google.golang.org/grpc version #1374

Merged
dstepanov-yadro merged 1 commit from dstepanov-yadro/frostfs-node:feat/upgrade_grpc_version into master 2024-10-26 11:30:26 +00:00
2 changed files with 26 additions and 9 deletions

View file

@ -2,6 +2,7 @@ package tree
import ( import (
"context" "context"
"crypto/ecdsa"
"errors" "errors"
"fmt" "fmt"
"sync" "sync"
@ -19,6 +20,7 @@ import (
type clientCache struct { type clientCache struct {
sync.Mutex sync.Mutex
simplelru.LRU[string, cacheItem] simplelru.LRU[string, cacheItem]
key *ecdsa.PrivateKey
} }
type cacheItem struct { type cacheItem struct {
@ -34,13 +36,14 @@ const (
var errRecentlyFailed = errors.New("client has recently failed") var errRecentlyFailed = errors.New("client has recently failed")
func (c *clientCache) init() { func (c *clientCache) init(pk *ecdsa.PrivateKey) {
l, _ := simplelru.NewLRU(defaultClientCacheSize, func(_ string, value cacheItem) { l, _ := simplelru.NewLRU(defaultClientCacheSize, func(_ string, value cacheItem) {
if conn := value.cc; conn != nil { if conn := value.cc; conn != nil {
_ = conn.Close() _ = conn.Close()
} }
}) })
c.LRU = *l c.LRU = *l
c.key = pk
} }
func (c *clientCache) get(ctx context.Context, netmapAddr string) (TreeServiceClient, error) { func (c *clientCache) get(ctx context.Context, netmapAddr string) (TreeServiceClient, error) {
@ -63,7 +66,7 @@ func (c *clientCache) get(ctx context.Context, netmapAddr string) (TreeServiceCl
} }
} }
cc, err := dialTreeService(ctx, netmapAddr) cc, err := c.dialTreeService(ctx, netmapAddr)
lastTry := time.Now() lastTry := time.Now()
c.Lock() c.Lock()
@ -81,14 +84,13 @@ func (c *clientCache) get(ctx context.Context, netmapAddr string) (TreeServiceCl
return NewTreeServiceClient(cc), nil return NewTreeServiceClient(cc), nil
} }
func dialTreeService(ctx context.Context, netmapAddr string) (*grpc.ClientConn, error) { func (c *clientCache) dialTreeService(ctx context.Context, netmapAddr string) (*grpc.ClientConn, error) {
var netAddr network.Address var netAddr network.Address
if err := netAddr.FromString(netmapAddr); err != nil { if err := netAddr.FromString(netmapAddr); err != nil {
return nil, err return nil, err
} }
opts := []grpc.DialOption{ opts := []grpc.DialOption{
grpc.WithBlock(),
grpc.WithChainUnaryInterceptor( grpc.WithChainUnaryInterceptor(
metrics.NewUnaryClientInterceptor(), metrics.NewUnaryClientInterceptor(),
tracing.NewUnaryClientInteceptor(), tracing.NewUnaryClientInteceptor(),
@ -103,9 +105,24 @@ func dialTreeService(ctx context.Context, netmapAddr string) (*grpc.ClientConn,
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials())) opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
} }
ctx, cancel := context.WithTimeout(ctx, defaultClientConnectTimeout) req := &HealthcheckRequest{
cc, err := grpc.DialContext(ctx, netAddr.URIAddr(), opts...) Body: &HealthcheckRequest_Body{},
cancel() }
if err := SignMessage(req, c.key); err != nil {
return nil, err
}
return cc, err cc, err := grpc.NewClient(netAddr.URIAddr(), opts...)
if err != nil {
return nil, err
}
ctx, cancel := context.WithTimeout(ctx, defaultClientConnectTimeout)
defer cancel()
// perform some request to check connection
if _, err := NewTreeServiceClient(cc).Healthcheck(ctx, req); err != nil {

Can we use only connection methods, like WaitForStateChange?

Can we use only connection methods, like `WaitForStateChange`?

I checked the option with WaitForStateChange, but it requires cc.Connect() call which is experimental. So I decided to perform regualr RPC request.

image

I checked the option with `WaitForStateChange`, but it requires `cc.Connect()` call which is experimental. So I decided to perform regualr RPC request. ![image](/attachments/1d88b92d-ef48-4de9-b9aa-12d20ddf9495)
_ = cc.Close()
return nil, err
}
return cc, nil
} }

View file

@ -65,7 +65,7 @@ func New(opts ...Option) *Service {
s.log = &logger.Logger{Logger: zap.NewNop()} s.log = &logger.Logger{Logger: zap.NewNop()}
} }
s.cache.init() s.cache.init(s.key)
s.closeCh = make(chan struct{}) s.closeCh = make(chan struct{})
s.replicateCh = make(chan movePair, s.replicatorChannelCapacity) s.replicateCh = make(chan movePair, s.replicatorChannelCapacity)
s.replicateLocalCh = make(chan applyOp) s.replicateLocalCh = make(chan applyOp)