vendor: update all dependencies
This commit is contained in:
+35
-15
@@ -19,19 +19,17 @@ package spanner
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"cloud.google.com/go/internal/version"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/api/option"
|
||||
"google.golang.org/api/transport"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/metadata"
|
||||
|
||||
sppb "google.golang.org/genproto/googleapis/spanner/v1"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -43,6 +41,9 @@ const (
|
||||
// apiClientHeader is the name of the metadata header used to indicate client
|
||||
// information.
|
||||
apiClientHeader = "x-goog-api-client"
|
||||
|
||||
// numChannels is the default value for NumChannels of client
|
||||
numChannels = 4
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -55,7 +56,7 @@ const (
|
||||
|
||||
var (
|
||||
validDBPattern = regexp.MustCompile("^projects/[^/]+/instances/[^/]+/databases/[^/]+$")
|
||||
clientUserAgent = fmt.Sprintf("cloudspanner go/%s", runtime.Version())
|
||||
clientUserAgent = fmt.Sprintf("gl-go/%s gccl/%s grpc/%s", version.Go(), version.Repo, grpc.Version)
|
||||
)
|
||||
|
||||
func validDatabaseName(db string) error {
|
||||
@@ -82,6 +83,7 @@ type Client struct {
|
||||
// ClientConfig has configurations for the client.
|
||||
type ClientConfig struct {
|
||||
// NumChannels is the number of GRPC channels.
|
||||
// If zero, numChannels is used.
|
||||
NumChannels int
|
||||
co []option.ClientOption
|
||||
// SessionPoolConfig is the configuration for session pool.
|
||||
@@ -95,12 +97,12 @@ func errDial(ci int, err error) error {
|
||||
return e
|
||||
}
|
||||
|
||||
func contextWithMetadata(ctx context.Context, md metadata.MD) context.Context {
|
||||
existing, ok := metadata.FromContext(ctx)
|
||||
func contextWithOutgoingMetadata(ctx context.Context, md metadata.MD) context.Context {
|
||||
existing, ok := metadata.FromOutgoingContext(ctx)
|
||||
if ok {
|
||||
md = metadata.Join(existing, md)
|
||||
}
|
||||
return metadata.NewContext(ctx, md)
|
||||
return metadata.NewOutgoingContext(ctx, md)
|
||||
}
|
||||
|
||||
// NewClient creates a client to a database. A valid database name has the
|
||||
@@ -121,14 +123,20 @@ func NewClientWithConfig(ctx context.Context, database string, config ClientConf
|
||||
database: database,
|
||||
md: metadata.Pairs(
|
||||
resourcePrefixHeader, database,
|
||||
apiClientHeader, clientUserAgent,
|
||||
"x-goog-api-client", fmt.Sprintf("gl-go/%s gccl/%s grpc/", version.Go(), version.Repo)),
|
||||
apiClientHeader, clientUserAgent),
|
||||
}
|
||||
allOpts := []option.ClientOption{option.WithEndpoint(prodAddr), option.WithScopes(Scope), option.WithUserAgent(clientUserAgent)}
|
||||
allOpts := []option.ClientOption{option.WithEndpoint(prodAddr), option.WithScopes(Scope), option.WithUserAgent(clientUserAgent), option.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(100<<20), grpc.MaxCallRecvMsgSize(100<<20)))}
|
||||
allOpts = append(allOpts, opts...)
|
||||
// Prepare gRPC channels.
|
||||
if config.NumChannels == 0 {
|
||||
config.NumChannels = 4
|
||||
config.NumChannels = numChannels
|
||||
}
|
||||
// Default MaxOpened sessions
|
||||
if config.MaxOpened == 0 {
|
||||
config.MaxOpened = uint64(config.NumChannels * 100)
|
||||
}
|
||||
if config.MaxBurst == 0 {
|
||||
config.MaxBurst = 10
|
||||
}
|
||||
for i := 0; i < config.NumChannels; i++ {
|
||||
conn, err := transport.DialGRPC(ctx, allOpts...)
|
||||
@@ -201,6 +209,15 @@ func (c *Client) ReadOnlyTransaction() *ReadOnlyTransaction {
|
||||
return t
|
||||
}
|
||||
|
||||
type transactionInProgressKey struct{}
|
||||
|
||||
func checkNestedTxn(ctx context.Context) error {
|
||||
if ctx.Value(transactionInProgressKey{}) != nil {
|
||||
return spannerErrorf(codes.FailedPrecondition, "Cloud Spanner does not support nested transactions")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReadWriteTransaction executes a read-write transaction, with retries as
|
||||
// necessary.
|
||||
//
|
||||
@@ -216,7 +233,10 @@ func (c *Client) ReadOnlyTransaction() *ReadOnlyTransaction {
|
||||
// To limit the number of retries, set a deadline on the Context rather than
|
||||
// using a fixed limit on the number of attempts. ReadWriteTransaction will
|
||||
// retry as needed until that deadline is met.
|
||||
func (c *Client) ReadWriteTransaction(ctx context.Context, f func(t *ReadWriteTransaction) error) (time.Time, error) {
|
||||
func (c *Client) ReadWriteTransaction(ctx context.Context, f func(context.Context, *ReadWriteTransaction) error) (time.Time, error) {
|
||||
if err := checkNestedTxn(ctx); err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
var (
|
||||
ts time.Time
|
||||
sh *sessionHandle
|
||||
@@ -292,7 +312,7 @@ func (c *Client) Apply(ctx context.Context, ms []*Mutation, opts ...ApplyOption)
|
||||
opt(ao)
|
||||
}
|
||||
if !ao.atLeastOnce {
|
||||
return c.ReadWriteTransaction(ctx, func(t *ReadWriteTransaction) error {
|
||||
return c.ReadWriteTransaction(ctx, func(ctx context.Context, t *ReadWriteTransaction) error {
|
||||
t.BufferWrite(ms)
|
||||
return nil
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user