Skip to content

DBI-798: Safer check on mirror validation with MySQL sources setting server_id#4564

Merged
pfcoperez merged 5 commits into
mainfrom
DBI-798/connectors/mysql/improved-server-id-check
Jul 13, 2026
Merged

DBI-798: Safer check on mirror validation with MySQL sources setting server_id#4564
pfcoperez merged 5 commits into
mainfrom
DBI-798/connectors/mysql/improved-server-id-check

Conversation

@pfcoperez

Copy link
Copy Markdown
Member

It adds a check on the utilization of the same server_id in the source MySQL server.
This offer an extra layer of protection against collisions with other replication actors.

…server_id

It adds a check on the utilization in the source DB of the server_id.
@pfcoperez
pfcoperez requested a review from a team as a code owner July 10, 2026 18:16
@claude

claude Bot commented Jul 10, 2026

Copy link
Copy Markdown

Code review

Found 1 issue. Checked for bugs and CLAUDE.md compliance.

Bug: nil pointer dereference at flow/cmd/validate_mirror.go:199

mysqlConn.Conn() returns nil at this call site, causing a panic inside HasReplicaWithServerId.

MySqlConnector uses lazy connection initialization. NewMySqlConnector stores conn as nil and never calls connect(). The actual TCP connection is only established on-demand via Execute()/withRetries(), which internally call connect().

Conn() is just c.conn.Load() — a bare atomic load that returns nil until a connection has been established. Since connectors.GetAs only calls the constructor (no queries), Conn() returns nil. HasReplicaWithServerId then calls conn.Execute(SHOW REPLICAS) on nil, which panics.

Suggested fix: Change HasReplicaWithServerId to accept the MySqlConnector (or a context + an interface with Execute) so it goes through the lazy-connect path, or trigger connection establishment before calling Conn().

See: NewMySqlConnector, Conn(), HasReplicaWithServerId

Comment thread flow/cmd/validate_mirror.go Outdated

// 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I followed your suggestion at 19f4325, it not only saves the extra connection cycle but also cleans-up several boundary leaks.

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
3025 2 3023 395
View the top 2 failed test(s) by shortest run time
github.com/PeerDB-io/peerdb/flow/e2e::TestPeerFlowE2ETestSuiteMariaDB_CH
Stack Traces | 0.01s run time
=== RUN   TestPeerFlowE2ETestSuiteMariaDB_CH
=== PAUSE TestPeerFlowE2ETestSuiteMariaDB_CH
=== CONT  TestPeerFlowE2ETestSuiteMariaDB_CH
--- FAIL: TestPeerFlowE2ETestSuiteMariaDB_CH (0.01s)
github.com/PeerDB-io/peerdb/flow/e2e::TestPeerFlowE2ETestSuiteMariaDB_CH/Test_MariaDB_PartialRowEvent
Stack Traces | 40s run time
=== RUN   TestPeerFlowE2ETestSuiteMariaDB_CH/Test_MariaDB_PartialRowEvent
=== PAUSE TestPeerFlowE2ETestSuiteMariaDB_CH/Test_MariaDB_PartialRowEvent
=== CONT  TestPeerFlowE2ETestSuiteMariaDB_CH/Test_MariaDB_PartialRowEvent
2026/07/13 09:44:58 INFO Received AWS credentials from peer for connector: ci x-peerdb-additional-metadata={Operation:FLOW_OPERATION_UNKNOWN}
2026/07/13 09:44:58 INFO Received AWS credentials from peer for connector: clickhouse x-peerdb-additional-metadata={Operation:FLOW_OPERATION_UNKNOWN}
2026/07/13 09:44:58 INFO fetched schema x-peerdb-additional-metadata={Operation:FLOW_OPERATION_UNKNOWN} table=e2e_test_mach_httj25do.test_my_enum
    clickhouse_mysql_test.go:2226: 
        	Error Trace:	.../flow/e2e/mysql.go:130
        	            				.../flow/e2e/clickhouse_mysql_test.go:2226
        	            				.../hostedtoolcache/go/1.26.4.../src/runtime/asm_amd64.s:1771
        	Error:      	Received unexpected error:
        	            	MySQL execute error: readInitialHandshake: io.ReadFull(header) failed. err EOF: connection was bad
        	Test:       	TestPeerFlowE2ETestSuiteMariaDB_CH/Test_MariaDB_PartialRowEvent
2026/07/13 09:45:08 INFO fetched schema x-peerdb-additional-metadata={Operation:FLOW_OPERATION_UNKNOWN} table=e2e_test_mach_w1r8soly.test_extra_ch_cols
--- FAIL: TestPeerFlowE2ETestSuiteMariaDB_CH/Test_MariaDB_PartialRowEvent (39.96s)

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@github-actions

Copy link
Copy Markdown
Contributor

❌ Test Failure

Analysis: The PR's own new test TestValidateCDCMirror_ServerIDPeerReuse fails deterministically across all three MySQL matrix jobs with an "internal server error" RPC response, indicating a real bug in the new server_id validation code rather than a flaky/timing/network issue.
Confidence: 0.94

⚠️ This appears to be a real bug - manual intervention needed

View workflow run

@jgao54

jgao54 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

(pending integrations test fixes)

@claude

claude Bot commented Jul 12, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

…nector `ValidateMirrorSource` method.

This not only saves a connection-disconnection cycle as suggested by the PR comment but also reduces the leaks of concrete connector details in mirror.
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Possible Flaky Test

Analysis: Only the mysql-pos e2e matrix failed (near the 1200s timeout with no captured --- FAIL/panic and a job that hung on teardown) while both mysql-gtid matrices passed on the same commit, pointing to a timing/infra flake rather than a server_id-validation regression that would affect both modes.
Confidence: 0.62

⚠️ Confidence too low (0.62) to retry automatically - manual review recommended

View workflow run

@pfcoperez
pfcoperez merged commit 5db1ce0 into main Jul 13, 2026
20 of 21 checks passed
@pfcoperez
pfcoperez deleted the DBI-798/connectors/mysql/improved-server-id-check branch July 13, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants