Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spannertest: TransactionSelector type *spannerpb.TransactionSelector_Begin not supported #7414

Closed
jonathanrhodes opened this issue Feb 13, 2023 · 2 comments · Fixed by #7421
Assignees
Labels
api: spanner Issues related to the Spanner API. priority: p2 Moderately-important priority. Fix may not be included in next release.

Comments

@jonathanrhodes
Copy link

Client

Spanner (in-memory spannertest)

Environment

macos laptop

Go Environment

$ go version
go version go1.19.2 darwin/amd64

Code

e.g.

package main

import (
	"context"
	"log"

	"cloud.google.com/go/spanner"
	database "cloud.google.com/go/spanner/admin/database/apiv1"
	databasePb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
	"cloud.google.com/go/spanner/spannertest"
	"google.golang.org/api/option"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

func main() {
	ctx := context.Background()

	check := func(err error) {
		if err != nil {
			log.Fatal(err)
		}
	}

	spannerServer, err := spannertest.NewServer("localhost:0")
	check(err)

	conn, err := grpc.Dial(spannerServer.Addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
	check(err)

	databaseAdminClient, err := database.NewDatabaseAdminClient(context.Background(), option.WithGRPCConn(conn))
	check(err)

	const dbName = "projects/test/instances/test/databases/test"

	op, err := databaseAdminClient.UpdateDatabaseDdl(ctx, &databasePb.UpdateDatabaseDdlRequest{
		Database:   dbName,
		Statements: []string{`CREATE TABLE Test (ID STRING(MAX) NOT NULL) PRIMARY KEY(ID)`},
	})
	check(err)
	check(op.Wait(ctx))

	spannerClient, err := spanner.NewClient(ctx, dbName, option.WithGRPCConn(conn))
	check(err)

	_, err = spannerClient.ReadWriteTransaction(ctx, func(ctx context.Context, tx *spanner.ReadWriteTransaction) error {
		iter := tx.Query(ctx, spanner.NewStatement(`SELECT * FROM Test`))
		defer iter.Stop()
		_, err := iter.Next()
		return err
	})
	check(err)
}

Expected behavior

v1.42.0 and before: the query proceed with the following output:

2023/02/13 12:10:17 spannertest.inmem: Querying: SELECT * FROM Test
2023/02/13 12:10:17 spannertest.inmem: Rollback(session:"ff6cd471" transaction_id:"tx-823061b7413e")
2023/02/13 12:10:17 no more items in iterator

Actual behavior

v1.43.0 and v1.44.0: the query fails with the following error:

2023/02/13 12:11:50 spanner: code = "Unknown", desc = "rpc error: code = Unknown desc = TransactionSelector type *spannerpb.TransactionSelector_Begin not supported"

Screenshots

e.g. A chart showing how messages are slow. Delete if not necessary.

Additional context

I see that spanner v1.43.0 included the following change:

  • spanner: Inline begin transaction for ReadWriteTransactions (#7149) (2ce3606)

Perhaps this is related?

@rahul2393
Copy link
Contributor

Thanks @jonathanrhodes for reporting this, have created a PR to handle this case.

@rahul2393 rahul2393 added priority: p2 Moderately-important priority. Fix may not be included in next release. and removed triage me I really want to be triaged. labels Feb 14, 2023
@jonathanrhodes
Copy link
Author

Thanks for fixing this @rahul2393! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API. priority: p2 Moderately-important priority. Fix may not be included in next release.
Projects
None yet
2 participants