Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion flow/activities/flowable.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ func (a *FlowableActivity) SyncFlow(
syncDone := make(chan struct{})
normRequests := make(chan NormalizeBatchRequest, normalizeBufferSize)

group, groupCtx := errgroup.WithContext(ctx)
cancelCtx, cancelFunc := context.WithCancel(ctx)
defer cancelFunc()
group, groupCtx := errgroup.WithContext(cancelCtx)
group.Go(func() error {
normalizeCtx := internal.WithOperationContext(groupCtx, protos.FlowOperation_FLOW_OPERATION_NORMALIZE)
// returning error signals sync to stop, normalize can recover connections without interrupting sync, so never return error
Expand Down Expand Up @@ -382,6 +384,7 @@ func (a *FlowableActivity) SyncFlow(
logger.Error("failed to sync records", slog.Any("error", syncErr))
syncState.Store(shared.Ptr("cleanup"))
close(syncDone)
cancelFunc()
return errors.Join(syncErr, group.Wait())
} else if syncResponse != nil {
totalRecordsSynced.Add(syncResponse.NumRecordsSynced)
Expand Down
15 changes: 3 additions & 12 deletions flow/activities/flowable_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"google.golang.org/protobuf/proto"

"github.com/PeerDB-io/peerdb/flow/connectors"
connmysql "github.com/PeerDB-io/peerdb/flow/connectors/mysql"
connmetadata "github.com/PeerDB-io/peerdb/flow/connectors/external_metadata"
connpostgres "github.com/PeerDB-io/peerdb/flow/connectors/postgres"
"github.com/PeerDB-io/peerdb/flow/connectors/utils/monitoring"
"github.com/PeerDB-io/peerdb/flow/generated/protos"
Expand Down Expand Up @@ -139,17 +139,8 @@ func syncCore[TPull connectors.CDCPullConnectorCore, TSync connectors.CDCSyncCon
}

lastOffset, err := func() (model.CdcCheckpoint, error) {
if myConn, isMy := any(srcConn).(*connmysql.MySqlConnector); isMy {
return myConn.GetLastOffset(ctx, config.FlowJobName)
} else {
dstConn, err := connectors.GetByNameAs[TSync](ctx, config.Env, a.CatalogPool, config.DestinationName)
if err != nil {
return model.CdcCheckpoint{}, fmt.Errorf("failed to get destination connector: %w", err)
}
defer connectors.CloseConnector(ctx, dstConn)

return dstConn.GetLastOffset(ctx, config.FlowJobName)
}
pgMetadata := connmetadata.NewPostgresMetadataFromCatalog(logger, a.CatalogPool)
Copy link
Member

@serprex serprex Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't work correctly for pg to pg replication where we store metadata on destination peer instead of catalog

I've brought up wanting to change this, but for now you need to check if source & destination are both pg

In most cases you can return GetLastOffset from srcConn which'll usually do what you're doing here. The problem is that originally metadata was managed by destination connector

return pgMetadata.GetLastOffset(ctx, flowName)
}()
if err != nil {
return nil, a.Alerter.LogFlowError(ctx, flowName, err)
Expand Down
Loading