@@ -101,7 +101,7 @@ func updateFlowConfigWithLatestSettings(
101101 cloneCfg := proto .CloneOf (cfg )
102102 cloneCfg .MaxBatchSize = state .SyncFlowOptions .BatchSize
103103 cloneCfg .IdleTimeoutSeconds = state .SyncFlowOptions .IdleTimeoutSeconds
104- cloneCfg .TableMappings = state .SyncFlowOptions .TableMappings
104+ cloneCfg .TableMappingVersion = state .SyncFlowOptions .TableMappingVersion
105105 if state .SnapshotNumRowsPerPartition > 0 {
106106 cloneCfg .SnapshotNumRowsPerPartition = state .SnapshotNumRowsPerPartition
107107 }
@@ -125,7 +125,6 @@ func syncStateToConfigProtoInCatalog(
125125 cfg * protos.FlowConnectionConfigs ,
126126 state * CDCFlowWorkflowState ,
127127) * protos.FlowConnectionConfigs {
128- // TODO: make sure that `cfg` includes table mappings.
129128 cloneCfg := updateFlowConfigWithLatestSettings (cfg , state )
130129 uploadConfigToCatalog (ctx , cloneCfg )
131130 return cloneCfg
@@ -200,6 +199,24 @@ func processCDCFlowConfigUpdate(
200199 }
201200 }
202201
202+ // MIGRATION: Move `tableMapping` to the DB
203+ if len (state .SyncFlowOptions .TableMappings ) > 0 {
204+ migrateCtx := workflow .WithActivityOptions (ctx , workflow.ActivityOptions {
205+ StartToCloseTimeout : 5 * time .Minute ,
206+ })
207+ if err := workflow .ExecuteActivity (
208+ migrateCtx ,
209+ flowable .MigrateTableMappingsToCatalog ,
210+ cfg .FlowJobName ,
211+ state .SyncFlowOptions .TableMappings ,
212+ 1 , //hardcoding version as 1 for migration purposes.
213+ ).Get (migrateCtx , nil ); err != nil {
214+ return fmt .Errorf ("failed to migrate TableMappings: %w" , err )
215+ }
216+ state .SyncFlowOptions .TableMappings = nil
217+ state .SyncFlowOptions .TableMappingVersion = 1
218+ }
219+
203220 syncStateToConfigProtoInCatalog (ctx , cfg , state )
204221 return nil
205222}
@@ -275,7 +292,7 @@ func processTableAdditions(
275292 alterPublicationAddAdditionalTablesFuture := workflow .ExecuteActivity (
276293 alterPublicationAddAdditionalTablesCtx ,
277294 flowable .AddTablesToPublication ,
278- internal . MinimizeFlowConfiguration ( cfg ) , flowConfigUpdate .AdditionalTables )
295+ cfg , flowConfigUpdate .AdditionalTables )
279296
280297 var res * CDCFlowWorkflowResult
281298 var addTablesFlowErr error
@@ -317,7 +334,6 @@ func processTableAdditions(
317334 childAddTablesCDCFlowFuture := workflow .ExecuteChildWorkflow (
318335 childAddTablesCDCFlowCtx ,
319336 CDCFlowWorkflow ,
320- // TODO: `additonalTableCfg` this cannot be minimized in the main branch; but the limitation is minimal.
321337 additionalTablesCfg ,
322338 nil ,
323339 )
@@ -392,7 +408,7 @@ func processTableRemovals(
392408 rawTableCleanupFuture := workflow .ExecuteActivity (
393409 removeTablesCtx ,
394410 flowable .RemoveTablesFromRawTable ,
395- internal . MinimizeFlowConfiguration ( cfg ) , state .FlowConfigUpdate .RemovedTables )
411+ cfg , state .FlowConfigUpdate .RemovedTables )
396412 removeTablesSelector .AddFuture (rawTableCleanupFuture , func (f workflow.Future ) {
397413 if err := f .Get (ctx , nil ); err != nil {
398414 logger .Error ("failed to clean up raw table for removed tables" , slog .Any ("error" , err ))
@@ -404,7 +420,7 @@ func processTableRemovals(
404420 removeTablesFromCatalogFuture := workflow .ExecuteActivity (
405421 removeTablesCtx ,
406422 flowable .RemoveTablesFromCatalog ,
407- internal . MinimizeFlowConfiguration ( cfg ) , state .FlowConfigUpdate .RemovedTables )
423+ cfg , state .FlowConfigUpdate .RemovedTables )
408424 removeTablesSelector .AddFuture (removeTablesFromCatalogFuture , func (f workflow.Future ) {
409425 if err := f .Get (ctx , nil ); err != nil {
410426 logger .Error ("failed to clean up raw table for removed tables" , slog .Any ("error" , err ))
@@ -574,7 +590,7 @@ func CDCFlowWorkflow(
574590
575591 logger .Info ("mirror resumed" , slog .Duration ("after" , time .Since (startTime )))
576592 state .updateStatus (ctx , logger , protos .FlowStatus_STATUS_RUNNING )
577- return state , workflow .NewContinueAsNewError (ctx , CDCFlowWorkflow , internal . MinimizeFlowConfiguration ( cfg ) , state )
593+ return state , workflow .NewContinueAsNewError (ctx , CDCFlowWorkflow , cfg , state )
578594 }
579595
580596 originalRunID := workflow .GetInfo (ctx ).OriginalRunID
@@ -656,7 +672,7 @@ func CDCFlowWorkflow(
656672 // Resync will rely rely on the `cfg.Resync` flag to rename the tables
657673 // during the snapshot process. This is how we're able to also remove the need
658674 // to sync the config back into the DB / not rely on the `state.TableMappings`.
659- setupFlowFuture := workflow .ExecuteChildWorkflow (setupFlowCtx , SetupFlowWorkflow , internal . MinimizeFlowConfiguration ( cfg ) )
675+ setupFlowFuture := workflow .ExecuteChildWorkflow (setupFlowCtx , SetupFlowWorkflow , cfg )
660676
661677 var setupFlowOutput * protos.SetupFlowOutput
662678 var setupFlowError error
@@ -792,7 +808,7 @@ func CDCFlowWorkflow(
792808 logger .Info ("executed setup flow and snapshot flow, start running" )
793809 state .updateStatus (ctx , logger , protos .FlowStatus_STATUS_RUNNING )
794810 }
795- return state , workflow .NewContinueAsNewError (ctx , CDCFlowWorkflow , internal . MinimizeFlowConfiguration ( cfg ) , state )
811+ return state , workflow .NewContinueAsNewError (ctx , CDCFlowWorkflow , cfg , state )
796812 }
797813
798814 var finished bool
@@ -804,7 +820,7 @@ func CDCFlowWorkflow(
804820 RetryPolicy : & temporal.RetryPolicy {MaximumAttempts : 1 },
805821 }))
806822 state .SyncFlowOptions .TableMappings = []* protos.TableMapping {}
807- syncFlowFuture := workflow .ExecuteActivity (syncCtx , flowable .SyncFlow , internal . MinimizeFlowConfiguration ( cfg ) , state .SyncFlowOptions )
823+ syncFlowFuture := workflow .ExecuteActivity (syncCtx , flowable .SyncFlow , cfg , state .SyncFlowOptions )
808824
809825 mainLoopSelector := workflow .NewNamedSelector (ctx , "MainLoop" )
810826 mainLoopSelector .AddReceive (ctx .Done (), func (_ workflow.ReceiveChannel , _ bool ) {
@@ -925,7 +941,7 @@ func CDCFlowWorkflow(
925941 if state .ActiveSignal == model .TerminateSignal || state .ActiveSignal == model .ResyncSignal {
926942 return state , workflow .NewContinueAsNewError (ctx , DropFlowWorkflow , state .DropFlowInput )
927943 }
928- return state , workflow .NewContinueAsNewError (ctx , CDCFlowWorkflow , internal . MinimizeFlowConfiguration ( cfg ) , state )
944+ return state , workflow .NewContinueAsNewError (ctx , CDCFlowWorkflow , cfg , state )
929945 }
930946 }
931947}
0 commit comments