Replication Or Galera Cluster
Total Page:16
File Type:pdf, Size:1020Kb
www.fromdual.com MySQL Servers Working as a Team - Replication or Galera Cluster Open Source Data Center Conference, April 26th - 28th, Berlin Jörg Brühe Senior Support Engineer, FromDual GmbH [email protected] CC-BY-SA MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 1 / 42 FromDual GmbH www.fromdual.com Support Consulting remote-DBA Training MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 2 / 42 About Me www.fromdual.com ● Development distributed SQL-DBMS Porting mainframe -> Unix, Interface to archiver tools (ADSM, NetWorker) ● MySQL Build Team Release builds incl. tests, packaging, scripts, ... ● DBA MySQL running a web platform (master-master-replication) ● Support-Engineer (FromDual) Support + Remote-DBA for MySQL / MariaDB / Percona both with and without Galera Cluster MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 3 / 42 Contents www.fromdual.com MySQL Server: Architecture Binlog Replication Galera Cluster Comparison Examples / When (not) to Choose Which MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 4 / 42 General Remarks www.fromdual.com ● Concepts rather than details: ”the forest, not the trees“ ● MySQL 5.6 (established GA version) ● Also valid for Percona and MariaDB ● Not applicable to ”embedded“ MySQL ● Not considered: NDB = ”MySQL Cluster“ MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 5 / 42 www.fromdual.com MySQL Server: Architecture Binlog Replication Galera Cluster Comparison Examples / When (not) to Choose Which MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 6 / 42 Client-Server-DBMS www.fromdual.com App App App Client (application) local or remote Socket, LAN or internet Server is separate process, Server multi-threaded: 1 thread per user session Disk Disk / SSD, local or SAN MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 7 / 42 Inside the Server www.fromdual.com Application / Client Thread Connection mysqld Cache Manager Parser Optimizer User Au- thenticationMySQL ist eine multi-Thread und NICHT eine multi-Prozess Access Control CommandApplikation! Logging Table Open Dispatcher Cache (.frm, fh) Table Manager Query Query Cache Table Definition Cache Module Cache (tbl def.) Handler Interface MyISAM InnoDB Memory NDB PBXT Aria XtraDB Federated-X ... MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 8 / 42 www.fromdual.com MySQL Server: Architecture Binlog Replication Galera Cluster Comparison Examples / When (not) to Choose Which MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 9 / 42 MySQL Teamwork: Replication or Galera Cluster, [email protected],CC-BY-SA Replication April, or Galera2016Cluster, Teamwork: MySQL changes and schema All data Binlog: Layers +Binlog Layers User thread 1 MyISAM User thread 2 ... InnoDB ... - InnoDB: Handler - Table File layer: Interface Handler - … Cache - Query - Privileges - Optimizer - Parser layer: SQL - ... - Recovery - Row Locks - RowAccess www.fromdual.com 10 / 42 Binlog www.fromdual.com ● All data changes executed ● All schema changes executed ● Timestamps ● Essential for Point-in-Time-Recovery ”PITR“ ● Independent of table handler ● Formats ”statement“, ”row“, and ”mixed“ ● Segments of configurable size ● Numbered sequentially MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 11 / 42 www.fromdual.com MySQL Server: Architecture Binlog Replication Galera Cluster Comparison Examples / When (not) to Choose Which MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 12 / 42 MySQL Replication www.fromdual.com ● Applications communicate with ”Master“ ● ”Master“ logs all changes ● ”Slave“ has identical initial state ● Slave fetches all changes from master and applies them locally ● Replication is running asynchronous ● Slave stops replication on difference MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 13 / 42 “ “ Slave: Binlog MySQL Teamwork: Replication or Galera Cluster, [email protected],CC-BY-SA Replication April, or Galera2016Cluster, Teamwork: MySQL log_slave_updates = for forwarding1” log_slave_updates log-bin = FILE”, no or else binlog User thread 1 Slave binlog fetches MyISAM User thread 2 InnoDB ... SQL thread ... IO thread Log Relay “ Master: log-bin = FILE”, or no else binlog Binlog (no master function)(no master User thread 3 MyISAM User thread 1 InnoDB User thread 2 ... www.fromdual.com ... 14 / 42 Typical Usage www.fromdual.com ● ”High Availability“ ● Geographic redundancy ● Support higher read load (= ”read scale-out“) ● Read-only instance(s) e.g. for backup or reports ● Intentional delay is possible ● Filtering (by DB or table) is possible MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 15 / 42 MySQL Teamwork: Replication or Galera Cluster, [email protected],CC-BY-SA Replication April, or Galera2016Cluster, Teamwork: MySQL ● ● Multiple slavesper master are possible ”log_slave_updates =1“ Recommended: ”read-only =1“on slave User thread 1 MyISAM User thread 2 Replication Cascade InnoDB ... ... SQL thread IO thread User thread 1 MyISAM User thread 2 InnoDB ... SQL thread ... IO thread User thread 3 MyISAM User thread 1 www.fromdual.com InnoDB User thread 2 ... 16 ... / 42 Entries in Binlog www.fromdual.com Original: ● Identification by file name and position ● Replication: ”change master to ...“ specifying host, port, user, password, file, position ● See also: ”mysqldump --master-data“ From MySQL 5.6 also: ● GTID = ”Global Transaction ID“ ● Replication: ”change master to ...“ specifying host, port, user, password, ”auto_position = 1“ MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 17 / 42 Binlog MySQL Teamwork: Replication or Galera Cluster, [email protected],CC-BY-SA Replication April, or Galera2016Cluster, Teamwork: MySQL ● Overlapping changes are fatal! User thread 1 Master-Master-Replication MyISAM User thread 2 InnoDB ... SQL thread ... IO thread Log Relay Binlog User thread 3 MyISAM User thread 1 InnoDB User thread 2 ... ... SQL thread www.fromdual.com IO thread Log Relay 18 / 42 Notes about Replication www.fromdual.com ● Master-Master is controversial, be careful! ● Replication increases read throughput, but not/barely write throughput ● Replication causes file IO und network load ● Format ”row“ is more efficient, but less readable ● Multi-threaded replication since MySQL 5.6, multi-master (”multi-source“) coming in MySQL 5.7 ● Big installation: booking.com ● Recommended: datacharmer.blogspot.de (Giuseppe Maxia, August 2015) MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 19 / 42 www.fromdual.com MySQL Server: Architecture Binlog Replication Galera Cluster Comparison Examples / When (not) to Choose Which MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 20 / 42 Replication Weaknesses www.fromdual.com ● Asynchronous ● Asymmetrical ● Only one write node ● Parallel writes may cause breakage ● HA needs failover after node crash ● Each node is SPOF for its slaves, breakdown requires structure change ● Dynamic changes are complicated MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 21 / 42 Better Alternative www.fromdual.com ● Synchronous transfer ● Symmetrical cluster ● Write accesses on all nodes ● Distributed conflict analysis and handling ● HA by continuity after node outage ● Dynamic entry / exit of nodes supported MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 22 / 42 Galera Cluster www.fromdual.com App App App Inclusiding outage detection Load balancing (LB) and redirection for HA Node 1 Node 2 Node 3 wsrep wsrep wsrep “Working Set Replication” Galera replication Dedicated network preferred = = Locale disks, each holding all data “shared nothing” architecture MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 23 / 42 Galera Properties (1) www.fromdual.com + Based on InnoDB (due to transactions and rollback) + Also transfers user definitions, privileges, ... + Quasi-synchronous transfer on commit, check for conflicts, efficient + Symmetrical, HA without server failover, quorum + No loss of transactions + Brings read scale-out, also some write increase + Dynamical entry / exit possible, synchronisation is automated MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 24 / 42 Order of Events www.fromdual.com Graph by Vadim Tkachenko (Percona): http://www.mysqlperformanceblog.com/2012/01/19/ percona-xtradb-cluster-feature-2-multi-master-replication/ MySQL Teamwork: Replication or Galera Cluster, [email protected], 2016 April, CC-BY-SA 25 / 42 Galera Properties (2) www.fromdual.com - MySQL sources need patching (Codership offers binaries, ditto MariaDB and Percona) - Beware of hot spots (rows) - Conflict detection is late, full rollback (Check postponed till commit) - Minimum size is 3 nodes - Synchronisation time for large DB (mysqldump -> xtrabackup or rsync) MySQL Teamwork: Replication or Galera