Skip to content

Commit

Permalink
Merge #29648
Browse files Browse the repository at this point in the history
29648: sql: add TestSchemaChangeRetryError r=vivekmenezes a=vivekmenezes

This reproduces the problem seen in #17698. It's gonna take some
work to fix.

Release note: None

Co-authored-by: Vivek Menezes <[email protected]>
  • Loading branch information
craig[bot] and vivekmenezes committed Sep 6, 2018
2 parents 1907546 + 794be46 commit ba240ad
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions pkg/sql/schema_changer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3475,3 +3475,62 @@ func TestCancelSchemaChange(t *testing.T) {
t.Fatalf("read the wrong number of rows: e = %d, v = %d", eCount, count)
}
}

// This test checks that when a transaction containing schema changes
// needs to be retried it gets retried internal to cockroach.
func TestSchemaChangeRetryError(t *testing.T) {
defer leaktest.AfterTest(t)()
const numNodes = 3

params, _ := tests.CreateTestServerParams()

tc := serverutils.StartTestCluster(t, numNodes,
base.TestClusterArgs{
ReplicationMode: base.ReplicationManual,
ServerArgs: params,
})
defer tc.Stopper().Stop(context.TODO())
sqlDB := tc.ServerConn(0)

if _, err := sqlDB.Exec(`
CREATE DATABASE t;
CREATE TABLE t.test (k INT PRIMARY KEY, v INT, pi DECIMAL DEFAULT (DECIMAL '3.14'));
`); err != nil {
t.Fatal(err)
}

// The timestamp of the transaction is initialized.
tx, err := sqlDB.Begin()
if err != nil {
t.Fatal(err)
}

otherSQLDB := tc.ServerConn(1)

// Read schema on another node that picks a later timestamp.
rows, err := otherSQLDB.Query("SELECT * FROM t.test")
if err != nil {
t.Fatal(err)
}
rows.Close()

if _, err := tx.Exec(`
CREATE TABLE t.another (k INT PRIMARY KEY, v INT, pi DECIMAL DEFAULT (DECIMAL '3.14'));
`); err != nil {
t.Fatal(err)
}

if _, err := tx.Exec(`
CREATE UNIQUE INDEX vidx ON t.test (v);
`); err != nil {
t.Fatal(err)
}

// TODO(andreimatei): fix #17698. The transaction should get retried
// without returning this error to the user.
if err := tx.Commit(); !testutils.IsError(err,
`restart transaction: HandledRetryableTxnError: TransactionRetryError: retry txn \(RETRY_SERIALIZABLE\)`,
) {
t.Fatalf("err = %+v", err)
}
}

0 comments on commit ba240ad

Please sign in to comment.