Skip to content

Commit

Permalink
skip holding client connection on wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul2393 committed Sep 4, 2024
1 parent da6b8ce commit fa026aa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 42 deletions.
8 changes: 0 additions & 8 deletions spanner/apiv1/spanner_client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,3 @@ import "google.golang.org/api/option"
func DefaultClientOptions() []option.ClientOption {
return defaultGRPCClientOptions()
}

// Returns the default call options used by the generated Spanner client.
//
// This function is only intended for use by the client library, and may be
// removed at any time without any warning.
func DefaultCallOptions() *CallOptions {
return defaultCallOptions()
}
35 changes: 2 additions & 33 deletions spanner/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ package spanner

import (
"context"
"strings"

vkit "cloud.google.com/go/spanner/apiv1"
"cloud.google.com/go/spanner/apiv1/spannerpb"
"cloud.google.com/go/spanner/internal"
"github.com/googleapis/gax-go/v2"
"google.golang.org/api/option"
gtransport "google.golang.org/api/transport/grpc"
"google.golang.org/grpc"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/status"
Expand All @@ -44,7 +41,6 @@ const metricsTracerKey contextKey = "metricsTracer"
type spannerClient interface {
CallOptions() *vkit.CallOptions
Close() error
setGoogleClientInfo(...string)
Connection() *grpc.ClientConn
CreateSession(context.Context, *spannerpb.CreateSessionRequest, ...gax.CallOption) (*spannerpb.Session, error)
BatchCreateSessions(context.Context, *spannerpb.BatchCreateSessionsRequest, ...gax.CallOption) (*spannerpb.BatchCreateSessionsResponse, error)
Expand All @@ -68,9 +64,6 @@ type spannerClient interface {
// spannerClient interface.
type grpcSpannerClient struct {
raw *vkit.Client
connPool gtransport.ConnPool
client spannerpb.SpannerClient
xGoogHeaders []string
metricsTracerFactory *builtinMetricsTracerFactory
}

Expand All @@ -86,23 +79,8 @@ func newGRPCSpannerClient(ctx context.Context, sc *sessionClient, opts ...option
if err != nil {
return nil, err
}
clientOpts := vkit.DefaultClientOptions()
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
if err != nil {
return nil, err
}
clientInfo := []string{"gccl", internal.Version}
if sc.userAgent != "" {
agentWithVersion := strings.SplitN(sc.userAgent, "/", 2)
if len(agentWithVersion) == 2 {
clientInfo = append(clientInfo, agentWithVersion[0], agentWithVersion[1])
}
}
if sc.callOptions != nil {
raw.CallOptions = mergeCallOptions(raw.CallOptions, sc.callOptions)
}
g := &grpcSpannerClient{raw: raw, metricsTracerFactory: sc.metricsTracerFactory, connPool: connPool, client: spannerpb.NewSpannerClient(connPool)}
g.setGoogleClientInfo(clientInfo...)

g := &grpcSpannerClient{raw: raw, metricsTracerFactory: sc.metricsTracerFactory}
return g, nil
}

Expand All @@ -115,15 +93,6 @@ func (g *grpcSpannerClient) CallOptions() *vkit.CallOptions {
return g.raw.CallOptions
}

func (g *grpcSpannerClient) setGoogleClientInfo(keyval ...string) {
g.raw.SetGoogleClientInfo(keyval...)
kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
kv = append(kv, "gapic", internal.Version, "gax", gax.Version, "grpc", grpc.Version)
g.xGoogHeaders = []string{
"x-goog-api-client", gax.XGoogHeader(kv...),
}
}

func (g *grpcSpannerClient) Close() error {
return g.raw.Close()
}
Expand Down
5 changes: 4 additions & 1 deletion spanner/spannertest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ func makeClient(t *testing.T) (*spanner.Client, *dbadmin.DatabaseAdminClient, *v
client, _, err = spanner.NewMultiEndpointClient(ctx, dbName(), gmeCfg, opts...)
os.Setenv("SPANNER_EMULATOR_HOST", old)
} else {
opts = append(opts, option.WithGRPCConn(conn))
opts = append(opts,
option.WithGRPCDialOption(grpc.WithTransportCredentials(insecure.NewCredentials())),
option.WithoutAuthentication(),
option.WithEndpoint(srv.Addr))
client, err = spanner.NewClient(ctx, dbName(), opts...)
}
if err != nil {
Expand Down

0 comments on commit fa026aa

Please sign in to comment.