Skip to content

Commit c396d6f

Browse files
committed
feat(resync): Add support to update snapshot config (max_parallel_workers, num_tables, rows_per_partition) during resync signal
1 parent 20728e8 commit c396d6f

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

flow/cmd/handler.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ func (h *FlowRequestHandler) FlowStateChange(
423423
ctx context.Context,
424424
req *protos.FlowStateChangeRequest,
425425
) (*protos.FlowStateChangeResponse, APIError) {
426+
// Flow-API
426427
logs := slog.String(string(shared.FlowNameKey), req.FlowJobName)
427428
slog.InfoContext(ctx, "FlowStateChange called", logs, slog.Any("req", req))
428429
if underMaintenance, err := internal.PeerDBMaintenanceModeEnabled(ctx, nil); err != nil {
@@ -505,6 +506,9 @@ func (h *FlowRequestHandler) FlowStateChange(
505506

506507
config.Resync = true
507508
config.DoInitialSnapshot = true
509+
// Override Snapshot Parameters
510+
overrideSnapshotParametersInResync(req, config)
511+
508512
// validate mirror first because once the mirror is dropped, there's no going back
509513
if _, err := h.ValidateCDCMirror(ctx, &protos.CreateCDCFlowRequest{
510514
ConnectionConfigs: config,
@@ -551,6 +555,21 @@ func (h *FlowRequestHandler) FlowStateChange(
551555
return &protos.FlowStateChangeResponse{}, nil
552556
}
553557

558+
func overrideSnapshotParametersInResync(req *protos.FlowStateChangeRequest, configs *protos.FlowConnectionConfigs) {
559+
if req.FlowConfigUpdate != nil && req.FlowConfigUpdate.GetCdcFlowConfigUpdate() != nil {
560+
cdcConfigUpdate := req.FlowConfigUpdate.GetCdcFlowConfigUpdate()
561+
if cdcConfigUpdate.SnapshotMaxParallelWorkers > 0 {
562+
configs.SnapshotMaxParallelWorkers = cdcConfigUpdate.SnapshotMaxParallelWorkers
563+
}
564+
if cdcConfigUpdate.SnapshotNumTablesInParallel > 0 {
565+
configs.SnapshotNumTablesInParallel = cdcConfigUpdate.SnapshotNumTablesInParallel
566+
}
567+
if cdcConfigUpdate.SnapshotNumRowsPerPartition > 0 {
568+
configs.SnapshotNumRowsPerPartition = cdcConfigUpdate.SnapshotNumRowsPerPartition
569+
}
570+
}
571+
}
572+
554573
func (h *FlowRequestHandler) handleCancelWorkflow(ctx context.Context, workflowID, runID string) error {
555574
ctxWithTimeout, cancel := context.WithTimeout(ctx, 2*time.Minute)
556575
defer cancel()

flow/shared/telemetry/activity_logging.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ func LogActivityStartFlowConfigUpdate(ctx context.Context, flowName string, upda
9393
changes = append(changes, fmt.Sprintf("tables removed: %v", removedTables))
9494
}
9595

96+
if update.SnapshotMaxParallelWorkers > 0 {
97+
changes = append(changes, fmt.Sprintf("snapshotMaxParallelWorkers: %v", update.SnapshotMaxParallelWorkers))
98+
}
99+
if update.SnapshotNumTablesInParallel > 0 {
100+
changes = append(changes, fmt.Sprintf("snapshotNumTablesInParallel: %v", update.SnapshotNumTablesInParallel))
101+
}
102+
if update.SnapshotNumRowsPerPartition > 0 {
103+
changes = append(changes, fmt.Sprintf("snapshotNumRowsPerPartition: %v", update.SnapshotNumRowsPerPartition))
104+
}
105+
96106
logActivity(ctx, ActionStartFlowConfigUpdate,
97107
slog.String("flowName", flowName),
98108
slog.String("activityDetails", strings.Join(changes, ", ")))

flow/workflows/cdc_flow.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ func handleFlowSignalStateChange(
192192
// we should ContinueAsNew after the first signal in the selector, but just in case
193193
cfg.Resync = true
194194
cfg.DoInitialSnapshot = true
195+
// This is just for in-memory
196+
// Override Snapshot Parameters if request in State Change request
197+
overrideSnapshotParametersInState(val, state)
195198
state.DropFlowInput = &protos.DropFlowInput{
196199
// to be filled in just before ContinueAsNew
197200
FlowJobName: cfg.FlowJobName,
@@ -206,6 +209,21 @@ func handleFlowSignalStateChange(
206209
}
207210
}
208211

212+
func overrideSnapshotParametersInState(req *protos.FlowStateChangeRequest, state *cdc_state.CDCFlowWorkflowState) {
213+
if req.FlowConfigUpdate != nil && req.FlowConfigUpdate.GetCdcFlowConfigUpdate() != nil {
214+
cdcConfigUpdate := req.FlowConfigUpdate.GetCdcFlowConfigUpdate()
215+
if cdcConfigUpdate.SnapshotMaxParallelWorkers > 0 {
216+
state.SnapshotMaxParallelWorkers = cdcConfigUpdate.SnapshotMaxParallelWorkers
217+
}
218+
if cdcConfigUpdate.SnapshotNumTablesInParallel > 0 {
219+
state.SnapshotNumTablesInParallel = cdcConfigUpdate.SnapshotNumTablesInParallel
220+
}
221+
if cdcConfigUpdate.SnapshotNumRowsPerPartition > 0 {
222+
state.SnapshotNumRowsPerPartition = cdcConfigUpdate.SnapshotNumRowsPerPartition
223+
}
224+
}
225+
}
226+
209227
func processTableAdditions(
210228
ctx workflow.Context,
211229
logger log.Logger,
@@ -494,6 +512,8 @@ func CDCFlowWorkflow(
494512
state.ActiveSignal = model.ResyncSignal
495513
cfg.Resync = true
496514
cfg.DoInitialSnapshot = true
515+
// Update State with snapshot parameters
516+
overrideSnapshotParametersInState(val, state)
497517
resyncCfg := syncStateToConfigProtoInCatalog(ctx, cfg, state)
498518
state.DropFlowInput = &protos.DropFlowInput{
499519
FlowJobName: resyncCfg.FlowJobName,
@@ -627,6 +647,9 @@ func CDCFlowWorkflow(
627647
cfg.TableMappings = originalTableMappings
628648
// this is the only place where we can have a resync during a resync
629649
// so we need to NOT sync the tableMappings to catalog to preserve original names
650+
651+
// We still override the snapshot parameters (when resync with updated values)
652+
overrideSnapshotParametersInState(val, state)
630653
uploadConfigToCatalog(ctx, cfg)
631654
state.DropFlowInput = &protos.DropFlowInput{
632655
FlowJobName: cfg.FlowJobName,
@@ -863,6 +886,7 @@ func CDCFlowWorkflow(
863886
state.ActiveSignal = model.ResyncSignal
864887
cfg.Resync = true
865888
cfg.DoInitialSnapshot = true
889+
overrideSnapshotParametersInState(val, state)
866890
resyncCfg := syncStateToConfigProtoInCatalog(ctx, cfg, state)
867891
state.DropFlowInput = &protos.DropFlowInput{
868892
FlowJobName: resyncCfg.FlowJobName,

0 commit comments

Comments
 (0)