Skip to content
Open
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions flow/cmd/validate_mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import (
"google.golang.org/protobuf/proto"

"github.com/PeerDB-io/peerdb/flow/connectors"
connmysql "github.com/PeerDB-io/peerdb/flow/connectors/mysql"
"github.com/PeerDB-io/peerdb/flow/generated/proto_conversions"
"github.com/PeerDB-io/peerdb/flow/generated/protos"
"github.com/PeerDB-io/peerdb/flow/internal"
"github.com/PeerDB-io/peerdb/flow/pkg/common"
mysql_validation "github.com/PeerDB-io/peerdb/flow/pkg/mysql"
"github.com/PeerDB-io/peerdb/flow/shared"
"github.com/PeerDB-io/peerdb/flow/shared/types"
)
Expand Down Expand Up @@ -186,6 +188,25 @@ func (h *FlowRequestHandler) checkSourcePeerReuse(
return nil
}

// beyond other PeerDB mirrors (checked below), the pinned server_id must not be already registered
// as a replica on the source DB itself.
mysqlConn, mysqlClose, err := connectors.GetAs[*connmysql.MySqlConnector](ctx, cfg.Env, peer)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: can avoid an extra connect/disconnect by moving mysql_validation.HasReplicaWithServerId inside ValidateMirrorSource and pass in an already instantiated conn, although i understand that having this here put server_id validation check together. Your call.

if err != nil {
return NewInternalApiError(fmt.Errorf("failed to create MySQL connector for source peer %s: %w", cfg.SourceName, err))
}
defer mysqlClose(ctx)

if inUse, err := mysql_validation.HasReplicaWithServerId(mysqlConn.Conn(), *mysqlCfg.ServerId); err != nil {
return NewInternalApiError(fmt.Errorf("failed to check replicas registered on source peer %s: %w", cfg.SourceName, err))
} else if inUse {
return NewFailedPreconditionApiError(
fmt.Errorf("source peer %q pins server_id=%d, which is already in use by a replica registered on the source database",
cfg.SourceName, *mysqlCfg.ServerId),
NewMirrorErrorInfo(map[string]string{
common.ErrorMetadataOffendingField: "source_name",
}))
}

// CDC flows for this source peer other than the mirror being validated.
// query_string IS NULL filters out QRep flows, which do
// not stream the binlog.
Expand Down
Loading