Skip to content

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

feat: create/update/convert task ghost flags payload (#9044)

p0ny91e45f050663
diff --git a/backend/api/v1/rollout_service.go b/backend/api/v1/rollout_service.go
index d8cf678a1f..5f9f5f84f1 100644
--- a/backend/api/v1/rollout_service.go
+++ b/backend/api/v1/rollout_service.go
@@ -826,6 +826,27 @@ func (s *RolloutService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePla
continue
}
+ // Flags for gh-ost.
+ if err := func() error {
+ if task.Type != api.TaskDatabaseSchemaUpdateGhostSync {
+ return nil
+ }
+ payload := &api.TaskDatabaseSchemaUpdateGhostSyncPayload{}
+ if err := json.Unmarshal([]byte(task.Payload), payload); err != nil {
+ return status.Errorf(codes.Internal, "failed to unmarshal task payload: %v", err)
+ }
+ oldFlags := payload.Flags
+ newFlags := spec.GetChangeDatabaseConfig().GetGhostFlags()
+ if cmp.Equal(oldFlags, newFlags) {
+ return nil
+ }
+ taskPatch.Flags = &newFlags
+ doUpdate = true
+ return nil
+ }(); err != nil {
+ return nil, errors.Wrapf(err, "failed to maybe update flags for task %d", task.ID)
+ }
+
// EarliestAllowedTs
if spec.EarliestAllowedTime.GetSeconds() != task.EarliestAllowedTs {
seconds := spec.EarliestAllowedTime.GetSeconds()
diff --git a/backend/api/v1/rollout_service_converter.go b/backend/api/v1/rollout_service_converter.go
index a4e7372669..0603be5e3e 100644
--- a/backend/api/v1/rollout_service_converter.go
+++ b/backend/api/v1/rollout_service_converter.go
@@ -126,6 +126,7 @@ func convertToPlanSpecChangeDatabaseConfig(config *storepb.PlanConfig_Spec_Chang
SchemaVersion: c.SchemaVersion,
RollbackEnabled: c.RollbackEnabled,
RollbackDetail: convertToPlanSpecChangeDatabaseConfigRollbackDetail(c.RollbackDetail),
+ GhostFlags: c.GhostFlags,
},
}
}
@@ -253,6 +254,7 @@ func convertPlanSpecChangeDatabaseConfig(config *v1pb.Plan_Spec_ChangeDatabaseCo
Type: storepb.PlanConfig_ChangeDatabaseConfig_Type(c.Type),
SchemaVersion: c.SchemaVersion,
RollbackEnabled: c.RollbackEnabled,
+ GhostFlags: c.GhostFlags,
},
}
}
diff --git a/backend/api/v1/rollout_service_task.go b/backend/api/v1/rollout_service_task.go
index 7ba1408a8f..34316b7d47 100644
--- a/backend/api/v1/rollout_service_task.go
+++ b/backend/api/v1/rollout_service_task.go
@@ -394,6 +394,7 @@ func getTaskCreatesFromChangeDatabaseConfigDatabaseTarget(ctx context.Context, s
SpecID: spec.Id,
SheetID: sheetUID,
SchemaVersion: c.SchemaVersion,
+ Flags: c.GhostFlags,
}
bytesSync, err := json.Marshal(payloadSync)
if err != nil {
diff --git a/backend/legacyapi/task.go b/backend/legacyapi/task.go
index b5f7da18fa..232f088a6a 100644
--- a/backend/legacyapi/task.go
+++ b/backend/legacyapi/task.go
@@ -153,6 +153,8 @@ type TaskDatabaseSchemaUpdateGhostSyncPayload struct {
SheetID int `json:"sheetId,omitempty"`
SchemaVersion string `json:"schemaVersion,omitempty"`
+
+ Flags map[string]string `json:"flags,omitempty"`
// SocketFileName is the socket file that gh-ost listens on.
// The name follows this template,
// `./tmp/gh-ost.{{ISSUE_ID}}.{{TASK_ID}}.{{DATABASE_ID}}.{{DATABASE_NAME}}.{{TABLE_NAME}}.sock`
@@ -299,4 +301,7 @@ type TaskPatch struct {
// When RollbackEnabled is enabled, RollbackSheetID is kept till it's set to the new sheet ID by the runner.
RollbackSheetID *int
RollbackError *string
+
+ // Flags for gh-ost.
+ Flags *map[string]string
}
diff --git a/backend/store/task.go b/backend/store/task.go
index 0033a3f39c..9cd4e23ab3 100644
--- a/backend/store/task.go
+++ b/backend/store/task.go
@@ -3,6 +3,7 @@ package store
import (
"context"
"database/sql"
+ "encoding/json"
"fmt"
"math"
"sort"
@@ -302,8 +303,8 @@ func (s *Store) UpdateTaskV2(ctx context.Context, patch *api.TaskPatch) (*TaskMe
if (patch.SchemaVersion != nil || patch.SheetID != nil) && patch.Payload != nil {
return nil, errors.Errorf("cannot set both sheetID/schemaVersion and payload for TaskPatch")
}
- if (patch.RollbackEnabled != nil || patch.RollbackSQLStatus != nil || patch.RollbackSheetID != nil || patch.RollbackError != nil) && patch.Payload != nil {
- return nil, errors.Errorf("cannot set both rollbackEnabled/rollbackSQLStatus/rollbackSheetID/rollbackError payload for TaskPatch")
+ if (patch.RollbackEnabled != nil || patch.RollbackSQLStatus != nil || patch.RollbackSheetID != nil || patch.RollbackError != nil || patch.Flags != nil) && patch.Payload != nil {
+ return nil, errors.Errorf("cannot set both rollbackEnabled/rollbackSQLStatus/rollbackSheetID/rollbackError/flags payload for TaskPatch")
}
var payloadSet []string
if v := patch.SheetID; v != nil {
@@ -324,6 +325,13 @@ func (s *Store) UpdateTaskV2(ctx context.Context, patch *api.TaskPatch) (*TaskMe
if v := patch.RollbackError; v != nil {
payloadSet, args = append(payloadSet, fmt.Sprintf(`jsonb_build_object('rollbackError', to_jsonb($%d::TEXT))`, len(args)+1)), append(args, *v)
}
+ if v := patch.Flags; v != nil {
+ jsonb, err := json.Marshal(v)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to marshal flags")
+ }
+ payloadSet, args = append(payloadSet, fmt.Sprintf(`jsonb_build_object('flags', $%d::JSONB)`, len(args)+1)), append(args, jsonb)
+ }
if len(payloadSet) != 0 {
set = append(set, fmt.Sprintf(`payload = payload || %s`, strings.Join(payloadSet, "||")))
}