Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor snapshot flow for slot based snapshotting #974

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions flow/workflows/snapshot_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,27 @@ func (s *SnapshotFlowExecution) cloneTables(
return nil
}

func (s *SnapshotFlowExecution) cloneTablesWithSlot(
ctx workflow.Context,
sessionCtx workflow.Context,
numTablesInParallel int,
) error {
logger := s.logger
slotInfo, err := s.setupReplication(sessionCtx)
if err != nil {
return fmt.Errorf("failed to setup replication: %w", err)
}

logger.Info("cloning tables in parallel: ", numTablesInParallel)
s.cloneTables(ctx, slotInfo, numTablesInParallel)

if err := s.closeSlotKeepAlive(sessionCtx); err != nil {
return fmt.Errorf("failed to close slot keep alive: %w", err)
}

return nil
}

func SnapshotFlowWorkflow(ctx workflow.Context, config *protos.FlowConnectionConfigs) error {
logger := workflow.GetLogger(ctx)

Expand Down Expand Up @@ -271,21 +292,8 @@ func SnapshotFlowWorkflow(ctx workflow.Context, config *protos.FlowConnectionCon
}
defer workflow.CompleteSession(sessionCtx)

slotInfo, err := se.setupReplication(sessionCtx)
if err != nil {
return fmt.Errorf("failed to setup replication: %w", err)
}

if slotInfo == nil {
logger.Info("no slot info returned, skipping qrep workflow")
return nil
}

logger.Info("cloning tables in parallel: ", numTablesInParallel)
se.cloneTables(ctx, slotInfo, numTablesInParallel)

if err := se.closeSlotKeepAlive(sessionCtx); err != nil {
return fmt.Errorf("failed to close slot keep alive: %w", err)
if err := se.cloneTablesWithSlot(ctx, sessionCtx, numTablesInParallel); err != nil {
return fmt.Errorf("failed to clone slots and create replication slot: %w", err)
}

return nil
Expand Down
Loading