vendor: update all dependencies
This commit is contained in:
+42
-42
@@ -36,8 +36,10 @@ type transactionID []byte
|
||||
type txReadEnv interface {
|
||||
// acquire returns a read-transaction environment that can be used to perform a transactional read.
|
||||
acquire(ctx context.Context) (*sessionHandle, *sppb.TransactionSelector, error)
|
||||
// release should be called at the end of every transactional read to deal with session recycling and read timestamp recording.
|
||||
release(time.Time, error)
|
||||
// sets the transaction's read timestamp
|
||||
setTimestamp(time.Time)
|
||||
// release should be called at the end of every transactional read to deal with session recycling.
|
||||
release(error)
|
||||
}
|
||||
|
||||
// txReadOnly contains methods for doing transactional reads.
|
||||
@@ -52,37 +54,25 @@ func errSessionClosed(sh *sessionHandle) error {
|
||||
"session is already recycled / destroyed: session_id = %q, rpc_client = %v", sh.getID(), sh.getClient())
|
||||
}
|
||||
|
||||
// Read reads multiple rows from the database.
|
||||
//
|
||||
// The provided function is called once in serial for each row read. If the
|
||||
// function returns a non-nil error, Read immediately returns that value.
|
||||
//
|
||||
// If no rows are read, Read will return nil without calling the provided
|
||||
// function.
|
||||
// Read returns a RowIterator for reading multiple rows from the database.
|
||||
func (t *txReadOnly) Read(ctx context.Context, table string, keys KeySet, columns []string) *RowIterator {
|
||||
// ReadUsingIndex will use primary index if an empty index name is provided.
|
||||
return t.ReadUsingIndex(ctx, table, "", keys, columns)
|
||||
}
|
||||
|
||||
// ReadUsingIndex reads multiple rows from the database using an index.
|
||||
// ReadUsingIndex returns a RowIterator for reading multiple rows from the database
|
||||
// using an index.
|
||||
//
|
||||
// Currently, this function can only read columns that are part of the index
|
||||
// key, part of the primary key, or stored in the index due to a STORING clause
|
||||
// in the index definition.
|
||||
//
|
||||
// The provided function is called once in serial for each row read. If the
|
||||
// function returns a non-nil error, ReadUsingIndex immediately returns that
|
||||
// value.
|
||||
//
|
||||
// If no rows are read, ReadUsingIndex will return nil without calling the
|
||||
// provided function.
|
||||
func (t *txReadOnly) ReadUsingIndex(ctx context.Context, table, index string, keys KeySet, columns []string) *RowIterator {
|
||||
var (
|
||||
sh *sessionHandle
|
||||
ts *sppb.TransactionSelector
|
||||
err error
|
||||
)
|
||||
kset, err := keys.proto()
|
||||
kset, err := keys.keySetProto()
|
||||
if err != nil {
|
||||
return &RowIterator{err: err}
|
||||
}
|
||||
@@ -96,7 +86,7 @@ func (t *txReadOnly) ReadUsingIndex(ctx context.Context, table, index string, ke
|
||||
return &RowIterator{err: errSessionClosed(sh)}
|
||||
}
|
||||
return stream(
|
||||
contextWithMetadata(ctx, sh.getMetadata()),
|
||||
contextWithOutgoingMetadata(ctx, sh.getMetadata()),
|
||||
func(ctx context.Context, resumeToken []byte) (streamingReceiver, error) {
|
||||
return client.StreamingRead(ctx,
|
||||
&sppb.ReadRequest{
|
||||
@@ -109,6 +99,7 @@ func (t *txReadOnly) ReadUsingIndex(ctx context.Context, table, index string, ke
|
||||
ResumeToken: resumeToken,
|
||||
})
|
||||
},
|
||||
t.setTimestamp,
|
||||
t.release,
|
||||
)
|
||||
}
|
||||
@@ -121,9 +112,9 @@ func errRowNotFound(table string, key Key) error {
|
||||
// ReadRow reads a single row from the database.
|
||||
//
|
||||
// If no row is present with the given key, then ReadRow returns an error where
|
||||
// IsRowNotFound(err) is true.
|
||||
// spanner.ErrCode(err) is codes.NotFound.
|
||||
func (t *txReadOnly) ReadRow(ctx context.Context, table string, key Key, columns []string) (*Row, error) {
|
||||
iter := t.Read(ctx, table, Keys(key), columns)
|
||||
iter := t.Read(ctx, table, key, columns)
|
||||
defer iter.Stop()
|
||||
row, err := iter.Next()
|
||||
switch err {
|
||||
@@ -136,13 +127,8 @@ func (t *txReadOnly) ReadRow(ctx context.Context, table string, key Key, columns
|
||||
}
|
||||
}
|
||||
|
||||
// Query executes a query against the database.
|
||||
//
|
||||
// The provided function is called once in serial for each row read. If the
|
||||
// function returns a non-nil error, Query immediately returns that value.
|
||||
//
|
||||
// If no rows are read, Query will return nil without calling the provided
|
||||
// function.
|
||||
// Query executes a query against the database. It returns a RowIterator
|
||||
// for retrieving the resulting rows.
|
||||
func (t *txReadOnly) Query(ctx context.Context, statement Statement) *RowIterator {
|
||||
var (
|
||||
sh *sessionHandle
|
||||
@@ -167,11 +153,12 @@ func (t *txReadOnly) Query(ctx context.Context, statement Statement) *RowIterato
|
||||
return &RowIterator{err: err}
|
||||
}
|
||||
return stream(
|
||||
contextWithMetadata(ctx, sh.getMetadata()),
|
||||
contextWithOutgoingMetadata(ctx, sh.getMetadata()),
|
||||
func(ctx context.Context, resumeToken []byte) (streamingReceiver, error) {
|
||||
req.ResumeToken = resumeToken
|
||||
return client.ExecuteStreamingSql(ctx, req)
|
||||
},
|
||||
t.setTimestamp,
|
||||
t.release)
|
||||
}
|
||||
|
||||
@@ -296,7 +283,7 @@ func (t *ReadOnlyTransaction) begin(ctx context.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = runRetryable(contextWithMetadata(ctx, sh.getMetadata()), func(ctx context.Context) error {
|
||||
err = runRetryable(contextWithOutgoingMetadata(ctx, sh.getMetadata()), func(ctx context.Context) error {
|
||||
res, e := sh.getClient().BeginTransaction(ctx, &sppb.BeginTransactionRequest{
|
||||
Session: sh.getID(),
|
||||
Options: &sppb.TransactionOptions{
|
||||
@@ -333,6 +320,9 @@ func (t *ReadOnlyTransaction) begin(ctx context.Context) error {
|
||||
|
||||
// acquire implements txReadEnv.acquire.
|
||||
func (t *ReadOnlyTransaction) acquire(ctx context.Context) (*sessionHandle, *sppb.TransactionSelector, error) {
|
||||
if err := checkNestedTxn(ctx); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if t.singleUse {
|
||||
return t.acquireSingleUse(ctx)
|
||||
}
|
||||
@@ -423,12 +413,17 @@ func (t *ReadOnlyTransaction) acquireMultiUse(ctx context.Context) (*sessionHand
|
||||
}
|
||||
}
|
||||
|
||||
// release implements txReadEnv.release.
|
||||
func (t *ReadOnlyTransaction) release(rts time.Time, err error) {
|
||||
func (t *ReadOnlyTransaction) setTimestamp(ts time.Time) {
|
||||
t.mu.Lock()
|
||||
if t.singleUse && !rts.IsZero() {
|
||||
t.rts = rts
|
||||
defer t.mu.Unlock()
|
||||
if t.rts.IsZero() {
|
||||
t.rts = ts
|
||||
}
|
||||
}
|
||||
|
||||
// release implements txReadEnv.release.
|
||||
func (t *ReadOnlyTransaction) release(err error) {
|
||||
t.mu.Lock()
|
||||
sh := t.sh
|
||||
t.mu.Unlock()
|
||||
if sh != nil { // sh could be nil if t.acquire() fails.
|
||||
@@ -454,10 +449,15 @@ func (t *ReadOnlyTransaction) Close() {
|
||||
}
|
||||
sh := t.sh
|
||||
t.mu.Unlock()
|
||||
if sh == nil {
|
||||
return
|
||||
}
|
||||
// If session handle is already destroyed, this becomes a noop.
|
||||
// If there are still active queries and if the recycled session is reused before they complete, Cloud Spanner will cancel them
|
||||
// on behalf of the new transaction on the session.
|
||||
sh.recycle()
|
||||
if sh != nil {
|
||||
sh.recycle()
|
||||
}
|
||||
}
|
||||
|
||||
// Timestamp returns the timestamp chosen to perform reads and
|
||||
@@ -608,7 +608,7 @@ func (t *ReadWriteTransaction) acquire(ctx context.Context) (*sessionHandle, *sp
|
||||
}
|
||||
|
||||
// release implements txReadEnv.release.
|
||||
func (t *ReadWriteTransaction) release(_ time.Time, err error) {
|
||||
func (t *ReadWriteTransaction) release(err error) {
|
||||
t.mu.Lock()
|
||||
sh := t.sh
|
||||
t.mu.Unlock()
|
||||
@@ -646,7 +646,7 @@ func (t *ReadWriteTransaction) begin(ctx context.Context) error {
|
||||
t.state = txActive
|
||||
return nil
|
||||
}
|
||||
tx, err := beginTransaction(contextWithMetadata(ctx, t.sh.getMetadata()), t.sh.getID(), t.sh.getClient())
|
||||
tx, err := beginTransaction(contextWithOutgoingMetadata(ctx, t.sh.getMetadata()), t.sh.getID(), t.sh.getClient())
|
||||
if err == nil {
|
||||
t.tx = tx
|
||||
t.state = txActive
|
||||
@@ -673,7 +673,7 @@ func (t *ReadWriteTransaction) commit(ctx context.Context) (time.Time, error) {
|
||||
if sid == "" || client == nil {
|
||||
return ts, errSessionClosed(t.sh)
|
||||
}
|
||||
err = runRetryable(contextWithMetadata(ctx, t.sh.getMetadata()), func(ctx context.Context) error {
|
||||
err = runRetryable(contextWithOutgoingMetadata(ctx, t.sh.getMetadata()), func(ctx context.Context) error {
|
||||
var trailer metadata.MD
|
||||
res, e := client.Commit(ctx, &sppb.CommitRequest{
|
||||
Session: sid,
|
||||
@@ -707,7 +707,7 @@ func (t *ReadWriteTransaction) rollback(ctx context.Context) {
|
||||
if sid == "" || client == nil {
|
||||
return
|
||||
}
|
||||
err := runRetryable(contextWithMetadata(ctx, t.sh.getMetadata()), func(ctx context.Context) error {
|
||||
err := runRetryable(contextWithOutgoingMetadata(ctx, t.sh.getMetadata()), func(ctx context.Context) error {
|
||||
_, e := client.Rollback(ctx, &sppb.RollbackRequest{
|
||||
Session: sid,
|
||||
TransactionId: t.tx,
|
||||
@@ -721,12 +721,12 @@ func (t *ReadWriteTransaction) rollback(ctx context.Context) {
|
||||
}
|
||||
|
||||
// runInTransaction executes f under a read-write transaction context.
|
||||
func (t *ReadWriteTransaction) runInTransaction(ctx context.Context, f func(t *ReadWriteTransaction) error) (time.Time, error) {
|
||||
func (t *ReadWriteTransaction) runInTransaction(ctx context.Context, f func(context.Context, *ReadWriteTransaction) error) (time.Time, error) {
|
||||
var (
|
||||
ts time.Time
|
||||
err error
|
||||
)
|
||||
if err = f(t); err == nil {
|
||||
if err = f(context.WithValue(ctx, transactionInProgressKey{}, 1), t); err == nil {
|
||||
// Try to commit if transaction body returns no error.
|
||||
ts, err = t.commit(ctx)
|
||||
}
|
||||
@@ -776,7 +776,7 @@ func (t *writeOnlyTransaction) applyAtLeastOnce(ctx context.Context, ms ...*Muta
|
||||
return e
|
||||
}
|
||||
}
|
||||
res, e := sh.getClient().Commit(contextWithMetadata(ctx, sh.getMetadata()), &sppb.CommitRequest{
|
||||
res, e := sh.getClient().Commit(contextWithOutgoingMetadata(ctx, sh.getMetadata()), &sppb.CommitRequest{
|
||||
Session: sh.getID(),
|
||||
Transaction: &sppb.CommitRequest_SingleUseTransaction{
|
||||
SingleUseTransaction: &sppb.TransactionOptions{
|
||||
|
||||
Reference in New Issue
Block a user