Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: add task created_ts to ghost filename (#10214)

Danny Xu03891616040b
diff --git a/backend/component/ghost/config.go b/backend/component/ghost/config.go
index bdb9a0af02..587793b9fa 100644
--- a/backend/component/ghost/config.go
+++ b/backend/component/ghost/config.go
@@ -202,17 +202,17 @@ func GetUserFlags(flags map[string]string) (*UserFlags, error) {
return f, nil
}
-func getSocketFilename(taskID int, databaseID int, databaseName string, tableName string) string {
- return fmt.Sprintf("/tmp/gh-ost.%v.%v.%v.%v.sock", taskID, databaseID, databaseName, tableName)
+func getSocketFilename(taskID int, taskCreatedTs int64, databaseID int, databaseName, tableName string) string {
+ return fmt.Sprintf("/tmp/gh-ost.%v.%v.%v.%v.%v.sock", taskID, taskCreatedTs, databaseID, databaseName, tableName)
}
// GetPostponeFlagFilename gets the postpone flag filename for gh-ost.
-func GetPostponeFlagFilename(taskID int, databaseID int, databaseName string, tableName string) string {
- return fmt.Sprintf("/tmp/gh-ost.%v.%v.%v.%v.postponeFlag", taskID, databaseID, databaseName, tableName)
+func GetPostponeFlagFilename(taskID int, taskCreatedTs int64, databaseID int, databaseName, tableName string) string {
+ return fmt.Sprintf("/tmp/gh-ost.%v.%v.%v.%v.%v.postponeFlag", taskID, taskCreatedTs, databaseID, databaseName, tableName)
}
// NewMigrationContext is the context for gh-ost migration.
-func NewMigrationContext(taskID int, database *store.DatabaseMessage, dataSource *store.DataSourceMessage, secret string, tableName string, statement string, noop bool, flags map[string]string, serverIDOffset uint) (*base.MigrationContext, error) {
+func NewMigrationContext(taskID int, taskCreatedTs int64, database *store.DatabaseMessage, dataSource *store.DataSourceMessage, secret string, tableName string, statement string, noop bool, flags map[string]string, serverIDOffset uint) (*base.MigrationContext, error) {
password, err := common.Unobfuscate(dataSource.ObfuscatedPassword, secret)
if err != nil {
return nil, errors.Wrapf(err, "failed to get password")
@@ -274,9 +274,9 @@ func NewMigrationContext(taskID int, database *store.DatabaseMessage, dataSource
}
migrationContext.OriginalTableName = parser.GetExplicitTable()
}
- migrationContext.ServeSocketFile = getSocketFilename(taskID, database.UID, database.DatabaseName, tableName)
+ migrationContext.ServeSocketFile = getSocketFilename(taskID, taskCreatedTs, database.UID, database.DatabaseName, tableName)
migrationContext.DropServeSocket = true
- migrationContext.PostponeCutOverFlagFile = GetPostponeFlagFilename(taskID, database.UID, database.DatabaseName, tableName)
+ migrationContext.PostponeCutOverFlagFile = GetPostponeFlagFilename(taskID, taskCreatedTs, database.UID, database.DatabaseName, tableName)
migrationContext.InitiallyDropGhostTable = true
migrationContext.TimestampOldTable = defaultConfig.timestampOldTable
migrationContext.SetHeartbeatIntervalMilliseconds(defaultConfig.heartbeatIntervalMilliseconds)
diff --git a/backend/runner/plancheck/ghost_sync_executor.go b/backend/runner/plancheck/ghost_sync_executor.go
index fc2fa7ba4e..687a447979 100644
--- a/backend/runner/plancheck/ghost_sync_executor.go
+++ b/backend/runner/plancheck/ghost_sync_executor.go
@@ -102,7 +102,7 @@ func (e *GhostSyncExecutor) Run(ctx context.Context, config *storepb.PlanCheckRu
return nil, common.Wrapf(err, common.Internal, "failed to parse table name from statement, statement: %v", statement)
}
- migrationContext, err := ghost.NewMigrationContext(rand.Intn(10000000), database, adminDataSource, e.secret, tableName, renderedStatement, true, config.GhostFlags, 20000000)
+ migrationContext, err := ghost.NewMigrationContext(rand.Intn(10000000), rand.Int63n(10000000), database, adminDataSource, e.secret, tableName, renderedStatement, true, config.GhostFlags, 20000000)
if err != nil {
return nil, common.Wrapf(err, common.Internal, "failed to create migration context")
}
diff --git a/backend/runner/taskrun/schema_update_ghost_cutover_executor.go b/backend/runner/taskrun/schema_update_ghost_cutover_executor.go
index 1e0ce2a28e..8be115a577 100644
--- a/backend/runner/taskrun/schema_update_ghost_cutover_executor.go
+++ b/backend/runner/taskrun/schema_update_ghost_cutover_executor.go
@@ -98,7 +98,7 @@ func (e *SchemaUpdateGhostCutoverExecutor) RunOnce(ctx context.Context, _ contex
return true, nil, common.Wrapf(err, common.Internal, "failed to parse table name from statement, statement: %v", statement)
}
- postponeFilename := ghost.GetPostponeFlagFilename(syncTaskID, database.UID, database.DatabaseName, tableName)
+ postponeFilename := ghost.GetPostponeFlagFilename(syncTaskID, syncTask.CreatedTs, database.UID, database.DatabaseName, tableName)
value, ok := e.stateCfg.GhostTaskState.Load(syncTaskID)
if !ok {
diff --git a/backend/runner/taskrun/schema_update_ghost_sync_executor.go b/backend/runner/taskrun/schema_update_ghost_sync_executor.go
index 045fbabb94..4fa01cbf4f 100644
--- a/backend/runner/taskrun/schema_update_ghost_sync_executor.go
+++ b/backend/runner/taskrun/schema_update_ghost_sync_executor.go
@@ -101,7 +101,7 @@ func (exec *SchemaUpdateGhostSyncExecutor) runGhostMigration(ctx context.Context
// To avoid leaking the rendered statement, the error message should use the original statement and not the rendered statement.
renderedStatement := utils.RenderStatement(statement, materials)
- migrationContext, err := ghost.NewMigrationContext(task.ID, database, adminDataSource, exec.secret, tableName, renderedStatement, false, flags, 10000000)
+ migrationContext, err := ghost.NewMigrationContext(task.ID, task.CreatedTs, database, adminDataSource, exec.secret, tableName, renderedStatement, false, flags, 10000000)
if err != nil {
return true, nil, errors.Wrap(err, "failed to init migrationContext for gh-ost")
}