Skip to content

Commit

Permalink
cdc flow: continue as new after state updates (#2420)
Browse files Browse the repository at this point in the history
prevents rewinding state to start of workflow from undoing changes to settings (such as table additions/removals)
  • Loading branch information
serprex authored Jan 9, 2025
1 parent 905c072 commit 48930ad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions flow/e2e/clickhouse/peer_flow_ch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func (s ClickHouseSuite) Test_Addition_Removal() {
return !rows.Next()
})

runID := e2e.EnvGetRunID(s.t, env)
e2e.SignalWorkflow(env, model.CDCDynamicPropertiesSignal, &protos.CDCFlowConfigUpdate{
AdditionalTables: []*protos.TableMapping{
{
Expand All @@ -123,6 +124,8 @@ func (s ClickHouseSuite) Test_Addition_Removal() {
flowStatus := getFlowStatus()
return flowStatus == protos.FlowStatus_STATUS_RUNNING
})
afterAddRunID := e2e.EnvGetRunID(s.t, env)
require.NotEqual(s.t, runID, afterAddRunID)

_, err = s.Conn().Exec(context.Background(), fmt.Sprintf(`
INSERT INTO %s (key) VALUES ('test');
Expand Down Expand Up @@ -163,6 +166,8 @@ func (s ClickHouseSuite) Test_Addition_Removal() {
flowStatus := getFlowStatus()
return flowStatus == protos.FlowStatus_STATUS_RUNNING
})
afterRemoveRunID := e2e.EnvGetRunID(s.t, env)
require.NotEqual(s.t, runID, afterRemoveRunID)

_, err = s.Conn().Exec(context.Background(), fmt.Sprintf(`
INSERT INTO %s (key) VALUES ('test');
Expand Down
7 changes: 7 additions & 0 deletions flow/e2e/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,13 @@ func EnvGetWorkflowState(t *testing.T, env WorkflowRun) peerflow.CDCFlowWorkflow
return state
}

func EnvGetRunID(t *testing.T, env WorkflowRun) string {
t.Helper()
execData, err := env.c.DescribeWorkflowExecution(context.Background(), env.GetID(), "")
require.NoError(t, err)
return execData.WorkflowExecutionInfo.Execution.RunId
}

func EnvGetFlowStatus(t *testing.T, env WorkflowRun) protos.FlowStatus {
t.Helper()
var flowStatus protos.FlowStatus
Expand Down
2 changes: 2 additions & 0 deletions flow/workflows/cdc_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ func CDCFlowWorkflow(

logger.Info(fmt.Sprintf("mirror has been resumed after %s", time.Since(startTime).Round(time.Second)))
state.CurrentFlowStatus = protos.FlowStatus_STATUS_RUNNING
return state, workflow.NewContinueAsNewError(ctx, CDCFlowWorkflow, cfg, state)
}

originalRunID := workflow.GetInfo(ctx).OriginalRunID
Expand Down Expand Up @@ -479,6 +480,7 @@ func CDCFlowWorkflow(
}

state.CurrentFlowStatus = protos.FlowStatus_STATUS_RUNNING
return state, workflow.NewContinueAsNewError(ctx, CDCFlowWorkflow, cfg, state)
}

var finished bool
Expand Down

0 comments on commit 48930ad

Please sign in to comment.