@@ -123,7 +123,7 @@ func updateFlowConfigWithLatestSettings(
123123 cloneCfg := proto .CloneOf (cfg )
124124 cloneCfg .MaxBatchSize = state .SyncFlowOptions .BatchSize
125125 cloneCfg .IdleTimeoutSeconds = state .SyncFlowOptions .IdleTimeoutSeconds
126- cloneCfg .TableMappings = state .SyncFlowOptions .TableMappings
126+ cloneCfg .TableMappingVersion = state .SyncFlowOptions .TableMappingVersion
127127 if state .SnapshotNumRowsPerPartition > 0 {
128128 cloneCfg .SnapshotNumRowsPerPartition = state .SnapshotNumRowsPerPartition
129129 }
@@ -221,6 +221,24 @@ func processCDCFlowConfigUpdate(
221221 }
222222 }
223223
224+ // MIGRATION: Move `tableMapping` to the DB
225+ if len (state .SyncFlowOptions .TableMappings ) > 0 {
226+ migrateCtx := workflow .WithActivityOptions (ctx , workflow.ActivityOptions {
227+ StartToCloseTimeout : 5 * time .Minute ,
228+ })
229+ if err := workflow .ExecuteActivity (
230+ migrateCtx ,
231+ flowable .MigrateTableMappingsToCatalog ,
232+ cfg .FlowJobName ,
233+ state .SyncFlowOptions .TableMappings ,
234+ 1 , //hardcoding version as 1 for migration purposes.
235+ ).Get (migrateCtx , nil ); err != nil {
236+ return fmt .Errorf ("failed to migrate TableMappings: %w" , err )
237+ }
238+ state .SyncFlowOptions .TableMappings = nil
239+ state .SyncFlowOptions .TableMappingVersion = 1
240+ }
241+
224242 syncStateToConfigProtoInCatalog (ctx , cfg , state )
225243 return nil
226244}
@@ -296,7 +314,7 @@ func processTableAdditions(
296314 alterPublicationAddAdditionalTablesFuture := workflow .ExecuteActivity (
297315 alterPublicationAddAdditionalTablesCtx ,
298316 flowable .AddTablesToPublication ,
299- internal . MinimizeFlowConfiguration ( cfg ) , flowConfigUpdate .AdditionalTables )
317+ cfg , flowConfigUpdate .AdditionalTables )
300318
301319 var res * CDCFlowWorkflowResult
302320 var addTablesFlowErr error
@@ -338,7 +356,6 @@ func processTableAdditions(
338356 childAddTablesCDCFlowFuture := workflow .ExecuteChildWorkflow (
339357 childAddTablesCDCFlowCtx ,
340358 CDCFlowWorkflow ,
341- // TODO: `additonalTableCfg` this cannot be minimized in the main branch; but the limitation is minimal.
342359 additionalTablesCfg ,
343360 nil ,
344361 )
@@ -413,7 +430,7 @@ func processTableRemovals(
413430 rawTableCleanupFuture := workflow .ExecuteActivity (
414431 removeTablesCtx ,
415432 flowable .RemoveTablesFromRawTable ,
416- internal . MinimizeFlowConfiguration ( cfg ) , state .FlowConfigUpdate .RemovedTables )
433+ cfg , state .FlowConfigUpdate .RemovedTables )
417434 removeTablesSelector .AddFuture (rawTableCleanupFuture , func (f workflow.Future ) {
418435 if err := f .Get (ctx , nil ); err != nil {
419436 logger .Error ("failed to clean up raw table for removed tables" , slog .Any ("error" , err ))
@@ -425,7 +442,7 @@ func processTableRemovals(
425442 removeTablesFromCatalogFuture := workflow .ExecuteActivity (
426443 removeTablesCtx ,
427444 flowable .RemoveTablesFromCatalog ,
428- internal . MinimizeFlowConfiguration ( cfg ) , state .FlowConfigUpdate .RemovedTables )
445+ cfg , state .FlowConfigUpdate .RemovedTables )
429446 removeTablesSelector .AddFuture (removeTablesFromCatalogFuture , func (f workflow.Future ) {
430447 if err := f .Get (ctx , nil ); err != nil {
431448 logger .Error ("failed to clean up raw table for removed tables" , slog .Any ("error" , err ))
@@ -595,7 +612,7 @@ func CDCFlowWorkflow(
595612
596613 logger .Info ("mirror resumed" , slog .Duration ("after" , time .Since (startTime )))
597614 state .updateStatus (ctx , logger , protos .FlowStatus_STATUS_RUNNING )
598- return state , workflow .NewContinueAsNewError (ctx , CDCFlowWorkflow , internal . MinimizeFlowConfiguration ( cfg ) , state )
615+ return state , workflow .NewContinueAsNewError (ctx , CDCFlowWorkflow , cfg , state )
599616 }
600617
601618 originalRunID := workflow .GetInfo (ctx ).OriginalRunID
@@ -677,7 +694,7 @@ func CDCFlowWorkflow(
677694 // Resync will rely rely on the `cfg.Resync` flag to rename the tables
678695 // during the snapshot process. This is how we're able to also remove the need
679696 // to sync the config back into the DB / not rely on the `state.TableMappings`.
680- setupFlowFuture := workflow .ExecuteChildWorkflow (setupFlowCtx , SetupFlowWorkflow , internal . MinimizeFlowConfiguration ( cfg ) )
697+ setupFlowFuture := workflow .ExecuteChildWorkflow (setupFlowCtx , SetupFlowWorkflow , cfg )
681698
682699 var setupFlowOutput * protos.SetupFlowOutput
683700 var setupFlowError error
@@ -813,7 +830,7 @@ func CDCFlowWorkflow(
813830 logger .Info ("executed setup flow and snapshot flow, start running" )
814831 state .updateStatus (ctx , logger , protos .FlowStatus_STATUS_RUNNING )
815832 }
816- return state , workflow .NewContinueAsNewError (ctx , CDCFlowWorkflow , internal . MinimizeFlowConfiguration ( cfg ) , state )
833+ return state , workflow .NewContinueAsNewError (ctx , CDCFlowWorkflow , cfg , state )
817834 }
818835
819836 var finished bool
@@ -825,7 +842,7 @@ func CDCFlowWorkflow(
825842 RetryPolicy : & temporal.RetryPolicy {MaximumAttempts : 1 },
826843 }))
827844 state .SyncFlowOptions .TableMappings = []* protos.TableMapping {}
828- syncFlowFuture := workflow .ExecuteActivity (syncCtx , flowable .SyncFlow , internal . MinimizeFlowConfiguration ( cfg ) , state .SyncFlowOptions )
845+ syncFlowFuture := workflow .ExecuteActivity (syncCtx , flowable .SyncFlow , cfg , state .SyncFlowOptions )
829846
830847 mainLoopSelector := workflow .NewNamedSelector (ctx , "MainLoop" )
831848 mainLoopSelector .AddReceive (ctx .Done (), func (_ workflow.ReceiveChannel , _ bool ) {
@@ -946,7 +963,7 @@ func CDCFlowWorkflow(
946963 if state .ActiveSignal == model .TerminateSignal || state .ActiveSignal == model .ResyncSignal {
947964 return state , workflow .NewContinueAsNewError (ctx , DropFlowWorkflow , state .DropFlowInput )
948965 }
949- return state , workflow .NewContinueAsNewError (ctx , CDCFlowWorkflow , internal . MinimizeFlowConfiguration ( cfg ) , state )
966+ return state , workflow .NewContinueAsNewError (ctx , CDCFlowWorkflow , cfg , state )
950967 }
951968 }
952969}
0 commit comments