From c5d093cc086e26ab418acc060c51cd25c219218e Mon Sep 17 00:00:00 2001 From: Prudhvi Chaitanya Dhulipalla Date: Fri, 27 Sep 2024 10:00:28 -0700 Subject: [PATCH] Use tablename for metadatalock name as tablename respsects both the mysql table name length and MDL name length limits --- pkg/migration/runner.go | 2 +- pkg/migration/runner_test.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/migration/runner.go b/pkg/migration/runner.go index eebaddc..32d3b4c 100644 --- a/pkg/migration/runner.go +++ b/pkg/migration/runner.go @@ -202,7 +202,7 @@ func (r *Runner) Run(originalCtx context.Context) error { } // Take a metadata lock to prevent other migrations from running concurrently. - r.metadataLock, err = dbconn.NewMetadataLock(ctx, r.dsn(), r.table.QuotedName, r.logger) + r.metadataLock, err = dbconn.NewMetadataLock(ctx, r.dsn(), r.table.TableName, r.logger) if err != nil { return err } diff --git a/pkg/migration/runner_test.go b/pkg/migration/runner_test.go index 12db606..2383158 100644 --- a/pkg/migration/runner_test.go +++ b/pkg/migration/runner_test.go @@ -333,7 +333,7 @@ func TestTableLength(t *testing.T) { assert.NoError(t, err) err = m.Run(context.Background()) assert.Error(t, err) - assert.ErrorContains(t, err, "is too long") + assert.ErrorContains(t, err, "table name must be less than 54 characters") assert.NoError(t, m.Close()) // There is another condition where the error will be in dropping the _old table first @@ -350,7 +350,7 @@ func TestTableLength(t *testing.T) { assert.NoError(t, err) err = m.Run(context.Background()) assert.Error(t, err) - assert.ErrorContains(t, err, "is too long") + assert.ErrorContains(t, err, "table name must be less than 54 characters") assert.NoError(t, m.Close()) } @@ -2763,6 +2763,12 @@ func TestResumeFromCheckpointE2EWithManualSentinel(t *testing.T) { continue // table does not exist yet } if rowCount > 0 { + // Test that it's not possible to acquire metadata lock with name + // as tablename while the migration is running. + lock, err := dbconn.NewMetadataLock(ctx, testutils.DSN(), + tableName, &testLogger{}) + assert.ErrorContains(t, err, "could not acquire metadata lock: resume_checkpoint_e2e_w_sentinel, lock is held by another connection") + assert.Nil(t, lock) break } }