Skip to content

Commit

Permalink
Make sync batch size dynamic (#806)
Browse files Browse the repository at this point in the history
  • Loading branch information
iskakaushik authored Dec 12, 2023
1 parent 36cc29f commit de891b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions flow/shared/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
)

const (
peerFlowTaskQueue = "peer-flow-task-queue"
snapshotFlowTaskQueue = "snapshot-flow-task-queue"
CDCFlowSignalName = "peer-flow-signal"
peerFlowTaskQueue = "peer-flow-task-queue"
snapshotFlowTaskQueue = "snapshot-flow-task-queue"
CDCFlowSignalName = "peer-flow-signal"
CDCBatchSizeSignalName = "cdc-batch-size-signal"
)

const MirrorNameSearchAttribute = "MirrorName"
Expand Down
15 changes: 15 additions & 0 deletions flow/workflows/cdc_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,20 @@ func CDCFlowWorkflowWithConfig(
BatchSize: int32(limits.MaxBatchSize),
}

// add a signal to change the batch size
batchSizeSignalChan := workflow.GetSignalChannel(ctx, shared.CDCBatchSizeSignalName)
batchSizeSelector := workflow.NewSelector(ctx)
batchSizeSelector.AddReceive(batchSizeSignalChan, func(c workflow.ReceiveChannel, more bool) {
var batchSize int32
c.Receive(ctx, &batchSize)
w.logger.Info("received batch size signal: ", batchSize)
syncFlowOptions.BatchSize = batchSize
})
batchSizeSelector.AddDefault(func() {
w.logger.Info("no batch size signal received, batch size remains: ",
syncFlowOptions.BatchSize)
})

currentSyncFlowNum := 0
totalRecordsSynced := 0

Expand Down Expand Up @@ -435,6 +449,7 @@ func CDCFlowWorkflowWithConfig(
}
})
selector.Select(ctx)
batchSizeSelector.Select(ctx)
}

state.TruncateProgress()
Expand Down

0 comments on commit de891b0

Please sign in to comment.