SlideShare une entreprise Scribd logo
1  sur  231
Advanced MySQL
Replication Techniques


Giuseppe Maxia, QA Director, Continuent, Inc



     Facts. And Demos. Possibly fun
about me - Giuseppe Maxia
•   a.k.a. The Data Charmer
•   QA Director at Continuent, Inc
•   Long time hacking with MySQL features
•   Formerly, community manager,db consultant, designer,
    coder.
•   A passion for QA and open source
•   Blogger
• http://datacharmer.blogspot.com
Agenda
•   Replication basics
•   Replication blues
    •   Master switch and failover
    •   Slave lagging
    •   Gotchas
•   Replication power techniques and features
    •   row-based, semi-synch, delayed
    •   Circular, bi-directional
    •   leveraging replication
•   Tools and tips
•   Replication outside the box
    •   seamless failover, parallel, multi-master
DA
AG
  EN           Replication basics



       • Principles
       • How to set up replication
       • Monitoring replication
DA
AG
  EN     Principles
database server

                               a simple web
                                application
                                  scheme

 r/w requests



                  web server




                         clients
                                              6
database server

                             scaling web
                              requests


 r/w requests




                         web servers

                  load balancer


                       clients
                                           7
read/write
  master                               a web
                                     application
                      read/only
                        slaves
                                    scheme with
                                     replication
                    load balancer
R/W


             R/O




                     web servers

              load balancer


                   clients
                                                   8
client                                                         master
                      transaction




                                                  binary log




                            reads
slave
             IO thread




                                      relay log                replication
                                                                concepts
         SQL thread                 reads
                                                                             9
DA
AG
  EN     replication setup
1   SHUT DOWN THE DATABASE SERVER



              Master




                                    11
2   MAKE A BACKUP COPY



        Master




                         12
3           ENABLE THE MASTER



                 Master



           Configuration file
    [mysqld]
    log-bin=mysql-bin
    server-id=1

                                13
4   RESTART THE MASTER



        Master




                         14
5        CREATE REPLICATION USER



                Master



              SQL command
    GRANT REPLICATION SLAVE ON *.*
    to 'slave_user@'10.10.100.%'
    IDENTIFIED BY 'slave_pass';

                                     15
6            INSTALL MySQL on the slave



                Slave 1




Make sure that:
• You're using the same version of MySQL
• You have the same directory structure
• The server is not started yet

                                           16
7   COPY THE MASTER DATA to the slave



             Slave 1




                                        17
8            ENABLE THE SLAVE



               Slave 1



           Configuration file
    [mysqld]
    server-id=2
    relay-log=mysql-relay
    read-only
    # optional:
    log-bin=mysql-bin           18
9   START THE SLAVE SERVER



        Slave 1




                             19
10          INITIALIZE THE SLAVE



               Slave 1



             SQL command
     CHANGE MASTER TO
     MASTER_HOST=master_IP,
     MASTER_PORT=3306,
     MASTER_USER=slave_user,
     MASTER_PASSWORD='slave_pwd';
                                    20
11       START THE SLAVE SERVICE



              Slave 1



             SQL command
     START SLAVE;




                                   21
12          CHECK THE SLAVE



              Slave 1



             SQL command
     SHOW SLAVE STATUS G
     ...
      Slave_IO_Running: Yes
     Slave_SQL_Running: Yes
     ...
                              22
Troubleshooting


• SHOW SLAVE STATUS says
 SLAVE_IO_RUNNING=No
 •   Make sure that the slave host can connect
     to the master

 •   Make sure that master and slave have
     different Server-id

 •   Check the error log of both master and slave
Testing the slave


• Create a table in the master.
• Make sure that the slave has replicated
  the table.
• Insert data in the master
• read that data in the slave
DA
AG
  EN     Monitoring
Sample                       get slave
                               status
monitoring
                                                            slave

                              Running?        No



                                 Yes
        master
                             Get master
                             binlog and
                              position




                            Same or later
                                                   No
                     Yes
                           binlog/position?

       check table
        contents
                                                    alert           26
monitoring replication
master> SHOW MASTER STATUS


slave> SHOW SLAVE STATUS



FULL SCRIPTS:


http://datacharmer.blogspot.com/2011/04/refactored-again-poor-mans-
mysql.html


http://forge.mysql.com/tools/tool.php?id=6
show master status
           File: mysql-bin.000002
       Position: 78045744
   Binlog_Do_DB:
Binlog_Ignore_DB:
show slave status
       Slave_IO_State: Waiting for master to send event
          Master_Host: 127.0.0.1
          Master_User: rsandbox
          Master_Port: 27371
        Connect_Retry: 60
      Master_Log_File: mysql-bin.000002
  Read_Master_Log_Pos: 78045744
       Relay_Log_File: mysql_sandbox27372-relay-bin.000055
        Relay_Log_Pos: 78045889
Relay_Master_Log_File: mysql-bin.000002
     Slave_IO_Running: Yes
    Slave_SQL_Running: Yes
show slave status
...
               Replicate_Do_DB:
           Replicate_Ignore_DB:
            Replicate_Do_Table:
        Replicate_Ignore_Table:
       Replicate_Wild_Do_Table:
 Replicate_Wild_Ignore_Table:
 ...
show slave status
...
                 Last_Errno: 0
                 Last_Error:
               Skip_Counter: 0
        Exec_Master_Log_Pos: 78045744
            Relay_Log_Space: 78046100
...
      Seconds_Behind_Master: 0
...
              Last_IO_Errno: 0
              Last_IO_Error:
             Last_SQL_Errno: 0
             Last_SQL_Error:
DA
AG
  EN              Replication blues



         •   Master switch and failover
         •   Slave lagging
         •   Gotchas
DA
AG
  EN     Master switch and failover
Replacing the               Master
  master                   crashe
                                  s


        Let all slaves
        catch up with
          execution               STOP
                              replication in
                                all slaves



         FIND the most                make it the
        up to date slave               master



          FIND which          run missing
                                                     connect all
       transactions are       transactions
                                                    slaves to the
         missing from           to other
                                                    new master
         other slaves            slaves


                              Stop
                                                                    34
Planned master switch


• Stop accepting writes
• Wait until all slaves have caught up
• Stop replication in all slaves
• Promote a slave to master
• Point all slaves to the new master
Changing a failed master



• Pre-requisite:
• log_bin and log_slave_updates must be
  enabled in all the slaves
• If not, there is more manual labor
Changing a failed master (1)



• Wait until all slaves have caught up
• Identify the most advanced slave
• Make that slave the new master
• ... so far, so good
Changing a failed master (2)
    • For each remaining slave:
    • Find the missing statements
•    Find the LAST statement replicated by the slave

•    Find the same statement in the new master
     binlog (*)

•    get the position of the NEXT statement


    (*) if log_slave_updates was not enabled, you
    need to convert the relay log statements to SQL
    and do the next step manually
Changing a failed master (3)


• For each remaining slave:
• Apply the missing statements
 •   CHANGE MASTER TO
     master_host=”new_master_hostname”,
     master_port=new_master_port,
     master_log_file=”mysql-bin.xxxxxx”,
     master_log_pos=YYYY
Reasons for complexity




• No global transaction ID
What is a global transaction ID


 • A unique identifier of a transaction
 • Unique for the whole cluster, not for each node
 • Generated by the ultimate source (the master)
 • Does not change when the transaction goes
   through an intermediate master
Why should you care



• Failure recovery
• MySQL DOES NOT have it
Defining the problem
                                              Slave 3

 Master          Replication          Slave 2

                                 Slave 1
           Binary log

          Transactions          Relay log         Binary log
             --------
             --------
             --------          Transactions      Transactions
             --------             --------       ========
                                  --------       ========
                                  --------       ========
                                  --------       ========
The master crashes
                                             Slave 3

Master          Replication          Slave 2

                                Slave 1
          Binary log

         Transactions          Relay log         Binary log
            --------
            --------
            --------          Transactions      Transactions
            --------             --------       ========
                                 --------       ========
                                 --------       ========
                                 --------       ========
Where do the slaves
                 stand?
 Slave 1         Slave 2        Slave 3




 Binary log      Binary log     Binary log

Transactions    Transactions   Transactions
========        ========       ========
========        ========       ========
========        ========       ========
========        ========       ========
Slave 3 becomes
                    master
                                  New master


 Slave 1            Slave 2
                                   Binary log

                                  Transactions
                                  ========
 Binary log         Binary log    ========
                                  ========
Transactions       Transactions   ========
========           ========
========           ========
========           ========
========           ========
Need to synch the
        missing transactions
                              New master


 Slave 1        Slave 2
                               Binary log

                              Transactions
                              ========
 Binary log     Binary log    ========
                              ========
Transactions   Transactions   ========
========       ========
========       ========
========       ========
========       ========
Transaction position in
     the new master binlog
                                      New master


 Slave 1            Slave 2
                                       Binary log

                                      Transactions
                                      ========
 Binary log         Binary log        ========
                                      ========
Transactions       Transactions       ========
========           ========
========           ========
========       ?   ========       ?
========           ========
An existing solution


• Google has made a patch to implement global
  transaction IDs
• HOWEVER
• It only works with 5.0
• It doesn't work with row based replication
Hack
ahead!
CREATE TABLE Global_Trans_ID (

   number INT UNSIGNED AUTO_INCREMENT PRIMARY KEY

) ENGINE = MyISAM;



CREATE TABLE Last_Exec_Trans (

   server_id INT UNSIGNED,

   trans_id INT UNSIGNED

) ENGINE = InnoDB;
CREATE PROCEDURE commit_trans ()

BEGIN

  DECLARE trans_id, server_id INT UNSIGNED;

  SET SQL_LOG_BIN = 0;

  INSERT INTO global_trans_id() values ();

  SELECT LAST_INSERT_ID() INTO trans_id,

          @@server_id INTO server_id;

   DELETE FROM global_trans_id where number < trans_Id;

  SET SQL_LOG_BIN = 1;

  INSERT INTO last_exec_trans(server_id, trans_id)

        VALUES (server_id, trans_id);

COMMIT;

END
Hacking
the hack
Simplifying the scheme


• No MyISAM table and LAST_INSERT_ID()
• Use UUID_SHORT() instead
• Replace the InnoDB table with a BlackHole one
Advantages



• 10 times faster
• No additional tables and storage required
Disadvantages



• The master SERVER ID must be < 256
Another solution




• We’ll see that in the second part of the
  talk
DA
AG
  EN     Slave lagging
Slave lagging



• Common causes:
 •   Excess of traffic

 •   Slave restart

 •   Long DDL operations
Slave lagging
                                               transaction
                                                 transaction
                                  MySQL            transaction
                                               transaction
                                                     transaction
                                  DBMS           transaction
                                                       transaction
                                                   transaction
                                                         transaction
                                                     transaction
                                                       transaction
                                                         transaction



                           BINARY LOG




    ns act act tio n
tra csio s ac ctio
      ac ion ion n
      an n s an
    nr tr tra aniton
    tsa a n csio
             nts ct n
          rn a o
         taa scti
               r
        trnsa



             n
             n
         tio
         t
      tra

tra




REPLICATION




                                           MySQL replication
                                          is SINGLE THREAD
             transaction
             transaction




         MySQL
         DBMS
Slave lagging remedies

• row-based replication (helps in some
  cases)
• Expensive query split
• Double apply (dangerous)
• Slave query prefetch (requires external
  app)
• Parallel replication (requires external
  app)
statement-based replication
master> set global binlog_format=‘statement’;
master> insert into test.t1 select count(*) from
  information_schema.columns;
master> show global status like 'opened_tables';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Opened_tables | 41    |
+---------------+-------+
slave> show global status like 'opened_tables';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Opened_tables | 41    |
+---------------+-------+
row-based replication
master> set global binlog_format=‘row’;
master> insert into test.t1 select count(*) from
  information_schema.columns;
master> show global status like 'opened_tables';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Opened_tables | 41    |
+---------------+-------+
slave> show global status like 'opened_tables';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Opened_tables | 17    |
+---------------+-------+
Expensive query split
# instead of this:
insert into t1 select benchmark(10000000, sha('abc'));
Query OK, 1 row affected (4.19 sec)
Records: 1 Duplicates: 0 Warnings: 0



# you may do this
set @result=(select benchmark(10000000, sha('abc')));
Query OK, 0 rows affected (4.19 sec)

insert into t1 values (@result);
Query OK, 1 row affected (0.00 sec)
Expensive query split
# at 471
#110410 8:21:21 server id 1 end_log_pos 518
User_var
SET @`result`:=0/*!*/;
# at 518
#110410 8:21:21 server id 1 end_log_pos 612    Query
thread_id=3     exec_time=0     error_code=0
SET TIMESTAMP=1302448881/*!*/;
insert into t1 values (@result)
Slave query prefetch

• What is it?
 •   a technique that fetches queries from the
     relay logs, and runs them as SELECT
     statements, to warm up the indexes

• How do you do it?
 •   mk-slave-prefetch (http://www.maatkit.org)

 •   Slave readahead http://sourceforge.net/
     projects/slavereadahead/
DA
AG
  EN     Gotchas
Gotchas




• When you thought that you had figured
  out everything ...
Gotchas: LOAD DATA

• LOAD DATA INFILE is replicated as a
  temporary file
• The slave needs three times the size of
  the data:
 •   the relay log

 •   the temporary file

 •   the data itself
Gotchas: default engine




• If you define storage_engine in the
  master, it does not get replicated
Gotchas: binlog format



• In circular replication, and relay slaves
• Changes to binlog_format are not
  propagated
Gotchas: binlog format

  server id: 101       insert into t1
format: statement   values (@@server_id) 101

 server id: 102
  format: row
                                         102

 server id: 103                          102
  format: row
Gotchas: set global not really global




• set global binlog_format=row
• Works for all new connections after the
  change
• It does not work for the event
  scheduler!
Gotchas: triggers and row replication




• In statement based replication, triggers
  are fired both on master and slave
• in row-based replication, triggers are
  fired on master only, and the resulting
  rows are moved to the slave
DA
AG
  EN   Replication power techniques
                and features

         •   row-based
         •   semi-synch
         •   delayed
         •   Circular
         •   bi-directional
         •   Leveraging replication
DA
AG
  EN     row-based replication
row-based replication


• Available in 5.1 and later
• can be changed using “binlog_format”
 •   row

 •   mixed

 •   statement (default)
row-based replication

• DO
 •   when you have expensive queries in the
     master

 •   when you are using non-deterministic
     functions

• DON’T
 •   When you are updating a lot of rows
DA
AG
  EN     semi-synch replication
semi-synchronous
          replication


• Available in 5.5 and higher
• Makes sure that at least one slave has
  copied the data.
• Increases reliability
client
                                       master   transaction
                           1                    with regular
                commit                           replication



                           execute     2

                                                  slave
     returns
4   to client
                         binary log        3



                  5      replication
                                                           81
client                                     transaction
                                       master
                            1                          with semi-
                commit                               synchronous
                                                       replication

                           execute     2

                                                      slave
7    returns
    to client
                         binary log        3

                            sends
                 4       transaction            relay log     5
                           to slave


                        gets
    6             acknowledgement
                                                                  82
semi-synchronous
      replication in practice



• installation:
  •   it’s a plugin.

  •   Actually, two plugins
semi-synch replication install
# in the master
plugin-load=rpl_semi_sync_master=semisync_master.so
rpl_semi_sync_master_enabled=1



# in each slave
plugin-load=rpl_semi_sync_slave=semisync_slave.so
rpl_semi_sync_slave_enabled=1



# restar all servers
semi-synch replication check
# in the master
show variables like 'rpl_semi%';
+------------------------------------+-------+
| Variable_name                      | Value |
+------------------------------------+-------+
| rpl_semi_sync_master_enabled       | ON    |
| rpl_semi_sync_master_timeout       | 10000 |
| rpl_semi_sync_master_trace_level   | 32    |
| rpl_semi_sync_master_wait_no_slave | ON    |
+------------------------------------+-------+
semi-synch replication check
show status like "rpl_semi_%tx";
+-----------------------------+-------+
| variable_name               | value |
+-----------------------------+-------+
| RPL_SEMI_SYNC_MASTER_NO_TX | 0      |
| RPL_SEMI_SYNC_MASTER_YES_TX | 0     |
+-----------------------------+-------+
semi-synch replication test
master> create table t1 ( i int);
Query OK, 0 rows affected (0.01 sec)

master> show status like "rpl_semi_%tx";
+-----------------------------+-------+
| Variable_name               | Value |
+-----------------------------+-------+
| Rpl_semi_sync_master_no_tx | 0      |
| Rpl_semi_sync_master_yes_tx | 1     |
+-----------------------------+-------+
disabling semi-synch
# for each slave

set global rpl_semi_sync_slave_enabled=0;
stop slave io_thread;
start slave io_thread;
disabled semi-synch replication test
master> insert into t1 values (1);
Query OK, 1 row affected (10.00 sec)

master> show status like "rpl_semi_%tx";
+-----------------------------+-------+
| Variable_name               | Value |
+-----------------------------+-------+
| Rpl_semi_sync_master_no_tx | 1      |
| Rpl_semi_sync_master_yes_tx | 1     |
+-----------------------------+-------+
2 rows in set (0.00 sec)
disabled semi-synch replication test
master> insert into t1 values (2);
Query OK, 1 row affected (0.01 sec)

master> show status like "rpl_semi_%tx";
+-----------------------------+-------+
| Variable_name               | Value |
+-----------------------------+-------+
| Rpl_semi_sync_master_no_tx | 2      |
| Rpl_semi_sync_master_yes_tx | 1     |
+-----------------------------+-------+
2 rows in set (0.00 sec)
re-enabling semi-synch
# in one slave

set global rpl_semi_sync_slave_enabled=1;
stop slave io_thread;
start slave io_thread;
reenabled semi-synch replication test
master> insert into t1 values (3);
Query OK, 1 row affected (0.01 sec)

master> show status like "rpl_semi_%tx";
+-----------------------------+-------+
| Variable_name               | Value |
+-----------------------------+-------+
| Rpl_semi_sync_master_no_tx | 2      |
| Rpl_semi_sync_master_yes_tx | 2     |
+-----------------------------+-------+
2 rows in set (0.00 sec)
DA
AG
  EN     delayed replication
delayed replication in practice
STOP SLAVE;
change master to master_delay=60;
START SLAVE;
delayed replication




• DEMO
DA
AG
  EN     Circular replication
Circular
 A
 A      MySQL                           B
        DBMS                   MySQL
                               DBMS     B
                master
                                       master




     MySQL

DD
     DBMS                      MySQL
                               DBMS
                                        C
                                        C
 master
DA
AG
  EN     bi-directional replication
bi-directional replication
bi-directional replication

                 MySQL   MySQL
                 DBMS    DBMS




Los Angeles                              New York




                                 MySQL
        MySQL            MySQL   DBMS
        DBMS             DBMS
                MySQL
                DBMS
DA
AG
  EN     Leveraging replication
Overview of MySQL partitions
Partition pruning
1a - unpartitioned table - SINGLE RECORD



             I
D                          select *
             N             from table_name
A
             D             where colx =
T
             E             120
A
             X
Partition pruning
2a - table partitioned by colx - SINGLE REC
      1-99


    100-199                  select *
                             from table_name
    200-299
                             where colx =
                             120
    300-399

    400-499


    500-599
Partition pruning
1a - unpartitioned table - RANGE



                               select *
              I                from
D
              N                table_name
A                              where colx
              D                between 120
T
              E                and 230
A
              X
Partition pruning
2a - table partitioned by colx - RANGE
      1-99

                                select *
    100-199                     from
                                table_name
    200-299                     where colx
                                between 120
                                and 230
    300-399

    400-499


    500-599
Storage comparison


 engine                       storage
                                (GB)
 innodb (with PK)                  330
 myisam (with PK)                  141
 archive                             13
 innodb partitioned (no PK)        237
 myisam partitioned (no PK)        107
 archive partitioned                 13
Benchmarking results
engine                         6 month range
InnoDB                              4 min 30s
MyISAM                               25.03s
Archive                            22 min 25s
InnoDB partitioned by month           13.19
MyISAM partitioned by year            6.31
MyISAM partitioned by month           4.45
Archive partitioned by year           16.67
Archive partitioned by month          8.97
Partitions limits
 Little concurrency
 Need of using the partitioning column
The ARCHIVE storage engine
Size matters



Innodb




                    Archive
REPLICATION PARTITIONING



      large
       data
ARCHIVE
Replication
                =
let the slave do the dirty work
master
backup


                                               slaves




                            STOP SLAVE

         remove slave
                               perform
           from load
                               backup
            balancer



                                         attach slave
         START          Let slave
                                            to load
         SLAVE          catch up
                                           balancer
master
  make
summary
 tables
                                           slaves




                            STOP SLAVE


           calculate                 remove slave
           summary                     from load
            tables                      balancer


                                     attach slave
                        Let slave
          START SLAVE                   to load
                        catch up
                                       balancer
master
Partitions
for heavy                                   innodb
                                         non partitioned
 statistics


        slave                                       slave



                                                        innodb
              innodb                                 non partitioned
      partitioned by range


                     slave

                                    MyISAM
                             partitioned by range
Simulating         master
  multiple                                 innodb
                                        non partitioned
dimensions
                                                       slave

       slave

                                                         innodb
                                                      non partitioned
           ARCHIVE
     partitioned by range
             (date)
                                         slave
                 slave
                                                         ARCHIVE
                                                   partitioned by range
                                  ARCHIVE                 (location)
                            partitioned by range
                                   (product)
DA
AG
  EN            Tools and tips
       • MySQL Sandbox
        • Replaying binary logs
        • Filtering binary logs
       • Baron Schwartz’s Maatkit
       • Shlomi Noach’s openark kit
       • Facebook’s Online Schema Change
       • Measuring replication speed
       • Detecting if replication is on
DA
AG
  EN     MySQL Sandbox
MySQL Sandbox
     http://mysqlsandbox.net
• Free software (Perl under GPL)
• One (unix) host
• Many database servers
• Single or multiple sandboxes
• Customized scripts to use the servers
• Standard or circular replication
• Installs IN SECONDS
overview

MySQL                     MySQL
server                    server

         DATA DIRECTORY


              PORT


              SOCKET
overview

 MySQL                                MySQL
 server                               server
                     SAME
                     DATA
                  DIRECTORY?
/var/lib/mysql                 /var/lib/mysql




            DATA CORRUPTION
overview

 MySQL                               MySQL
 server                              server

                     SAME
                    PORT or
                    SOCKET?
     3306                          3306


/tmp/mysql.sock               /tmp/mysql.sock

             DOES NOT START
The hard way (1)
the hard way (2)
The easy way
$ make_sandbox 
    /path/to/mysql-5.1.54_linux.tar.gz


# it should work always
The easier way
$ make_sandbox 5.1.54




# Needs some preliminary work
The easiest way
$ sb 5.1.54




# Needs the same preliminary work
MySQL Sandbox
                        VERSION
               MySQL
               server


$SANDBOX_HOME/msb_VERSION/data


                         VERSION


      /tmp/mysql_VERSION.sock
MySQL Sandbox
                       5.1.54
              MySQL
              server


$SANDBOX_HOME/msb_5_1_54/data


                          5154


        /tmp/mysql_5154.sock
MySQL Sandbox
                       5.5.9
              MySQL
              server


$SANDBOX_HOME/msb_5_5_09/data


                         5509


        /tmp/mysql_5509.sock
Single Sandbox
  MySQL        customized scripts
  server


   start
    stop
 restart
  status
   clear
send_kill
     use
Multiple Sandbox
 MySQL         customized scripts
 server


  start_all
   stop_all
restart_all m n1
 status_all s1 n2
  clear_all s2 n3
send_kill_a
       ll
    use_all
Where do you get it


•from CPAN
 sudo cpan MySQL::Sandbox

•from launchpad
 http://launchpad.net/mysql-sandbox
The easy replication way
$ make_replication_sandbox 
    /path/to/mysql-5.1.54_linux.tar.gz


# or, after some preparation


$ make_replication_sandbox 5.1.54
default architecture
                            $HOME




               /sandboxes            opt
                                            expanded
                                             tarballs
                                    mysql



 installed
sandboxes
default architecture
                          $HOME



             /sandboxes            opt



msb_5_0_91
                                  mysql
msb_5_1_48
                                          5.0.91
rsandbox_5_1_48
                                          5.1.45
       master
                                          5.1.48
       node1
                                          5.5.4
       node2
creating a single sanbox
make_sandbox 
   /path/to/mysql-X.X.XX-OS.tar.gz
using a single sanbox
# after
# make_sandbox 
#   /path/to/mysql-X.X.XX-OS.tar.gz

$ cd $SANDBOX_HOME/msb_X_X_XX
$ ./use
creating a single sanbox
   with a specific options file

make_sandbox 
   /path/to/mysql-X.X.XX-OS.tar.gz 
   --my_file=/path/to/my.cnf
easily create a sandbox after the first
                   one
              The long way
$ cd $HOME/opt/mysql   # $SANDBOX_BINARY
$   gunzip -c 
  /path/to/mysql-5.1.34-osx10.5-x86.tar.gz 
   | tar -xf -
$ mv mysql-5.1.34-osx10.5-x86 5.1.34
$ make sandbox 5.1.34
easily create a sandbox after the first
                   one
             The short way
$ make_sandbox 
  path/to/mysql-5.1.34-osx10.5-x86.tar.gz 
  --export_binaries
starting a single sanbox
$ cd $SANDBOX_HOME/msb_X_X_XX
$ ./start
starting a single sanbox
    with temporary options
$ cd $SANDBOX_HOME/msb_X_X_XX
$ ./start --option=value


$ ./restart --option=value


$ ./start --key-buffer=20000000
creating a sandbox with custom port
            and directory
  $ make_sandbox 5.1.34 
     --sandbox_port=7800 
     --sandbox_directory=mickeymouse
creating a sandbox with automatic
           port checking
 $ make_sandbox 5.1.34 --check_port


 # if 5.1.34 is free
 #    port=5134
 #    directory=msb_5_1_34
 # else
 #    port=5135 (or the first free)
 #    directory=msb_5_1_34_a
create a replication sandbox


$ make_replication_sandbox 
  path/to/mysql-5.1.34-osx10.5-x86.tar.gz
create a circular replication sandbox


$ make_replication_sandbox 
  --circular=4 
  path/to/mysql-5.1.34-osx10.5-x86.tar.gz
changing port to an existing sandbox


$ sbtool -o port 
    -s /path/to/source/sandbox 
    --new_port=XXXX
installing the innodb plugin


$ sbtool -o plugin 
    --plugin=innodb 
    -s /path/to/source/sandbox
creating a replication sandbox with
               new base port

$ make_replication_sandbox 
    --replication_directory=newwdir 
    --check_base_port 5.0.79

#   Creates a replication directory under
#   $SANDBOX_HOME/newdir
#   The previous one is preserved.
#   No conflicts happen
DA
AG
  EN     Replaying binary logs
DA
AG
  EN     Filtering binary logs
DA
AG
  EN     Maatkit
maatkit
•   mk-heartbeat Monitor MySQL replication delay.
•   mk-purge-logs Purge binary logs on a master based on purge rules.
•   mk-slave-delay Make a MySQL slave server lag behind its master.
•   mk-slave-find Find and print replication hierarchy tree of MySQL
    slaves.
•   mk-slave-move Move a MySQL slave around in the replication
    hierarchy.
•   mk-slave-prefetch Pipeline relay logs on a MySQL slave to pre-warm
    caches.
•   mk-slave-restart Watch and restart MySQL replication after errors.
•   mk-table-checksum Perform an online replication consistency check,
    or checksum MySQL tables efficiently on one or many servers.
•   mk-table-sync Synchronize MySQL table data efficiently.
•   http://www.maatkit.org/
Facebook Online Schema Change
    DA
  EN
AG
Facebook Online Schema Change



•   Based on one of Shlomi Noach OpenArk utilities
•   Developed in PHP by Facebook


•   http://www.facebook.com/note.php?note_id=430801045932
DA
AG
  EN     OpenArk
openark

•   oak-get-slave-lag: print slave replication lag and
    terminate with respective exit code.

•   oak-online-alter-table: perform a non-blocking ALTER
    TABLE operation.

•   oak-purge-master-logs: purge master logs, depending
    on the state of replicating slaves.

•   oak-show-replication-status: show how far behind are
    replicating slaves on a given master.

•   http://code.openark.org/forge/openark-kit
DA
AG
  EN     Check replication speed
check replication speed


• Write a time to the master
• Retrieve it from the slave
• Compare times
• http://forge.mysql.com/tools/tool.php?
  id=5
DA
AG
  EN     Replication outside the box



       • Seamless failover
       • Parallel replication
       • Multiple source replication
       • Multiple master replication
Advanced MySQL
Replication for the
      masses
Once Upon A
Time, In The Life
 Of A Database
  Consultant ...
The story of a steel
       foundry

• Used MySQL databases to store
  production monitoring data
• Inserted a zillion records per second.
• Slaves often lagged behind
transaction
                                             transaction
                                   MySQL       transaction
                                           transaction
                                                 transaction
                                   DBMS      transaction
                                                   transaction
                                               transaction
                                                     transaction
                                                 transaction
                                                   transaction
                                                     transaction



                            BINARY LOG




    ns act act tio n
tra ansio ns sac ntio
      ac ion ion n
                     ac
    nr tr tra aniton
    tsa a n csio
             nts ct n
          rn a o
         taa scti
               r
        trnsa



             n
             n
         tio
        ct
      tra

tra
REPLICATION
              transaction
              transaction




          MySQL
          DBMS
The story of a shoe
        maker

• Had a successful business, spread to a
  dozen stores.
• Needed to aggregate the data from the
  stores in his headquarters database.
MySQL
   MySQL
                           DBMS     MySQL
   DBMS
                                    DBMS




                            store
store                                store




                   MySQL
                   DBMS




           headquarters
The story of a widgets
        seller
• Had a successful business, designed for one
  server.
• Products were created in several sites.
• Needed to allow insertions from more
  than one master at the time
MySQL   MySQL
 DBMS    DBMS




master   master




 MySQL   MySQL
 DBMS    DBMS




master   master
All these stories tell
         us:

 Nice dream, but
 MySQL can’t do it
Enter Tungsten Replicator
Tungsten Replicator 2.0


• What is it?
http://code.google.com/p/tungsten-replicator
http://code.google.com/p/tungsten-replicator




                 Open Source
http://code.google.com/p/tungsten-replicator




                 Open Source
                 100% GPL v2
What can it do?

• Easy failover
• Multiple masters
• Multiple sources to a single slave
• Parallel replication
• Replicate to Oracle and PostgreSQL database
MySQL to foreign services


                      MySQL setup
                        to run as
                      MySQL master


        Master DB
                             Data is applied to
                              PostgreSQL or
                                   Oracle



                       Bin
                      Logs
           (Binlogs
           enabled)                               Slave DB

© Continuent 2010
From the beginning ...
Fail-over (1)
Fail-over (2)
Fail-over (3)
Fail-over (4)
Fail-over (5)
Fail-over (6)
Fail-over (7)
Fail-over (8)
Failover


• DEMO
master/slave with an attitude
The steel foundry dream
 or parallel replication
             From here ...
The steel foundry dream
 or parallel replication
              To here.
Parallel replication facts

• Sharded by database
• Good choice for slave lag problems
• Bad choice for single database projects
Testing parallel
  replication
db0
                        preparation (1)
 db1                                 sysbench



      db2                             sysbench


       db3                              sysbench


            db4                           sysbench



             db5                            sysbench


                  db6                           sysbench


                   db7                           sysbench



                        db8                        sysbench



                         db9                         sysbench


                                                       sysbench
preparation (2)
before the test (1)
before the test (2)
   SQL thread




  RELAY logs

                    IO thread



                                          binary logs

MySQL slave

                   RELAY logs

  Tungsten slave           direct:
                            alpha
                           (slave)

                       replicator alpha
starting the test
   SQL thread




  RELAY logs

                    IO thread



                                         binary logs

MySQL slave

                   RELAY logs

  Tungsten slave          direct:
                           alpha
                          (slave)

                      replicator alpha
MySQL native
      replication


slave catch up in 00:02:30
Tungsten parallel
       replication


slave catch up in 00:01:20
The widget seller
dream, or multi masters

• Tungsten Replicator recipe: use more
  services
Bi-directional replication
Bi-directional replication with slaves
True multiple master



 We’ll see that in a moment.
           But first
The shoe maker dream,
 or multiple sources

• Tungsten Replicator recipe is still valid: use
  more services
Multiple source replication
Multiple masters replication: 3 nodes
Multiple masters replication: 4 nodes
Updating 4 masters : 1 flow
Updating 4 masters : 2 flows
Updating 4 masters : 3 flows
Updating 4 masters : 4 flows
Tungsten in practice


• installation
Installation:
         the long way
• Get the binaries
• Expand the tarball
• Check the requirements in the manual
• Run ./configure
• Run ./configure-service
Installation:
         the quick way

• Get the tarball
• Get the tungsten deployer from Google
  Code
• Sit back and enjoy!
Tools

• replicator
• trepctl
• thl
replicator

• It’s the service provider
• You launch it once when you start
• You may restart it when you change config
trepctl

• Tungsten Replicator ConTroLler
• It’s the driving seat for your replication
• You can start, update, and stop services
• You can get specific info
thl


• Transaction History List
• Gives you access to the Tungsten relay logs
DA
AG
  EN     More info on replication
Books
High Performance MySQL
MySQL High Availability
Web Operations
Cloud Application Architectures
Talks
•   Monday, 1:30pm “Learn how to cure replication
    deprivation with Tungsten”

•   Tuesday 10:50am “Replication Update”

•   Tuesday 2:00pm “Diagnosing replication failures”

•   Tuesday 3:05 “Advanced replication monitoring”

•   Thursday 10:50am “Replication for Availability &
    Durability with MySQL and Amazon RDS”

•   Thursday 11:55am “Build your own PaaS for MySQL
    with Tungsten Enterprise”

•   Thursday 2:00pm “Error detection and correction with
    MySQL Replication”

•   Thursday 2:50pm “Performance comparisons and
    trade-offs for various MySQL replication schemes”
ADVERTISING
WE ARE HIRING!

QA and support
  engineers
http://www.continuent.com/about/careers
http://opendbcamp.org


         Open Database Camp

               Sardinia
           Technology Park

           6-7-8 May 2011
Contact Information


 Worldwide
 560 S. Winchester Blvd., Suite 500
 San Jose, CA 95128
 Tel (866) 998-3642
 Fax (408) 668-1009
 e-mail: sales@continuent.com




                      Continuent Web Site:
                   http://www.continuent.com
                        Tungsten Project
        http://code.google.com/p/tungsten-replicator


© Continuent 2011

Contenu connexe

Tendances

Alibaba patches in MariaDB
Alibaba patches in MariaDBAlibaba patches in MariaDB
Alibaba patches in MariaDBLixun Peng
 
A Tale of a Server Architecture (Frozen Rails 2012)
A Tale of a Server Architecture (Frozen Rails 2012)A Tale of a Server Architecture (Frozen Rails 2012)
A Tale of a Server Architecture (Frozen Rails 2012)Flowdock
 
JRuby on Rails Deployment: What They Didn't Tell You
JRuby on Rails Deployment: What They Didn't Tell YouJRuby on Rails Deployment: What They Didn't Tell You
JRuby on Rails Deployment: What They Didn't Tell Youelliando dias
 
DataMapper on Infinispan
DataMapper on InfinispanDataMapper on Infinispan
DataMapper on InfinispanLance Ball
 
Reducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQLReducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQLKenny Gryp
 
MySQL Binary Log API Presentation - OSCON 2011
MySQL Binary Log API Presentation - OSCON 2011MySQL Binary Log API Presentation - OSCON 2011
MySQL Binary Log API Presentation - OSCON 2011Mats Kindahl
 
.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011Fabio Akita
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011Lance Ball
 
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...Timofey Turenko
 
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyTorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyBruno Oliveira
 
When Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of TorqueboxWhen Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of Torqueboxrockyjaiswal
 
Why MySQL Replication Fails, and How to Get it Back
Why MySQL Replication Fails, and How to Get it BackWhy MySQL Replication Fails, and How to Get it Back
Why MySQL Replication Fails, and How to Get it BackSveta Smirnova
 
A26 MariaDB : The New&Implemented MySQL Branch by Colin Charles
A26 MariaDB : The New&Implemented MySQL Branch by Colin CharlesA26 MariaDB : The New&Implemented MySQL Branch by Colin Charles
A26 MariaDB : The New&Implemented MySQL Branch by Colin CharlesInsight Technology, Inc.
 
TorqueBox for Rubyists
TorqueBox for RubyistsTorqueBox for Rubyists
TorqueBox for Rubyistsbobmcwhirter
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxbobmcwhirter
 
Solving_the_C20K_problem_PHP_Performance_and_Scalability-phpquebec_2009
Solving_the_C20K_problem_PHP_Performance_and_Scalability-phpquebec_2009Solving_the_C20K_problem_PHP_Performance_and_Scalability-phpquebec_2009
Solving_the_C20K_problem_PHP_Performance_and_Scalability-phpquebec_2009Hiroshi Ono
 

Tendances (17)

Alibaba patches in MariaDB
Alibaba patches in MariaDBAlibaba patches in MariaDB
Alibaba patches in MariaDB
 
A Tale of a Server Architecture (Frozen Rails 2012)
A Tale of a Server Architecture (Frozen Rails 2012)A Tale of a Server Architecture (Frozen Rails 2012)
A Tale of a Server Architecture (Frozen Rails 2012)
 
JRuby on Rails Deployment: What They Didn't Tell You
JRuby on Rails Deployment: What They Didn't Tell YouJRuby on Rails Deployment: What They Didn't Tell You
JRuby on Rails Deployment: What They Didn't Tell You
 
DataMapper on Infinispan
DataMapper on InfinispanDataMapper on Infinispan
DataMapper on Infinispan
 
Reducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQLReducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQL
 
MySQL Binary Log API Presentation - OSCON 2011
MySQL Binary Log API Presentation - OSCON 2011MySQL Binary Log API Presentation - OSCON 2011
MySQL Binary Log API Presentation - OSCON 2011
 
.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
 
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
 
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyTorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
 
When Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of TorqueboxWhen Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of Torquebox
 
Why MySQL Replication Fails, and How to Get it Back
Why MySQL Replication Fails, and How to Get it BackWhy MySQL Replication Fails, and How to Get it Back
Why MySQL Replication Fails, and How to Get it Back
 
A26 MariaDB : The New&Implemented MySQL Branch by Colin Charles
A26 MariaDB : The New&Implemented MySQL Branch by Colin CharlesA26 MariaDB : The New&Implemented MySQL Branch by Colin Charles
A26 MariaDB : The New&Implemented MySQL Branch by Colin Charles
 
TorqueBox for Rubyists
TorqueBox for RubyistsTorqueBox for Rubyists
TorqueBox for Rubyists
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBox
 
Solving_the_C20K_problem_PHP_Performance_and_Scalability-phpquebec_2009
Solving_the_C20K_problem_PHP_Performance_and_Scalability-phpquebec_2009Solving_the_C20K_problem_PHP_Performance_and_Scalability-phpquebec_2009
Solving_the_C20K_problem_PHP_Performance_and_Scalability-phpquebec_2009
 
Devignition 2011
Devignition 2011Devignition 2011
Devignition 2011
 

En vedette

Advanced mysql replication techniques
Advanced mysql replication techniquesAdvanced mysql replication techniques
Advanced mysql replication techniquesGiuseppe Maxia
 
Dbms ii mca-ch11-recovery-2013
Dbms ii mca-ch11-recovery-2013Dbms ii mca-ch11-recovery-2013
Dbms ii mca-ch11-recovery-2013Prosanta Ghosh
 
Replication in Distributed Database
Replication in Distributed DatabaseReplication in Distributed Database
Replication in Distributed DatabaseAbhilasha Lahigude
 
database recovery techniques
database recovery techniques database recovery techniques
database recovery techniques Kalhan Liyanage
 
Fragmentation and types of fragmentation in Distributed Database
Fragmentation and types of fragmentation in Distributed DatabaseFragmentation and types of fragmentation in Distributed Database
Fragmentation and types of fragmentation in Distributed DatabaseAbhilasha Lahigude
 

En vedette (6)

Advanced mysql replication techniques
Advanced mysql replication techniquesAdvanced mysql replication techniques
Advanced mysql replication techniques
 
Dbms ii mca-ch11-recovery-2013
Dbms ii mca-ch11-recovery-2013Dbms ii mca-ch11-recovery-2013
Dbms ii mca-ch11-recovery-2013
 
Replication in Distributed Database
Replication in Distributed DatabaseReplication in Distributed Database
Replication in Distributed Database
 
Chapter25
Chapter25Chapter25
Chapter25
 
database recovery techniques
database recovery techniques database recovery techniques
database recovery techniques
 
Fragmentation and types of fragmentation in Distributed Database
Fragmentation and types of fragmentation in Distributed DatabaseFragmentation and types of fragmentation in Distributed Database
Fragmentation and types of fragmentation in Distributed Database
 

Similaire à My sql replication advanced techniques presentation

MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016Dave Stokes
 
MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016Dave Stokes
 
MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016Dave Stokes
 
Mater,slave on mysql
Mater,slave on mysqlMater,slave on mysql
Mater,slave on mysqlVasudeva Rao
 
MySQL High Availability Deep Dive
MySQL High Availability Deep DiveMySQL High Availability Deep Dive
MySQL High Availability Deep Divehastexo
 
Replication Tips & Tricks
Replication Tips & TricksReplication Tips & Tricks
Replication Tips & TricksMats Kindahl
 
Replication tutorial presentation
Replication tutorial presentationReplication tutorial presentation
Replication tutorial presentationcolderboy17
 
Mysql replication @ gnugroup
Mysql replication @ gnugroupMysql replication @ gnugroup
Mysql replication @ gnugroupJayant Chutke
 
Webinar Slides : Migrating to MySQL, MariaDB Galera and/or Percona XtraDB Clu...
Webinar Slides : Migrating to MySQL, MariaDB Galera and/or Percona XtraDB Clu...Webinar Slides : Migrating to MySQL, MariaDB Galera and/or Percona XtraDB Clu...
Webinar Slides : Migrating to MySQL, MariaDB Galera and/or Percona XtraDB Clu...Severalnines
 
2012 scale replication
2012 scale replication2012 scale replication
2012 scale replicationsqlhjalp
 
MySqL Failover by Weatherly Cloud Computing USA
MySqL Failover by Weatherly Cloud Computing USAMySqL Failover by Weatherly Cloud Computing USA
MySqL Failover by Weatherly Cloud Computing USAHarry Gonzalez
 
Replication Tips & Trick for SMUG
Replication Tips & Trick for SMUGReplication Tips & Trick for SMUG
Replication Tips & Trick for SMUGMats Kindahl
 
MySQL Replication Basics
MySQL Replication BasicsMySQL Replication Basics
MySQL Replication BasicsAbdul Manaf
 
Server modeling with mysql
Server modeling with mysqlServer modeling with mysql
Server modeling with mysqlDaeMyung Kang
 
Drupal Con My Sql Ha 2008 08 29
Drupal Con My Sql Ha 2008 08 29Drupal Con My Sql Ha 2008 08 29
Drupal Con My Sql Ha 2008 08 29liufabin 66688
 
Download presentation
Download presentationDownload presentation
Download presentationRachit Gaur
 
Download presentation531
Download presentation531Download presentation531
Download presentation531Indra Pratap
 

Similaire à My sql replication advanced techniques presentation (20)

MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016
 
MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016
 
Mysql S&M
Mysql S&MMysql S&M
Mysql S&M
 
MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016
 
Mater,slave on mysql
Mater,slave on mysqlMater,slave on mysql
Mater,slave on mysql
 
MySQL High Availability Deep Dive
MySQL High Availability Deep DiveMySQL High Availability Deep Dive
MySQL High Availability Deep Dive
 
Replication Tips & Tricks
Replication Tips & TricksReplication Tips & Tricks
Replication Tips & Tricks
 
Replication tutorial presentation
Replication tutorial presentationReplication tutorial presentation
Replication tutorial presentation
 
Mysql replication @ gnugroup
Mysql replication @ gnugroupMysql replication @ gnugroup
Mysql replication @ gnugroup
 
Mysql
MysqlMysql
Mysql
 
Webinar Slides : Migrating to MySQL, MariaDB Galera and/or Percona XtraDB Clu...
Webinar Slides : Migrating to MySQL, MariaDB Galera and/or Percona XtraDB Clu...Webinar Slides : Migrating to MySQL, MariaDB Galera and/or Percona XtraDB Clu...
Webinar Slides : Migrating to MySQL, MariaDB Galera and/or Percona XtraDB Clu...
 
2012 scale replication
2012 scale replication2012 scale replication
2012 scale replication
 
MySqL Failover by Weatherly Cloud Computing USA
MySqL Failover by Weatherly Cloud Computing USAMySqL Failover by Weatherly Cloud Computing USA
MySqL Failover by Weatherly Cloud Computing USA
 
Replication Tips & Trick for SMUG
Replication Tips & Trick for SMUGReplication Tips & Trick for SMUG
Replication Tips & Trick for SMUG
 
MySQL Replication Basics
MySQL Replication BasicsMySQL Replication Basics
MySQL Replication Basics
 
Scalr Demo
Scalr DemoScalr Demo
Scalr Demo
 
Server modeling with mysql
Server modeling with mysqlServer modeling with mysql
Server modeling with mysql
 
Drupal Con My Sql Ha 2008 08 29
Drupal Con My Sql Ha 2008 08 29Drupal Con My Sql Ha 2008 08 29
Drupal Con My Sql Ha 2008 08 29
 
Download presentation
Download presentationDownload presentation
Download presentation
 
Download presentation531
Download presentation531Download presentation531
Download presentation531
 

Dernier

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 

Dernier (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

My sql replication advanced techniques presentation

  • 1. Advanced MySQL Replication Techniques Giuseppe Maxia, QA Director, Continuent, Inc Facts. And Demos. Possibly fun
  • 2. about me - Giuseppe Maxia • a.k.a. The Data Charmer • QA Director at Continuent, Inc • Long time hacking with MySQL features • Formerly, community manager,db consultant, designer, coder. • A passion for QA and open source • Blogger • http://datacharmer.blogspot.com
  • 3. Agenda • Replication basics • Replication blues • Master switch and failover • Slave lagging • Gotchas • Replication power techniques and features • row-based, semi-synch, delayed • Circular, bi-directional • leveraging replication • Tools and tips • Replication outside the box • seamless failover, parallel, multi-master
  • 4. DA AG EN Replication basics • Principles • How to set up replication • Monitoring replication
  • 5. DA AG EN Principles
  • 6. database server a simple web application scheme r/w requests web server clients 6
  • 7. database server scaling web requests r/w requests web servers load balancer clients 7
  • 8. read/write master a web application read/only slaves scheme with replication load balancer R/W R/O web servers load balancer clients 8
  • 9. client master transaction binary log reads slave IO thread relay log replication concepts SQL thread reads 9
  • 10. DA AG EN replication setup
  • 11. 1 SHUT DOWN THE DATABASE SERVER Master 11
  • 12. 2 MAKE A BACKUP COPY Master 12
  • 13. 3 ENABLE THE MASTER Master Configuration file [mysqld] log-bin=mysql-bin server-id=1 13
  • 14. 4 RESTART THE MASTER Master 14
  • 15. 5 CREATE REPLICATION USER Master SQL command GRANT REPLICATION SLAVE ON *.* to 'slave_user@'10.10.100.%' IDENTIFIED BY 'slave_pass'; 15
  • 16. 6 INSTALL MySQL on the slave Slave 1 Make sure that: • You're using the same version of MySQL • You have the same directory structure • The server is not started yet 16
  • 17. 7 COPY THE MASTER DATA to the slave Slave 1 17
  • 18. 8 ENABLE THE SLAVE Slave 1 Configuration file [mysqld] server-id=2 relay-log=mysql-relay read-only # optional: log-bin=mysql-bin 18
  • 19. 9 START THE SLAVE SERVER Slave 1 19
  • 20. 10 INITIALIZE THE SLAVE Slave 1 SQL command CHANGE MASTER TO MASTER_HOST=master_IP, MASTER_PORT=3306, MASTER_USER=slave_user, MASTER_PASSWORD='slave_pwd'; 20
  • 21. 11 START THE SLAVE SERVICE Slave 1 SQL command START SLAVE; 21
  • 22. 12 CHECK THE SLAVE Slave 1 SQL command SHOW SLAVE STATUS G ... Slave_IO_Running: Yes Slave_SQL_Running: Yes ... 22
  • 23. Troubleshooting • SHOW SLAVE STATUS says SLAVE_IO_RUNNING=No • Make sure that the slave host can connect to the master • Make sure that master and slave have different Server-id • Check the error log of both master and slave
  • 24. Testing the slave • Create a table in the master. • Make sure that the slave has replicated the table. • Insert data in the master • read that data in the slave
  • 25. DA AG EN Monitoring
  • 26. Sample get slave status monitoring slave Running? No Yes master Get master binlog and position Same or later No Yes binlog/position? check table contents alert 26
  • 27. monitoring replication master> SHOW MASTER STATUS slave> SHOW SLAVE STATUS FULL SCRIPTS: http://datacharmer.blogspot.com/2011/04/refactored-again-poor-mans- mysql.html http://forge.mysql.com/tools/tool.php?id=6
  • 28. show master status File: mysql-bin.000002 Position: 78045744 Binlog_Do_DB: Binlog_Ignore_DB:
  • 29. show slave status Slave_IO_State: Waiting for master to send event Master_Host: 127.0.0.1 Master_User: rsandbox Master_Port: 27371 Connect_Retry: 60 Master_Log_File: mysql-bin.000002 Read_Master_Log_Pos: 78045744 Relay_Log_File: mysql_sandbox27372-relay-bin.000055 Relay_Log_Pos: 78045889 Relay_Master_Log_File: mysql-bin.000002 Slave_IO_Running: Yes Slave_SQL_Running: Yes
  • 30. show slave status ... Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: ...
  • 31. show slave status ... Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 78045744 Relay_Log_Space: 78046100 ... Seconds_Behind_Master: 0 ... Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error:
  • 32. DA AG EN Replication blues • Master switch and failover • Slave lagging • Gotchas
  • 33. DA AG EN Master switch and failover
  • 34. Replacing the Master master crashe s Let all slaves catch up with execution STOP replication in all slaves FIND the most make it the up to date slave master FIND which run missing connect all transactions are transactions slaves to the missing from to other new master other slaves slaves Stop 34
  • 35. Planned master switch • Stop accepting writes • Wait until all slaves have caught up • Stop replication in all slaves • Promote a slave to master • Point all slaves to the new master
  • 36. Changing a failed master • Pre-requisite: • log_bin and log_slave_updates must be enabled in all the slaves • If not, there is more manual labor
  • 37. Changing a failed master (1) • Wait until all slaves have caught up • Identify the most advanced slave • Make that slave the new master • ... so far, so good
  • 38. Changing a failed master (2) • For each remaining slave: • Find the missing statements • Find the LAST statement replicated by the slave • Find the same statement in the new master binlog (*) • get the position of the NEXT statement (*) if log_slave_updates was not enabled, you need to convert the relay log statements to SQL and do the next step manually
  • 39. Changing a failed master (3) • For each remaining slave: • Apply the missing statements • CHANGE MASTER TO master_host=”new_master_hostname”, master_port=new_master_port, master_log_file=”mysql-bin.xxxxxx”, master_log_pos=YYYY
  • 40. Reasons for complexity • No global transaction ID
  • 41. What is a global transaction ID • A unique identifier of a transaction • Unique for the whole cluster, not for each node • Generated by the ultimate source (the master) • Does not change when the transaction goes through an intermediate master
  • 42. Why should you care • Failure recovery • MySQL DOES NOT have it
  • 43. Defining the problem Slave 3 Master Replication Slave 2 Slave 1 Binary log Transactions Relay log Binary log -------- -------- -------- Transactions Transactions -------- -------- ======== -------- ======== -------- ======== -------- ========
  • 44. The master crashes Slave 3 Master Replication Slave 2 Slave 1 Binary log Transactions Relay log Binary log -------- -------- -------- Transactions Transactions -------- -------- ======== -------- ======== -------- ======== -------- ========
  • 45. Where do the slaves stand? Slave 1 Slave 2 Slave 3 Binary log Binary log Binary log Transactions Transactions Transactions ======== ======== ======== ======== ======== ======== ======== ======== ======== ======== ======== ========
  • 46. Slave 3 becomes master New master Slave 1 Slave 2 Binary log Transactions ======== Binary log Binary log ======== ======== Transactions Transactions ======== ======== ======== ======== ======== ======== ======== ======== ========
  • 47. Need to synch the missing transactions New master Slave 1 Slave 2 Binary log Transactions ======== Binary log Binary log ======== ======== Transactions Transactions ======== ======== ======== ======== ======== ======== ======== ======== ========
  • 48. Transaction position in the new master binlog New master Slave 1 Slave 2 Binary log Transactions ======== Binary log Binary log ======== ======== Transactions Transactions ======== ======== ======== ======== ======== ======== ? ======== ? ======== ========
  • 49. An existing solution • Google has made a patch to implement global transaction IDs • HOWEVER • It only works with 5.0 • It doesn't work with row based replication
  • 51. CREATE TABLE Global_Trans_ID ( number INT UNSIGNED AUTO_INCREMENT PRIMARY KEY ) ENGINE = MyISAM; CREATE TABLE Last_Exec_Trans ( server_id INT UNSIGNED, trans_id INT UNSIGNED ) ENGINE = InnoDB;
  • 52. CREATE PROCEDURE commit_trans () BEGIN DECLARE trans_id, server_id INT UNSIGNED; SET SQL_LOG_BIN = 0; INSERT INTO global_trans_id() values (); SELECT LAST_INSERT_ID() INTO trans_id, @@server_id INTO server_id; DELETE FROM global_trans_id where number < trans_Id; SET SQL_LOG_BIN = 1; INSERT INTO last_exec_trans(server_id, trans_id) VALUES (server_id, trans_id); COMMIT; END
  • 54. Simplifying the scheme • No MyISAM table and LAST_INSERT_ID() • Use UUID_SHORT() instead • Replace the InnoDB table with a BlackHole one
  • 55. Advantages • 10 times faster • No additional tables and storage required
  • 56. Disadvantages • The master SERVER ID must be < 256
  • 57. Another solution • We’ll see that in the second part of the talk
  • 58. DA AG EN Slave lagging
  • 59. Slave lagging • Common causes: • Excess of traffic • Slave restart • Long DDL operations
  • 60. Slave lagging transaction transaction MySQL transaction transaction transaction DBMS transaction transaction transaction transaction transaction transaction transaction BINARY LOG ns act act tio n tra csio s ac ctio ac ion ion n an n s an nr tr tra aniton tsa a n csio nts ct n rn a o taa scti r trnsa n n tio t tra tra REPLICATION MySQL replication is SINGLE THREAD transaction transaction MySQL DBMS
  • 61. Slave lagging remedies • row-based replication (helps in some cases) • Expensive query split • Double apply (dangerous) • Slave query prefetch (requires external app) • Parallel replication (requires external app)
  • 62. statement-based replication master> set global binlog_format=‘statement’; master> insert into test.t1 select count(*) from information_schema.columns; master> show global status like 'opened_tables'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Opened_tables | 41 | +---------------+-------+ slave> show global status like 'opened_tables'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Opened_tables | 41 | +---------------+-------+
  • 63. row-based replication master> set global binlog_format=‘row’; master> insert into test.t1 select count(*) from information_schema.columns; master> show global status like 'opened_tables'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Opened_tables | 41 | +---------------+-------+ slave> show global status like 'opened_tables'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Opened_tables | 17 | +---------------+-------+
  • 64. Expensive query split # instead of this: insert into t1 select benchmark(10000000, sha('abc')); Query OK, 1 row affected (4.19 sec) Records: 1 Duplicates: 0 Warnings: 0 # you may do this set @result=(select benchmark(10000000, sha('abc'))); Query OK, 0 rows affected (4.19 sec) insert into t1 values (@result); Query OK, 1 row affected (0.00 sec)
  • 65. Expensive query split # at 471 #110410 8:21:21 server id 1 end_log_pos 518 User_var SET @`result`:=0/*!*/; # at 518 #110410 8:21:21 server id 1 end_log_pos 612 Query thread_id=3 exec_time=0 error_code=0 SET TIMESTAMP=1302448881/*!*/; insert into t1 values (@result)
  • 66. Slave query prefetch • What is it? • a technique that fetches queries from the relay logs, and runs them as SELECT statements, to warm up the indexes • How do you do it? • mk-slave-prefetch (http://www.maatkit.org) • Slave readahead http://sourceforge.net/ projects/slavereadahead/
  • 67. DA AG EN Gotchas
  • 68. Gotchas • When you thought that you had figured out everything ...
  • 69. Gotchas: LOAD DATA • LOAD DATA INFILE is replicated as a temporary file • The slave needs three times the size of the data: • the relay log • the temporary file • the data itself
  • 70. Gotchas: default engine • If you define storage_engine in the master, it does not get replicated
  • 71. Gotchas: binlog format • In circular replication, and relay slaves • Changes to binlog_format are not propagated
  • 72. Gotchas: binlog format server id: 101 insert into t1 format: statement values (@@server_id) 101 server id: 102 format: row 102 server id: 103 102 format: row
  • 73. Gotchas: set global not really global • set global binlog_format=row • Works for all new connections after the change • It does not work for the event scheduler!
  • 74. Gotchas: triggers and row replication • In statement based replication, triggers are fired both on master and slave • in row-based replication, triggers are fired on master only, and the resulting rows are moved to the slave
  • 75. DA AG EN Replication power techniques and features • row-based • semi-synch • delayed • Circular • bi-directional • Leveraging replication
  • 76. DA AG EN row-based replication
  • 77. row-based replication • Available in 5.1 and later • can be changed using “binlog_format” • row • mixed • statement (default)
  • 78. row-based replication • DO • when you have expensive queries in the master • when you are using non-deterministic functions • DON’T • When you are updating a lot of rows
  • 79. DA AG EN semi-synch replication
  • 80. semi-synchronous replication • Available in 5.5 and higher • Makes sure that at least one slave has copied the data. • Increases reliability
  • 81. client master transaction 1 with regular commit replication execute 2 slave returns 4 to client binary log 3 5 replication 81
  • 82. client transaction master 1 with semi- commit synchronous replication execute 2 slave 7 returns to client binary log 3 sends 4 transaction relay log 5 to slave gets 6 acknowledgement 82
  • 83. semi-synchronous replication in practice • installation: • it’s a plugin. • Actually, two plugins
  • 84. semi-synch replication install # in the master plugin-load=rpl_semi_sync_master=semisync_master.so rpl_semi_sync_master_enabled=1 # in each slave plugin-load=rpl_semi_sync_slave=semisync_slave.so rpl_semi_sync_slave_enabled=1 # restar all servers
  • 85. semi-synch replication check # in the master show variables like 'rpl_semi%'; +------------------------------------+-------+ | Variable_name | Value | +------------------------------------+-------+ | rpl_semi_sync_master_enabled | ON | | rpl_semi_sync_master_timeout | 10000 | | rpl_semi_sync_master_trace_level | 32 | | rpl_semi_sync_master_wait_no_slave | ON | +------------------------------------+-------+
  • 86. semi-synch replication check show status like "rpl_semi_%tx"; +-----------------------------+-------+ | variable_name | value | +-----------------------------+-------+ | RPL_SEMI_SYNC_MASTER_NO_TX | 0 | | RPL_SEMI_SYNC_MASTER_YES_TX | 0 | +-----------------------------+-------+
  • 87. semi-synch replication test master> create table t1 ( i int); Query OK, 0 rows affected (0.01 sec) master> show status like "rpl_semi_%tx"; +-----------------------------+-------+ | Variable_name | Value | +-----------------------------+-------+ | Rpl_semi_sync_master_no_tx | 0 | | Rpl_semi_sync_master_yes_tx | 1 | +-----------------------------+-------+
  • 88. disabling semi-synch # for each slave set global rpl_semi_sync_slave_enabled=0; stop slave io_thread; start slave io_thread;
  • 89. disabled semi-synch replication test master> insert into t1 values (1); Query OK, 1 row affected (10.00 sec) master> show status like "rpl_semi_%tx"; +-----------------------------+-------+ | Variable_name | Value | +-----------------------------+-------+ | Rpl_semi_sync_master_no_tx | 1 | | Rpl_semi_sync_master_yes_tx | 1 | +-----------------------------+-------+ 2 rows in set (0.00 sec)
  • 90. disabled semi-synch replication test master> insert into t1 values (2); Query OK, 1 row affected (0.01 sec) master> show status like "rpl_semi_%tx"; +-----------------------------+-------+ | Variable_name | Value | +-----------------------------+-------+ | Rpl_semi_sync_master_no_tx | 2 | | Rpl_semi_sync_master_yes_tx | 1 | +-----------------------------+-------+ 2 rows in set (0.00 sec)
  • 91. re-enabling semi-synch # in one slave set global rpl_semi_sync_slave_enabled=1; stop slave io_thread; start slave io_thread;
  • 92. reenabled semi-synch replication test master> insert into t1 values (3); Query OK, 1 row affected (0.01 sec) master> show status like "rpl_semi_%tx"; +-----------------------------+-------+ | Variable_name | Value | +-----------------------------+-------+ | Rpl_semi_sync_master_no_tx | 2 | | Rpl_semi_sync_master_yes_tx | 2 | +-----------------------------+-------+ 2 rows in set (0.00 sec)
  • 93. DA AG EN delayed replication
  • 94. delayed replication in practice STOP SLAVE; change master to master_delay=60; START SLAVE;
  • 96. DA AG EN Circular replication
  • 97. Circular A A MySQL B DBMS MySQL DBMS B master master MySQL DD DBMS MySQL DBMS C C master
  • 98. DA AG EN bi-directional replication
  • 100. bi-directional replication MySQL MySQL DBMS DBMS Los Angeles New York MySQL MySQL MySQL DBMS DBMS DBMS MySQL DBMS
  • 101. DA AG EN Leveraging replication
  • 102. Overview of MySQL partitions
  • 103. Partition pruning 1a - unpartitioned table - SINGLE RECORD I D select * N from table_name A D where colx = T E 120 A X
  • 104. Partition pruning 2a - table partitioned by colx - SINGLE REC 1-99 100-199 select * from table_name 200-299 where colx = 120 300-399 400-499 500-599
  • 105. Partition pruning 1a - unpartitioned table - RANGE select * I from D N table_name A where colx D between 120 T E and 230 A X
  • 106. Partition pruning 2a - table partitioned by colx - RANGE 1-99 select * 100-199 from table_name 200-299 where colx between 120 and 230 300-399 400-499 500-599
  • 107. Storage comparison engine storage (GB) innodb (with PK) 330 myisam (with PK) 141 archive 13 innodb partitioned (no PK) 237 myisam partitioned (no PK) 107 archive partitioned 13
  • 108. Benchmarking results engine 6 month range InnoDB 4 min 30s MyISAM 25.03s Archive 22 min 25s InnoDB partitioned by month 13.19 MyISAM partitioned by year 6.31 MyISAM partitioned by month 4.45 Archive partitioned by year 16.67 Archive partitioned by month 8.97
  • 109. Partitions limits  Little concurrency  Need of using the partitioning column
  • 112. REPLICATION PARTITIONING large data ARCHIVE
  • 113. Replication = let the slave do the dirty work
  • 114. master backup slaves STOP SLAVE remove slave perform from load backup balancer attach slave START Let slave to load SLAVE catch up balancer
  • 115. master make summary tables slaves STOP SLAVE calculate remove slave summary from load tables balancer attach slave Let slave START SLAVE to load catch up balancer
  • 116. master Partitions for heavy innodb non partitioned statistics slave slave innodb innodb non partitioned partitioned by range slave MyISAM partitioned by range
  • 117. Simulating master multiple innodb non partitioned dimensions slave slave innodb non partitioned ARCHIVE partitioned by range (date) slave slave ARCHIVE partitioned by range ARCHIVE (location) partitioned by range (product)
  • 118. DA AG EN Tools and tips • MySQL Sandbox • Replaying binary logs • Filtering binary logs • Baron Schwartz’s Maatkit • Shlomi Noach’s openark kit • Facebook’s Online Schema Change • Measuring replication speed • Detecting if replication is on
  • 119. DA AG EN MySQL Sandbox
  • 120. MySQL Sandbox http://mysqlsandbox.net • Free software (Perl under GPL) • One (unix) host • Many database servers • Single or multiple sandboxes • Customized scripts to use the servers • Standard or circular replication • Installs IN SECONDS
  • 121. overview MySQL MySQL server server DATA DIRECTORY PORT SOCKET
  • 122. overview MySQL MySQL server server SAME DATA DIRECTORY? /var/lib/mysql /var/lib/mysql DATA CORRUPTION
  • 123. overview MySQL MySQL server server SAME PORT or SOCKET? 3306 3306 /tmp/mysql.sock /tmp/mysql.sock DOES NOT START
  • 124. The hard way (1)
  • 125. the hard way (2)
  • 126. The easy way $ make_sandbox /path/to/mysql-5.1.54_linux.tar.gz # it should work always
  • 127. The easier way $ make_sandbox 5.1.54 # Needs some preliminary work
  • 128. The easiest way $ sb 5.1.54 # Needs the same preliminary work
  • 129. MySQL Sandbox VERSION MySQL server $SANDBOX_HOME/msb_VERSION/data VERSION /tmp/mysql_VERSION.sock
  • 130. MySQL Sandbox 5.1.54 MySQL server $SANDBOX_HOME/msb_5_1_54/data 5154 /tmp/mysql_5154.sock
  • 131. MySQL Sandbox 5.5.9 MySQL server $SANDBOX_HOME/msb_5_5_09/data 5509 /tmp/mysql_5509.sock
  • 132. Single Sandbox MySQL customized scripts server start stop restart status clear send_kill use
  • 133. Multiple Sandbox MySQL customized scripts server start_all stop_all restart_all m n1 status_all s1 n2 clear_all s2 n3 send_kill_a ll use_all
  • 134. Where do you get it •from CPAN sudo cpan MySQL::Sandbox •from launchpad http://launchpad.net/mysql-sandbox
  • 135. The easy replication way $ make_replication_sandbox /path/to/mysql-5.1.54_linux.tar.gz # or, after some preparation $ make_replication_sandbox 5.1.54
  • 136. default architecture $HOME /sandboxes opt expanded tarballs mysql installed sandboxes
  • 137. default architecture $HOME /sandboxes opt msb_5_0_91 mysql msb_5_1_48 5.0.91 rsandbox_5_1_48 5.1.45 master 5.1.48 node1 5.5.4 node2
  • 138.
  • 139. creating a single sanbox make_sandbox /path/to/mysql-X.X.XX-OS.tar.gz
  • 140. using a single sanbox # after # make_sandbox # /path/to/mysql-X.X.XX-OS.tar.gz $ cd $SANDBOX_HOME/msb_X_X_XX $ ./use
  • 141. creating a single sanbox with a specific options file make_sandbox /path/to/mysql-X.X.XX-OS.tar.gz --my_file=/path/to/my.cnf
  • 142. easily create a sandbox after the first one The long way $ cd $HOME/opt/mysql # $SANDBOX_BINARY $ gunzip -c /path/to/mysql-5.1.34-osx10.5-x86.tar.gz | tar -xf - $ mv mysql-5.1.34-osx10.5-x86 5.1.34 $ make sandbox 5.1.34
  • 143. easily create a sandbox after the first one The short way $ make_sandbox path/to/mysql-5.1.34-osx10.5-x86.tar.gz --export_binaries
  • 144. starting a single sanbox $ cd $SANDBOX_HOME/msb_X_X_XX $ ./start
  • 145. starting a single sanbox with temporary options $ cd $SANDBOX_HOME/msb_X_X_XX $ ./start --option=value $ ./restart --option=value $ ./start --key-buffer=20000000
  • 146. creating a sandbox with custom port and directory $ make_sandbox 5.1.34 --sandbox_port=7800 --sandbox_directory=mickeymouse
  • 147. creating a sandbox with automatic port checking $ make_sandbox 5.1.34 --check_port # if 5.1.34 is free # port=5134 # directory=msb_5_1_34 # else # port=5135 (or the first free) # directory=msb_5_1_34_a
  • 148. create a replication sandbox $ make_replication_sandbox path/to/mysql-5.1.34-osx10.5-x86.tar.gz
  • 149. create a circular replication sandbox $ make_replication_sandbox --circular=4 path/to/mysql-5.1.34-osx10.5-x86.tar.gz
  • 150. changing port to an existing sandbox $ sbtool -o port -s /path/to/source/sandbox --new_port=XXXX
  • 151. installing the innodb plugin $ sbtool -o plugin --plugin=innodb -s /path/to/source/sandbox
  • 152. creating a replication sandbox with new base port $ make_replication_sandbox --replication_directory=newwdir --check_base_port 5.0.79 # Creates a replication directory under # $SANDBOX_HOME/newdir # The previous one is preserved. # No conflicts happen
  • 153. DA AG EN Replaying binary logs
  • 154. DA AG EN Filtering binary logs
  • 155. DA AG EN Maatkit
  • 156. maatkit • mk-heartbeat Monitor MySQL replication delay. • mk-purge-logs Purge binary logs on a master based on purge rules. • mk-slave-delay Make a MySQL slave server lag behind its master. • mk-slave-find Find and print replication hierarchy tree of MySQL slaves. • mk-slave-move Move a MySQL slave around in the replication hierarchy. • mk-slave-prefetch Pipeline relay logs on a MySQL slave to pre-warm caches. • mk-slave-restart Watch and restart MySQL replication after errors. • mk-table-checksum Perform an online replication consistency check, or checksum MySQL tables efficiently on one or many servers. • mk-table-sync Synchronize MySQL table data efficiently. • http://www.maatkit.org/
  • 157. Facebook Online Schema Change DA EN AG
  • 158. Facebook Online Schema Change • Based on one of Shlomi Noach OpenArk utilities • Developed in PHP by Facebook • http://www.facebook.com/note.php?note_id=430801045932
  • 159. DA AG EN OpenArk
  • 160. openark • oak-get-slave-lag: print slave replication lag and terminate with respective exit code. • oak-online-alter-table: perform a non-blocking ALTER TABLE operation. • oak-purge-master-logs: purge master logs, depending on the state of replicating slaves. • oak-show-replication-status: show how far behind are replicating slaves on a given master. • http://code.openark.org/forge/openark-kit
  • 161. DA AG EN Check replication speed
  • 162. check replication speed • Write a time to the master • Retrieve it from the slave • Compare times • http://forge.mysql.com/tools/tool.php? id=5
  • 163. DA AG EN Replication outside the box • Seamless failover • Parallel replication • Multiple source replication • Multiple master replication
  • 165. Once Upon A Time, In The Life Of A Database Consultant ...
  • 166. The story of a steel foundry • Used MySQL databases to store production monitoring data • Inserted a zillion records per second. • Slaves often lagged behind
  • 167. transaction transaction MySQL transaction transaction transaction DBMS transaction transaction transaction transaction transaction transaction transaction BINARY LOG ns act act tio n tra ansio ns sac ntio ac ion ion n ac nr tr tra aniton tsa a n csio nts ct n rn a o taa scti r trnsa n n tio ct tra tra REPLICATION transaction transaction MySQL DBMS
  • 168. The story of a shoe maker • Had a successful business, spread to a dozen stores. • Needed to aggregate the data from the stores in his headquarters database.
  • 169. MySQL MySQL DBMS MySQL DBMS DBMS store store store MySQL DBMS headquarters
  • 170. The story of a widgets seller • Had a successful business, designed for one server. • Products were created in several sites. • Needed to allow insertions from more than one master at the time
  • 171. MySQL MySQL DBMS DBMS master master MySQL MySQL DBMS DBMS master master
  • 172. All these stories tell us: Nice dream, but MySQL can’t do it
  • 178. What can it do? • Easy failover • Multiple masters • Multiple sources to a single slave • Parallel replication • Replicate to Oracle and PostgreSQL database
  • 179. MySQL to foreign services MySQL setup to run as MySQL master Master DB Data is applied to PostgreSQL or Oracle Bin Logs (Binlogs enabled) Slave DB © Continuent 2010
  • 190. master/slave with an attitude
  • 191. The steel foundry dream or parallel replication From here ...
  • 192. The steel foundry dream or parallel replication To here.
  • 193. Parallel replication facts • Sharded by database • Good choice for slave lag problems • Bad choice for single database projects
  • 194. Testing parallel replication
  • 195. db0 preparation (1) db1 sysbench db2 sysbench db3 sysbench db4 sysbench db5 sysbench db6 sysbench db7 sysbench db8 sysbench db9 sysbench sysbench
  • 198. before the test (2) SQL thread RELAY logs IO thread binary logs MySQL slave RELAY logs Tungsten slave direct: alpha (slave) replicator alpha
  • 199. starting the test SQL thread RELAY logs IO thread binary logs MySQL slave RELAY logs Tungsten slave direct: alpha (slave) replicator alpha
  • 200. MySQL native replication slave catch up in 00:02:30
  • 201. Tungsten parallel replication slave catch up in 00:01:20
  • 202. The widget seller dream, or multi masters • Tungsten Replicator recipe: use more services
  • 205. True multiple master We’ll see that in a moment. But first
  • 206. The shoe maker dream, or multiple sources • Tungsten Replicator recipe is still valid: use more services
  • 210. Updating 4 masters : 1 flow
  • 211. Updating 4 masters : 2 flows
  • 212. Updating 4 masters : 3 flows
  • 213. Updating 4 masters : 4 flows
  • 214. Tungsten in practice • installation
  • 215. Installation: the long way • Get the binaries • Expand the tarball • Check the requirements in the manual • Run ./configure • Run ./configure-service
  • 216. Installation: the quick way • Get the tarball • Get the tungsten deployer from Google Code • Sit back and enjoy!
  • 218. replicator • It’s the service provider • You launch it once when you start • You may restart it when you change config
  • 219. trepctl • Tungsten Replicator ConTroLler • It’s the driving seat for your replication • You can start, update, and stop services • You can get specific info
  • 220. thl • Transaction History List • Gives you access to the Tungsten relay logs
  • 221. DA AG EN More info on replication
  • 222. Books
  • 227. Talks • Monday, 1:30pm “Learn how to cure replication deprivation with Tungsten” • Tuesday 10:50am “Replication Update” • Tuesday 2:00pm “Diagnosing replication failures” • Tuesday 3:05 “Advanced replication monitoring” • Thursday 10:50am “Replication for Availability & Durability with MySQL and Amazon RDS” • Thursday 11:55am “Build your own PaaS for MySQL with Tungsten Enterprise” • Thursday 2:00pm “Error detection and correction with MySQL Replication” • Thursday 2:50pm “Performance comparisons and trade-offs for various MySQL replication schemes”
  • 229. WE ARE HIRING! QA and support engineers http://www.continuent.com/about/careers
  • 230. http://opendbcamp.org Open Database Camp Sardinia Technology Park 6-7-8 May 2011
  • 231. Contact Information Worldwide 560 S. Winchester Blvd., Suite 500 San Jose, CA 95128 Tel (866) 998-3642 Fax (408) 668-1009 e-mail: sales@continuent.com Continuent Web Site: http://www.continuent.com Tungsten Project http://code.google.com/p/tungsten-replicator © Continuent 2011

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. Common web applications connect the web servers through load balancers. These applications are easy to scale at the web server level. They simply update the load balancer list, and the application is able to serve web pages at a reasonable speed. The database server is usually able to handle the load of many web servers when the application is created. However, soon enough it becomes a SPOF\n
  7. Common web applications connect the web servers through load balancers. These applications are easy to scale at the web server level. They simply update the load balancer list, and the application is able to serve web pages at a reasonable speed. The database server is usually able to handle the load of many web servers when the application is created. However, soon enough it becomes a SPOF\n
  8. The way MySQL database evolves is using the &quot;scale out&quot; technique.\nInstead of buying more expensive servers, you run a master and several slaves on commodity hardware. The master handles the write requests, and a small portion of the reads (usually when they come within transactions) and the slaves handle the read requests.\nThe downside of this scheme is that your application must be able to split write requests from read ones.\n\n
  9. How does replication work? The writes go to the master. As soon as the transaction is successfully executed, the master writes it to the binary load.\nEach slave has two parallel threads dedicated to replication. The IO thread will fetch the events from the master binary log, saving them into a relay log. The SQL thread will take the events from the relay log and reproduce them in the slave\n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. First of all, you must make sure that replication is working.\nIf you monitor the master, it won&amp;#x2019;t tell you anything about replication problems.\nYou need to keep an eye on the whole system.\nMonitoring SHOW SLAVE STATUS will tell you if replication is running, and it will give you some clues on whether the process is going well.\n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. Replacing the master, instead, is probably the most complex operation in replication.\nFinding the transactions that are present in the most up to date slave (the one promoted to master) but missing in the other slaves, and making sure that each of the other slaves catches up the missing ones is a long manual chore.\nThe reason for this difficulty is that MySQL does not have a global transaction ID.\n\n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. With regular replication, you commit a transaction, and get back a result from the server. For you, that transaction is stored, and you walk away pleased of your work.\nHowever, if the master crashes after it has sent you the result and before the slave has had a chance to get the record, you have SILENTLY lost a record, which is the worst possible scenario, because you don&amp;#x2019;t know you miss it.\n
  82. WIth semi-synchronous replication, instead, the master does not send the result to the client right away. It will first alert the slave that a new transaction is ready in the binary log. The slave will get the transaction and store it in its relay log, and tells the master that it has got a copy of the transaction. Only then the master tells the client that the commit was successful. If the master crashes before returning to the client, the client will get an error, and will not miss a transaction.\nNotice that the operation tells only that the transaction has reached the slave, not that it has been committed to the slave. It is not a two-phase commit.\n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n
  106. \n
  107. \n
  108. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. \n
  114. \n
  115. \n
  116. \n
  117. \n
  118. \n
  119. \n
  120. MySQL Sandbox is a tool that installs an additional MySQL server in a few seconds.\nYou can have more than one database servers in your host, all of them independent from each other. Installing a new server with MySQL Sandbox is a matter of seconds. You can install either a single sandbox or a system including multiple ones. Sandboxed servers can be stand-alone or related in standard or circular replication systems.\nIt is free software, and it works on most every unix OS. In combination with Gearman, it can install and setup replication systems across multiple hosts.\n
  121. \n
  122. \n
  123. \n
  124. \n
  125. \n
  126. \n
  127. \n
  128. \n
  129. \n
  130. \n
  131. \n
  132. \n
  133. \n
  134. \n
  135. \n
  136. \n
  137. \n
  138. \n
  139. \n
  140. \n
  141. \n
  142. \n
  143. \n
  144. \n
  145. \n
  146. \n
  147. \n
  148. \n
  149. \n
  150. \n
  151. \n
  152. \n
  153. \n
  154. \n
  155. \n
  156. \n
  157. \n
  158. \n
  159. \n
  160. \n
  161. \n
  162. \n
  163. \n
  164. \n
  165. \n
  166. \n
  167. \n
  168. \n
  169. \n
  170. \n
  171. \n
  172. \n
  173. \n
  174. \n
  175. \n
  176. \n
  177. \n
  178. \n
  179. \n
  180. \n
  181. \n
  182. \n
  183. \n
  184. \n
  185. \n
  186. \n
  187. \n
  188. \n
  189. \n
  190. \n
  191. \n
  192. \n
  193. \n
  194. \n
  195. \n
  196. \n
  197. \n
  198. \n
  199. \n
  200. \n
  201. \n
  202. \n
  203. \n
  204. \n
  205. \n
  206. \n
  207. \n
  208. \n
  209. \n
  210. \n
  211. \n
  212. \n
  213. \n
  214. \n
  215. \n
  216. \n
  217. \n
  218. \n
  219. \n
  220. \n
  221. \n
  222. \n
  223. \n
  224. \n
  225. \n
  226. \n
  227. \n
  228. \n
  229. \n
  230. How do I get an eval copy of the software\n\nCan you share any whitepapers on this technology?\n\nWhat is the price?\nOur dedicated server price is based upon CPU&amp;#x2019;s and the size of the cluster\nThe monthly subscription starts at $125 list for a 2 node.\nVirtual Private Clusters are priced differently and I would be glad to discuss this off-line\n\nIs the entire database kept in memory?\n\nCan I make schema changes while the cluster is running\n\nHow do you differ from Veritas Cluster Server?\n