@@ -4170,94 +4170,6 @@ CREATE TABLE t.test (k INT PRIMARY KEY, v INT);
41704170 }
41714171}
41724172
4173- // Tests that a schema change that is queued behind another schema change
4174- // is executed through the synchronous execution path properly even if it
4175- // gets to run before the first schema change.
4176- func TestSchemaChangeCompletion (t * testing.T ) {
4177- defer leaktest .AfterTest (t )()
4178- defer log .Scope (t ).Close (t )
4179- skip .WithIssue (t , 51796 )
4180- // TODO (lucy): This test needs more complicated schema changer knobs than is
4181- // currently implemented.
4182- params , _ := tests .CreateTestServerParams ()
4183- var notifySchemaChange chan struct {}
4184- var restartSchemaChange chan struct {}
4185- params .Knobs = base.TestingKnobs {
4186- SQLSchemaChanger : & sql.SchemaChangerTestingKnobs {},
4187- }
4188- s , sqlDB , kvDB := serverutils .StartServer (t , params )
4189- ctx := context .Background ()
4190- defer s .Stopper ().Stop (ctx )
4191- codec := s .ApplicationLayer ().Codec ()
4192-
4193- if _ , err := sqlDB .Exec (`
4194- CREATE DATABASE t;
4195- CREATE TABLE t.test (k INT PRIMARY KEY, v INT);
4196- ` ); err != nil {
4197- t .Fatal (err )
4198- }
4199-
4200- // Add some data
4201- const maxValue = 200
4202- if err := sqltestutils .BulkInsertIntoTable (sqlDB , maxValue ); err != nil {
4203- t .Fatal (err )
4204- }
4205- if err := sqltestutils .CheckTableKeyCount (ctx , kvDB , codec , 1 , maxValue ); err != nil {
4206- t .Fatal (err )
4207- }
4208- if err := sqlutils .RunScrub (sqlDB , "t" , "test" ); err != nil {
4209- t .Fatal (err )
4210- }
4211-
4212- // Do not execute the first schema change so that the second schema
4213- // change gets queued up behind it. The second schema change will be
4214- // given the green signal to execute before the first one.
4215- var wg sync.WaitGroup
4216- wg .Add (2 )
4217- notifySchemaChange = make (chan struct {})
4218- restartSchemaChange = make (chan struct {})
4219- restart := restartSchemaChange
4220- go func () {
4221- if _ , err := sqlDB .Exec (`CREATE UNIQUE INDEX foo ON t.test (v)` ); err != nil {
4222- t .Error (err )
4223- }
4224- wg .Done ()
4225- }()
4226-
4227- <- notifySchemaChange
4228-
4229- notifySchemaChange = make (chan struct {})
4230- restartSchemaChange = make (chan struct {})
4231- go func () {
4232- if _ , err := sqlDB .Exec (`CREATE UNIQUE INDEX bar ON t.test (v)` ); err != nil {
4233- t .Error (err )
4234- }
4235- wg .Done ()
4236- }()
4237-
4238- <- notifySchemaChange
4239- // Allow second schema change to execute.
4240- close (restartSchemaChange )
4241-
4242- // Allow first schema change to execute after a bit.
4243- time .Sleep (time .Millisecond )
4244- close (restart )
4245-
4246- // Check that both schema changes have completed.
4247- wg .Wait ()
4248- if err := sqltestutils .CheckTableKeyCount (ctx , kvDB , codec , 3 , maxValue ); err != nil {
4249- t .Fatal (err )
4250- }
4251-
4252- // The notify schema change channel must be nil-ed out, or else
4253- // running scrub will cause it to trigger again on an already closed
4254- // channel when we run another statement.
4255- notifySchemaChange = nil
4256- if err := sqlutils .RunScrub (sqlDB , "t" , "test" ); err != nil {
4257- t .Fatal (err )
4258- }
4259- }
4260-
42614173// Test that a table TRUNCATE leaves the database in the correct state
42624174// for the asynchronous schema changer to eventually execute it.
42634175func TestTruncateInternals (t * testing.T ) {
0 commit comments