Skip to content

tobenna/mariadb-repl-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MariaDB Replication Bug Reproduction

This repo demonstrates how a MariaDB migration that adds a new UUID primary key can silently corrupt replication and eventually trigger:

ERROR 1032: Can't find record in '<table>'

This happens because MariaDB executes DDL as SQL on both master and replica, causing uuid() defaults to generate different PKs on each server.

Setup

Start master + replica:

docker compose up -d

Check replication:

docker exec -it replica mariadb -uroot -proot -e "SHOW SLAVE STATUS\G"

Should show:

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

Reproduce the Issue

Create demo db on the replica

docker exec -it replica mariadb -uroot -proot -e "CREATE DATABASE IF NOT EXISTS demo;"
  1. Run initial migration + seed
DB_HOST=127.0.0.1 DB_PORT=3306 npm run initial:migrate
DB_HOST=127.0.0.1 DB_PORT=3306 npm run seed
  1. Apply the problematic migration
DB_HOST=127.0.0.1 DB_PORT=3306 npm run bad:migrate

This migration:

  • Drops the old PK
  • Adds id with DEFAULT uuid()
  • Makes id the new PK
  • → master + replica now have different UUIDs
  1. Trigger replication failure
DB_HOST=127.0.0.1 DB_PORT=3306 npm run trigger-failure

Verify the Break

docker exec -it replica mariadb -uroot -proot -e "SHOW SLAVE STATUS\G"

Expected:

Last_SQL_Errno: 1032
Last_SQL_Error: ... Can't find record ...
Slave_SQL_Running: No

About

test maria db replication error

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published