- MySQL 5.0 supports auto-increment variables for bi-directional replication to avoid auto-increment collisions.
- MySQL 5.0 replicates character sets and time zones.
- 5.0 now replicates stored procedures, triggers and views.
- MySQL 5.1 introduces row-based logging and replication (RBR)
- Dyanmic switching of binary log format between
- 5.1 allows for cluster replication.
- Replication method cannot be configured per table, but since it’s dynamic you can change it from the client before a transaction, etc.
auto_increment_increment you can change starting points and how many you step between. Works with most table types. Works with InnoDB and MyISAM. This is specifically for multi-master setups.
- RBR allows clusters to replicate and also allows the server to replicate non-deterministic statements such as LOAD_FILE(). That being said you can’t have different table definitions on the slave as you can with SBR.
Wow, nothing super impressive here that makes me excited about new features in MySQL’s 5.0/5.1 replication. Their answer to the possible auto_increment collisions seems a bit simplistic and short-sighted, but then again I’m not a maintainer for MySQL’s replication code.
What annoys me greatly is MySQL’s refusal to simply add features to storage engines in favor of simply adding new storage engines. MyISAM doesn’t support transactions or foreign key constraints? Use InnoDB. InnoDB doesn’t support FULLTEXT? Use MyISAM. You need synchronous replication of data? Use NDB, but you need to denormalize and reduce your use of JOIN’s.
It’s enough to make me switch to PostgreSQL.
The second session today is replication for scaling and high availability, which I’m extremely interested in hearing about as we’ve been having problems with race conditions on our current replication setup.
- Replication works with all table types.
- Any “critical” reads must be done on the master as replication is asynchronous.
- Master will rotate binary logs automatically for every 1G of log records.
- You must purge any old, unused logs yourself. See the
PURGE MASTER LOGS command. Using file system commands is not recommended as there are index files that need to be updated.
- Master and slave must be similar hardware as slaves generally do as much work and, sometimes, more work than the master. In other words, don’t skimp on the slave.
- Keep a “spare” slave that you can take down and clone to bring up new slaves.
- Use a load balancer for managing access to slaves.
- There is no raw limit to the number of slaves that a master can host, but each slaves takes up one connection so you’re limited by your max connections on the master.
- You can create “relay” slaves that relay data from the master to slaves sitting below them. Doing this increases replication delays though.
- If a slave will also be a master (see above) you need to enable
- Relying on the
master-* lines in
my.cnf can be problematic over using
CHANGE MASTER SQL statement. The slave rememebers master information.
- Datacenter failover involves the www connecting through a proxy, which then decides who the current writeable master is.
- Should avoid DNS when doing inter-datacenter failover. DNS caching, propagation, etc.
- Using proxy allows instantaneous and complete switching of traffic between masters. Another option is stunnel.
- A connection comes through A and goes directly to that DB server. On B it comes through and is forwarded to A instead of going to B. None of the connections connect directly to either A or B.
- Writes go to only one master at a time. The firewall rules ensures that.
- Both masters should use
skip-slave-start and read-only. Entire setup should come up
read-only at boot. Essentially, make sure they come up in the state they failed in.
- Need to handle “Server is read only” and “Connection refused” in your application when failover is occurring.
- Master<->Master replication is only a problem if you’re writing to both masters at the same time.
- They recommend switching traffic between datacenters manually as it’s difficult to determine when to actually failover and not actually automatically failing over.
- Steps for failing over
- Set current master to read-only
- Wait for writes to flush through. Checking how far behind the other master is up-to-date. A way to do this is by creating a table on the master every second and seeing how long it takes to show up on the slave.
- Remove forward rules with old settings
- Add fowarding rules with new settings
- Remove read-only from new master using
SET GLOBAL read_only
- Make sure to STOP SLAVE on the new master when master fails. When you bring it back up check the data first. If all is well then allow replication on the failed master to catch up from the new master. If not then restore from the new master.
- Reverse the above steps to bring the master back up (usually done during a planned failover later). You’ll remain live against the new master until then.