@@ -296,7 +296,7 @@ func processTableAdditions(
296296 alterPublicationAddAdditionalTablesFuture := workflow .ExecuteActivity (
297297 alterPublicationAddAdditionalTablesCtx ,
298298 flowable .AddTablesToPublication ,
299- cfg , flowConfigUpdate .AdditionalTables )
299+ internal . MinimizeFlowConfiguration ( cfg ) , flowConfigUpdate .AdditionalTables )
300300
301301 var res * CDCFlowWorkflowResult
302302 var addTablesFlowErr error
@@ -338,6 +338,7 @@ func processTableAdditions(
338338 childAddTablesCDCFlowFuture := workflow .ExecuteChildWorkflow (
339339 childAddTablesCDCFlowCtx ,
340340 CDCFlowWorkflow ,
341+ // TODO: `additonalTableCfg` this cannot be minimized in the main branch; but the limitation is minimal.
341342 additionalTablesCfg ,
342343 nil ,
343344 )
@@ -412,7 +413,7 @@ func processTableRemovals(
412413 rawTableCleanupFuture := workflow .ExecuteActivity (
413414 removeTablesCtx ,
414415 flowable .RemoveTablesFromRawTable ,
415- cfg , state .FlowConfigUpdate .RemovedTables )
416+ internal . MinimizeFlowConfiguration ( cfg ) , state .FlowConfigUpdate .RemovedTables )
416417 removeTablesSelector .AddFuture (rawTableCleanupFuture , func (f workflow.Future ) {
417418 if err := f .Get (ctx , nil ); err != nil {
418419 logger .Error ("failed to clean up raw table for removed tables" , slog .Any ("error" , err ))
@@ -424,7 +425,7 @@ func processTableRemovals(
424425 removeTablesFromCatalogFuture := workflow .ExecuteActivity (
425426 removeTablesCtx ,
426427 flowable .RemoveTablesFromCatalog ,
427- cfg , state .FlowConfigUpdate .RemovedTables )
428+ internal . MinimizeFlowConfiguration ( cfg ) , state .FlowConfigUpdate .RemovedTables )
428429 removeTablesSelector .AddFuture (removeTablesFromCatalogFuture , func (f workflow.Future ) {
429430 if err := f .Get (ctx , nil ); err != nil {
430431 logger .Error ("failed to clean up raw table for removed tables" , slog .Any ("error" , err ))
@@ -594,7 +595,7 @@ func CDCFlowWorkflow(
594595
595596 logger .Info ("mirror resumed" , slog .Duration ("after" , time .Since (startTime )))
596597 state .updateStatus (ctx , logger , protos .FlowStatus_STATUS_RUNNING )
597- return state , workflow .NewContinueAsNewError (ctx , CDCFlowWorkflow , cfg , state )
598+ return state , workflow .NewContinueAsNewError (ctx , CDCFlowWorkflow , internal . MinimizeFlowConfiguration ( cfg ) , state )
598599 }
599600
600601 originalRunID := workflow .GetInfo (ctx ).OriginalRunID
@@ -627,22 +628,6 @@ func CDCFlowWorkflow(
627628 // for safety, rely on the idempotency of SetupFlow instead
628629 // also, no signals are being handled until the loop starts, so no PAUSE/DROP will take here.
629630 if state .CurrentFlowStatus != protos .FlowStatus_STATUS_RUNNING {
630- originalTableMappings := make ([]* protos.TableMapping , 0 , len (cfg .TableMappings ))
631- for _ , tableMapping := range cfg .TableMappings {
632- originalTableMappings = append (originalTableMappings , proto .CloneOf (tableMapping ))
633- }
634- // if resync is true, alter the table name schema mapping to temporarily add
635- // a suffix to the table names.
636- if cfg .Resync {
637- for _ , mapping := range state .SyncFlowOptions .TableMappings {
638- if mapping .Engine != protos .TableEngine_CH_ENGINE_NULL {
639- mapping .DestinationTableIdentifier += "_resync"
640- }
641- }
642- // because we have renamed the tables.
643- cfg .TableMappings = state .SyncFlowOptions .TableMappings
644- }
645-
646631 // start the SetupFlow workflow as a child workflow, and wait for it to complete
647632 // it should return the table schema for the source peer
648633 setupFlowID := GetChildWorkflowID ("setup-flow" , cfg .FlowJobName , originalRunID )
@@ -666,7 +651,6 @@ func CDCFlowWorkflow(
666651 state .ActiveSignal = model .ResyncSignal
667652 cfg .Resync = true
668653 cfg .DoInitialSnapshot = true
669- cfg .TableMappings = originalTableMappings
670654 // this is the only place where we can have a resync during a resync
671655 // so we need to NOT sync the tableMappings to catalog to preserve original names
672656 uploadConfigToCatalog (ctx , cfg )
@@ -690,7 +674,10 @@ func CDCFlowWorkflow(
690674 WaitForCancellation : true ,
691675 }
692676 setupFlowCtx := workflow .WithChildOptions (ctx , childSetupFlowOpts )
693- setupFlowFuture := workflow .ExecuteChildWorkflow (setupFlowCtx , SetupFlowWorkflow , cfg )
677+ // Resync will rely rely on the `cfg.Resync` flag to rename the tables
678+ // during the snapshot process. This is how we're able to also remove the need
679+ // to sync the config back into the DB / not rely on the `state.TableMappings`.
680+ setupFlowFuture := workflow .ExecuteChildWorkflow (setupFlowCtx , SetupFlowWorkflow , internal .MinimizeFlowConfiguration (cfg ))
694681
695682 var setupFlowOutput * protos.SetupFlowOutput
696683 var setupFlowError error
@@ -826,7 +813,7 @@ func CDCFlowWorkflow(
826813 logger .Info ("executed setup flow and snapshot flow, start running" )
827814 state .updateStatus (ctx , logger , protos .FlowStatus_STATUS_RUNNING )
828815 }
829- return state , workflow .NewContinueAsNewError (ctx , CDCFlowWorkflow , cfg , state )
816+ return state , workflow .NewContinueAsNewError (ctx , CDCFlowWorkflow , internal . MinimizeFlowConfiguration ( cfg ) , state )
830817 }
831818
832819 var finished bool
@@ -837,7 +824,8 @@ func CDCFlowWorkflow(
837824 WaitForCancellation : true ,
838825 RetryPolicy : & temporal.RetryPolicy {MaximumAttempts : 1 },
839826 }))
840- syncFlowFuture := workflow .ExecuteActivity (syncCtx , flowable .SyncFlow , cfg , state .SyncFlowOptions )
827+ state .SyncFlowOptions .TableMappings = []* protos.TableMapping {}
828+ syncFlowFuture := workflow .ExecuteActivity (syncCtx , flowable .SyncFlow , internal .MinimizeFlowConfiguration (cfg ), state .SyncFlowOptions )
841829
842830 mainLoopSelector := workflow .NewNamedSelector (ctx , "MainLoop" )
843831 mainLoopSelector .AddReceive (ctx .Done (), func (_ workflow.ReceiveChannel , _ bool ) {
@@ -958,7 +946,7 @@ func CDCFlowWorkflow(
958946 if state .ActiveSignal == model .TerminateSignal || state .ActiveSignal == model .ResyncSignal {
959947 return state , workflow .NewContinueAsNewError (ctx , DropFlowWorkflow , state .DropFlowInput )
960948 }
961- return state , workflow .NewContinueAsNewError (ctx , CDCFlowWorkflow , cfg , state )
949+ return state , workflow .NewContinueAsNewError (ctx , CDCFlowWorkflow , internal . MinimizeFlowConfiguration ( cfg ) , state )
962950 }
963951 }
964952}
0 commit comments