Skip to content

Commit ae76275

Browse files
author
Nam Nguyen
committed
fix: allow run gh-ost when performance_schema off & can custom z name to prevent issue github#1536 - github#1536
1 parent 13502df commit ae76275

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

go/base/context.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ type MigrationContext struct {
260260
AllowSetupMetadataLockInstruments bool
261261
IsOpenMetadataLockInstruments bool
262262

263+
AllowDisabledMetadataLockInstruments bool
264+
CustomZLength int
265+
263266
Log Logger
264267
}
265268

@@ -341,12 +344,12 @@ func (this *MigrationContext) SetConnectionCharset(charset string) {
341344
}
342345

343346
func getSafeTableName(baseName string, suffix string) string {
344-
name := fmt.Sprintf("_%s_%s", baseName, suffix)
347+
name := fmt.Sprintf("%s_%s_%s", getCustomZ(), baseName, suffix)
345348
if len(name) <= mysql.MaxTableNameLength {
346349
return name
347350
}
348351
extraCharacters := len(name) - mysql.MaxTableNameLength
349-
return fmt.Sprintf("_%s_%s", baseName[0:len(baseName)-extraCharacters], suffix)
352+
return fmt.Sprintf("%s_%s_%s", getCustomZ(), baseName[0:len(baseName)-extraCharacters], suffix)
350353
}
351354

352355
// GetGhostTableName generates the name of ghost table, based on original table name

go/base/zname.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package base
2+
3+
import "strings"
4+
5+
var (
6+
CustomZLength int
7+
)
8+
9+
func getCustomZ() string {
10+
return strings.Repeat("z", CustomZLength)
11+
}

go/cmd/gh-ost/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ func main() {
143143
flag.BoolVar(&migrationContext.AllowSetupMetadataLockInstruments, "allow-setup-metadata-lock-instruments", false, "validate rename session hold the MDL of original table before unlock tables in cut-over phase")
144144
flag.IntVar(&migrationContext.BinlogSyncerMaxReconnectAttempts, "binlogsyncer-max-reconnect-attempts", 0, "when master node fails, the maximum number of binlog synchronization attempts to reconnect. 0 is unlimited")
145145

146+
flag.BoolVar(&migrationContext.AllowDisabledMetadataLockInstruments, "allow-disabled-metadata-lock-instruments", false, "allow disabled metadata lock instruments")
147+
flag.IntVar(&migrationContext.CustomZLength, "custom-z-length", 0, "custom z name length")
148+
146149
flag.BoolVar(&migrationContext.IncludeTriggers, "include-triggers", false, "When true, the triggers (if exist) will be created on the new table")
147150
flag.StringVar(&migrationContext.TriggerSuffix, "trigger-suffix", "", "Add a suffix to the trigger name (i.e '_v2'). Requires '--include-triggers'")
148151
flag.BoolVar(&migrationContext.RemoveTriggerSuffix, "remove-trigger-suffix-if-exists", false, "Remove given suffix from name of trigger. Requires '--include-triggers' and '--trigger-suffix'")
@@ -373,6 +376,10 @@ func main() {
373376
migrationContext.Log.Errore(err)
374377
}
375378

379+
if migrationContext.CustomZLength > 0 {
380+
base.CustomZLength = migrationContext.CustomZLength
381+
}
382+
376383
log.Infof("starting gh-ost %+v (git commit: %s)", AppVersion, GitCommit)
377384
acceptSignals(migrationContext)
378385

go/logic/applier.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,24 @@ func (this *Applier) dropTable(tableName string) error {
545545
}
546546

547547
func (this *Applier) StateMetadataLockInstrument() error {
548-
query := `select /*+ MAX_EXECUTION_TIME(300) */ ENABLED, TIMED from performance_schema.setup_instruments WHERE NAME = 'wait/lock/metadata/sql/mdl'`
548+
// Check if performance_schema is enabled first
549+
var performanceSchemaValue string
550+
query := `SHOW VARIABLES LIKE 'performance_schema'`
551+
if err := this.db.QueryRow(query).Scan(new(string), &performanceSchemaValue); err != nil {
552+
return this.migrationContext.Log.Errorf("Unable to determine performance_schema status: %s", err)
553+
}
554+
555+
if !strings.EqualFold(performanceSchemaValue, "ON") {
556+
this.migrationContext.Log.Warningf("performance_schema is disabled (value: %s)", performanceSchemaValue)
557+
if this.migrationContext.AllowDisabledMetadataLockInstruments {
558+
this.migrationContext.Log.Warningf("AllowDisabledMetadataLockInstruments is enabled, proceeding without metadata lock instrumentation")
559+
this.migrationContext.IsOpenMetadataLockInstruments = false
560+
return nil
561+
}
562+
return this.migrationContext.Log.Errorf("performance_schema is disabled. Please enable it or use --allow-disabled-metadata-lock-instruments to proceed without metadata lock checking")
563+
}
564+
565+
query = `select /*+ MAX_EXECUTION_TIME(300) */ ENABLED, TIMED from performance_schema.setup_instruments WHERE NAME = 'wait/lock/metadata/sql/mdl'`
549566
var enabled, timed string
550567
if err := this.db.QueryRow(query).Scan(&enabled, &timed); err != nil {
551568
return this.migrationContext.Log.Errorf("query performance_schema.setup_instruments with name wait/lock/metadata/sql/mdl error: %s", err)

0 commit comments

Comments
 (0)