Skip to content

Commit

Permalink
Fix linter warnings and unhandled errors
Browse files Browse the repository at this point in the history
Signed-off-by: Riley Laine <rlaine@slack-corp.com>
  • Loading branch information
rjlaine committed May 22, 2024
1 parent 496ebe9 commit 0ea874f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
20 changes: 13 additions & 7 deletions go/vt/vtgateproxy/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ func (b *JSONGateResolverBuilder) start() error {

// notify all the resolvers that the targets changed
for _, r := range b.resolvers {
b.update(r)
err = b.update(r)
if err != nil {
log.Errorf("Failed to update resolver: %v", err)
}
}
}
}()
Expand Down Expand Up @@ -327,7 +330,7 @@ func (b *JSONGateResolverBuilder) GetPools() []string {
return pools
}

func (b *JSONGateResolverBuilder) GetTargets(poolType string) []targetHost {
func (b *JSONGateResolverBuilder) getTargets(poolType string) []targetHost {
// Copy the target slice
b.mu.RLock()
targets := []targetHost{}
Expand Down Expand Up @@ -375,10 +378,10 @@ func (s *shuffleSorter) shuffleSort(targets []targetHost, affinityField, affinit
}

// Update the current list of hosts for the given resolver
func (b *JSONGateResolverBuilder) update(r *JSONGateResolver) {
func (b *JSONGateResolverBuilder) update(r *JSONGateResolver) error {
log.V(100).Infof("resolving target %s to %d connections\n", r.target.URL.String(), *numConnections)

targets := b.GetTargets(r.poolType)
targets := b.getTargets(r.poolType)

var addrs []resolver.Address
for _, target := range targets {
Expand All @@ -387,7 +390,7 @@ func (b *JSONGateResolverBuilder) update(r *JSONGateResolver) {

log.V(100).Infof("updated targets for %s to %v", r.target.URL.String(), targets)

r.clientConn.UpdateState(resolver.State{Addresses: addrs})
return r.clientConn.UpdateState(resolver.State{Addresses: addrs})
}

// Build a new Resolver to route to the given target
Expand All @@ -412,7 +415,10 @@ func (b *JSONGateResolverBuilder) Build(target resolver.Target, cc resolver.Clie
poolType: poolType,
}

b.update(r)
err := b.update(r)
if err != nil {
return nil, err
}
b.resolvers = append(b.resolvers, r)

return r, nil
Expand All @@ -424,7 +430,7 @@ func (b *JSONGateResolverBuilder) debugTargets() any {
pools := b.GetPools()
targets := map[string][]targetHost{}
for pool := range b.targets {
targets[pool] = b.GetTargets(pool)
targets[pool] = b.getTargets(pool)
}
return struct {
Pools []string
Expand Down
1 change: 1 addition & 0 deletions go/vt/vtgateproxy/firstready_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (

"google.golang.org/grpc/balancer"
"google.golang.org/grpc/balancer/base"

"vitess.io/vitess/go/vt/log"
)

Expand Down
16 changes: 11 additions & 5 deletions go/vt/vtgateproxy/vtgateproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ import (
querypb "vitess.io/vitess/go/vt/proto/query"
vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/vterrors"

// Imported for flags
_ "vitess.io/vitess/go/vt/vtgate/grpcvtgateconn"

"vitess.io/vitess/go/vt/vtgate/vtgateconn"
)

Expand All @@ -60,7 +63,7 @@ var (

timings = stats.NewTimings("Timings", "proxy timings by operation", "operation")

vtGateProxy *VTGateProxy = &VTGateProxy{
vtGateProxy = &VTGateProxy{
targetConns: map[string]*vtgateconn.VTGateConn{},
mu: sync.RWMutex{},
}
Expand Down Expand Up @@ -113,7 +116,7 @@ func (proxy *VTGateProxy) getConnection(ctx context.Context, target string) (*vt

func (proxy *VTGateProxy) NewSession(ctx context.Context, options *querypb.ExecuteOptions, connectionAttributes map[string]string) (*vtgateconn.VTGateSession, error) {

targetUrl := url.URL{
targetURL := url.URL{
Scheme: "vtgate",
Host: "pool",
}
Expand All @@ -136,9 +139,9 @@ func (proxy *VTGateProxy) NewSession(ctx context.Context, options *querypb.Execu
}
}

targetUrl.RawQuery = values.Encode()
targetURL.RawQuery = values.Encode()

conn, err := proxy.getConnection(ctx, targetUrl.String())
conn, err := proxy.getConnection(ctx, targetURL.String())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -196,7 +199,10 @@ func (proxy *VTGateProxy) StreamExecute(ctx context.Context, session *vtgateconn
if err != nil {
return err
}
callback(qr)
err = callback(qr)
if err != nil {
return err
}
}

return nil
Expand Down

0 comments on commit 0ea874f

Please sign in to comment.