@@ -16,7 +16,6 @@ import (
1616 "github.com/PeerDB-io/peerdb/flow/generated/protos"
1717 "github.com/PeerDB-io/peerdb/flow/internal"
1818 "github.com/PeerDB-io/peerdb/flow/pkg/common"
19- mysql_validation "github.com/PeerDB-io/peerdb/flow/pkg/mysql"
2019 "github.com/PeerDB-io/peerdb/flow/shared"
2120 "github.com/PeerDB-io/peerdb/flow/shared/types"
2221)
@@ -188,25 +187,6 @@ func (h *FlowRequestHandler) checkSourcePeerReuse(
188187 return nil
189188 }
190189
191- // beyond other PeerDB mirrors (checked below), the pinned server_id must not be already registered
192- // as a replica on the source DB itself.
193- mysqlConn , mysqlClose , err := connectors .GetAs [* connmysql.MySqlConnector ](ctx , cfg .Env , peer )
194- if err != nil {
195- return NewInternalApiError (fmt .Errorf ("failed to create MySQL connector for source peer %s: %w" , cfg .SourceName , err ))
196- }
197- defer mysqlClose (ctx )
198-
199- if inUse , err := mysql_validation .HasReplicaWithServerId (mysqlConn .Conn (), * mysqlCfg .ServerId ); err != nil {
200- return NewInternalApiError (fmt .Errorf ("failed to check replicas registered on source peer %s: %w" , cfg .SourceName , err ))
201- } else if inUse {
202- return NewFailedPreconditionApiError (
203- fmt .Errorf ("source peer %q pins server_id=%d, which is already in use by a replica registered on the source database" ,
204- cfg .SourceName , * mysqlCfg .ServerId ),
205- NewMirrorErrorInfo (map [string ]string {
206- common .ErrorMetadataOffendingField : "source_name" ,
207- }))
208- }
209-
210190 // CDC flows for this source peer other than the mirror being validated.
211191 // query_string IS NULL filters out QRep flows, which do
212192 // not stream the binlog.
@@ -249,6 +229,25 @@ func (h *FlowRequestHandler) checkSourcePeerReuse(
249229 return NewInternalApiError (fmt .Errorf ("failed to iterate flows while checking peer reuse for %s: %w" , cfg .SourceName , err ))
250230 }
251231
232+ // Beyond other PeerDB mirrors (checked above), the pinned server_id must not be already
233+ // registered as a replica on the source DB itself.
234+ mysqlConn , mysqlClose , err := connectors .GetAs [* connmysql.MySqlConnector ](ctx , cfg .Env , peer )
235+ if err != nil {
236+ return NewInternalApiError (fmt .Errorf ("failed to create MySQL connector for source peer %s: %w" , cfg .SourceName , err ))
237+ }
238+ defer mysqlClose (ctx )
239+
240+ if inUse , err := mysqlConn .HasReplicaWithServerId (ctx , * mysqlCfg .ServerId ); err != nil {
241+ return NewInternalApiError (fmt .Errorf ("failed to check replicas registered on source peer %s: %w" , cfg .SourceName , err ))
242+ } else if inUse {
243+ return NewFailedPreconditionApiError (
244+ fmt .Errorf ("source peer %q pins server_id=%d, which is already in use by a replica registered on the source database" ,
245+ cfg .SourceName , * mysqlCfg .ServerId ),
246+ NewMirrorErrorInfo (map [string ]string {
247+ common .ErrorMetadataOffendingField : "source_name" ,
248+ }))
249+ }
250+
252251 return nil
253252}
254253
0 commit comments