mysql56 replication

35
MySQL 5.6 Replication New feature 데이터기술팀 운영파트 조민

Upload: chris-makayal

Post on 19-May-2015

380 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Mysql56 replication

MySQL 5.6 Replication New feature

데이터기술팀 운영파트

조민

Page 2: Mysql56 replication

INDEX

1. New Crash-Safe Slaves

2. New Multi-threaded Slaves

3. New Time-delayed Replication

4. New Optimized Row-based Replication

5. New Replication Checksums

6. New Global Transactions Identifiers (GTIDs)

Page 3: Mysql56 replication

INDEX

1. New Crash-Safe Slaves

2. New Multi-threaded Slaves

3. New Time-delayed Replication

4. New Optimized Row-based Replication

5. New Replication Checksums

6. New Global Transactions Identifiers (GTIDs)

Page 4: Mysql56 replication

1. New Crash-Safe Slaves (설정)

my.cnf

relay-log-info-repository=TABLE

master-info-repository=TABLE

# default FILE

==============================================================

mysql> stop slave;

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> set global master_info_repository='TABLE';

Query OK, 0 rows affected (0.02 sec)

mysql> set global relay_log_info_repository='TABLE';

Query OK, 0 rows affected (0.02 sec)

mysql> start slave;

Query OK, 0 rows affected, 1 warning (0.09 sec)

Page 5: Mysql56 replication

1. New Crash-Safe Slaves

mysql> select * from mysql.slave_master_info\G

*************************** 1. row ***************************

Number_of_lines: 23

Master_log_name: mysql-bin.000005

Master_log_pos: 2396

Host: 10.98.98.115

User_name: mig

User_password: mig

Port: 7979

Connect_retry: 60

Enabled_ssl: 0

Ssl_ca:

Ssl_capath:

Ssl_cert:

Ssl_cipher:

Ssl_key:

Ssl_verify_server_cert: 0

Heartbeat: 1800

Bind:

Ignored_server_ids: 0

Uuid: c35b769a-8fac-11e2-a667-00a0d1e293e2

Retry_count: 86400

Ssl_crl:

Ssl_crlpath:

Enabled_auto_position: 0

1 row in set (0.00 sec)

Page 6: Mysql56 replication

1. New Crash-Safe Slaves

mysql> select * from mysql.slave_relay_log_info\G

*************************** 1. row ***************************

Number_of_lines: 7

Relay_log_name: ./db-ha-db2-relay-bin.000011

Relay_log_pos: 1770

Master_log_name: mysql-bin.000005

Master_log_pos: 2396

Sql_delay: 60

Number_of_workers: 0

Id: 1

1 row in set (0.00 sec)

장애 시 Duplication 제거 Query 이용 !!! (DIS)

느리다!!!

Page 7: Mysql56 replication

2. New Multi-threaded Slaves

1. New Crash-Safe Slaves

2. New Multi-threaded Slaves

3. New Time-delayed Replication

4. New Optimized Row-based Replication

5. New Replication Checksums

6. New Global Transactions Identifiers (GTIDs)

Page 8: Mysql56 replication

2. New Multi-threaded Slaves (설정)

my.cnf

relay-log-info-repository=TABLE

master-info-repository=TABLE

slave-parallel-workers=3

=============================================

mysql> stop slave;

Query OK, 0 rows affected, 1 warning (0.09 sec)

mysql> set global slave_parallel_workers=3;

Query OK, 0 rows affected (0.00 sec)

mysql> start slave;

Query OK, 0 rows affected, 1 warning (0.09 sec)

Page 9: Mysql56 replication

2. New Multi-threaded Slaves

SLAVE

+-----+-------------+-----------+-------+---------+------+-----------------------------------------------------------------------------+------------------+

| Id | User | Host | db | Command | Time | State | Info |

+-----+-------------+-----------+-------+---------+------+-----------------------------------------------------------------------------+------------------+

| 1 | system user | | NULL | Connect | 1692 | Waiting for master to send event | NULL |

| 12 | root | localhost | mysql | Query | 0 | init | show processlist |

| 602 | system user | | NULL | Connect | 17 | Slave has read all relay log; waiting for the slave I/O thread to update it | NULL |

| 603 | system user | | NULL | Connect | 98 | Waiting for an event from Coordinator | NULL |

| 604 | system user | | NULL | Connect | 79 | Waiting for an event from Coordinator | NULL |

| 605 | system user | | NULL | Connect | 85 | Waiting for an event from Coordinator | NULL |

+-----+-------------+-----------+-------+---------+------+-----------------------------------------------------------------------------+------------------+

MASTER

mysql> show processlist;

+-----+------+--------------------------+------+-------------+------+-----------------------------------------------------------------------+------------------+

| Id | User | Host | db | Command | Time | State | Info |

+-----+------+--------------------------+------+-------------+------+-----------------------------------------------------------------------+------------------+

| 146 | root | localhost | NULL | Sleep | 362 | | NULL |

| 147 | mig | db-ha-db2.daum.net:34782 | NULL | Binlog Dump | 269 | Master has sent all binlog to slave; waiting for binlog to be updated | NULL |

| 148 | root | localhost | NULL | Query | 0 | init | show processlist |

+-----+------+--------------------------+------+-------------+------+-----------------------------------------------------------------------+------------------+

3 rows in set (0.00 sec)

Page 10: Mysql56 replication

2. New Multi-threaded Slaves

mysql> select * from slave_worker_info\G

*************************** 1. row ***************************

Id: 1

Relay_log_name:

Relay_log_pos: 0

Master_log_name:

Master_log_pos: 0

Checkpoint_relay_log_name:

Checkpoint_relay_log_pos: 0

Checkpoint_master_log_name:

Checkpoint_master_log_pos: 0

Checkpoint_seqno: 0

Checkpoint_group_size: 64

Checkpoint_group_bitmap:

*************************** 2. row ***************************

Id: 2

Relay_log_name:

Relay_log_pos: 0

Master_log_name:

Master_log_pos: 0

Checkpoint_relay_log_name:

Checkpoint_relay_log_pos: 0

Checkpoint_master_log_name:

Checkpoint_master_log_pos: 0

Checkpoint_seqno: 0

Checkpoint_group_size: 64

Checkpoint_group_bitmap:

*************************** 3. row ***************************

Id: 3

Relay_log_name:

Relay_log_pos: 0

Master_log_name:

Master_log_pos: 0

Checkpoint_relay_log_name:

Checkpoint_relay_log_pos: 0

Checkpoint_master_log_name:

Checkpoint_master_log_pos: 0

Checkpoint_seqno: 0

Checkpoint_group_size: 64

Checkpoint_group_bitmap:

3 rows in set (0.00 sec)

Page 11: Mysql56 replication

2. New Multi-threaded Slaves (thread 1)

MASTER

mysql> show processlist;

+----+------+--------------------------+-------+-------------+------+-----------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+

| Id | User | Host | db | Command | Time | State | Info |

+----+------+--------------------------+-------+-------------+------+-----------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+

| 5 | root | localhost | mysql | Query | 0 | init | show processlist |

| 7 | mig | db-ha-db2.daum.net:58746 | NULL | Binlog Dump | 208 | Master has sent all binlog to slave; waiting for binlog to be updated | NULL |

| 9 | root | localhost | test | Query | 1 | query end | INSERT INTO sbtest(k, c, pad) VALUES (0,' ','qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt'),(0 |

+----+------+--------------------------+-------+-------------+------+-----------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+

3 rows in set (0.00 sec)

Page 12: Mysql56 replication

2. New Multi-threaded Slaves

mysql> select * from slave_worker_info\G

*************************** 1. row ***************************

Id: 1

Relay_log_name:

Relay_log_pos: 0

Master_log_name:

Master_log_pos: 0

Checkpoint_relay_log_name:

Checkpoint_relay_log_pos: 0

Checkpoint_master_log_name:

Checkpoint_master_log_pos: 0

Checkpoint_seqno: 0

Checkpoint_group_size: 64

Checkpoint_group_bitmap:

*************************** 2. row ***************************

Id: 2

Relay_log_name:

Relay_log_pos: 0

Master_log_name:

Master_log_pos: 0

Checkpoint_relay_log_name:

Checkpoint_relay_log_pos: 0

Checkpoint_master_log_name:

Checkpoint_master_log_pos: 0

Checkpoint_seqno: 0

Checkpoint_group_size: 64

Checkpoint_group_bitmap:

*************************** 3. row ***************************

Id: 3

Relay_log_name: ./db-ha-db2-relay-bin.000013

Relay_log_pos: 34788107

Master_log_name: mysql-bin.000003

Master_log_pos: 95818597

Checkpoint_relay_log_name: ./db-ha-db2-relay-bin.000013

Checkpoint_relay_log_pos: 33567507

Checkpoint_master_log_name: mysql-bin.000003

Checkpoint_master_log_pos: 94597997

Checkpoint_seqno: 1

Checkpoint_group_size: 64

Checkpoint_group_bitmap:

3 rows in set (0.00 sec)

Page 13: Mysql56 replication

2. New Multi-threaded Slaves

mysql> select * from slave_worker_info \G

*************************** 1. row ***************************

Id: 1

Relay_log_name:

Relay_log_pos: 0

Master_log_name:

Master_log_pos: 0

Checkpoint_relay_log_name:

Checkpoint_relay_log_pos: 0

Checkpoint_master_log_name:

Checkpoint_master_log_pos: 0

Checkpoint_seqno: 0

Checkpoint_group_size: 64

Checkpoint_group_bitmap:

*************************** 2. row ***************************

Id: 2

Relay_log_name: ./db-ha-db2-relay-bin.000013

Relay_log_pos: 182013734

Master_log_name: mysql-bin.000003

Master_log_pos: 243044224

Checkpoint_relay_log_name: ./db-ha-db2-relay-bin.000013

Checkpoint_relay_log_pos: 178351946

Checkpoint_master_log_name: mysql-bin.000003

Checkpoint_master_log_pos: 239382436

Checkpoint_seqno: 5

Checkpoint_group_size: 64

Checkpoint_group_bitmap: *

*************************** 3. row ***************************

Id: 3

Relay_log_name: ./db-ha-db2-relay-bin.000013

Relay_log_pos: 181403434

Master_log_name: mysql-bin.000003

Master_log_pos: 242433924

Checkpoint_relay_log_name: ./db-ha-db2-relay-bin.000013

Checkpoint_relay_log_pos: 178351946

Checkpoint_master_log_name: mysql-bin.000003

Checkpoint_master_log_pos: 239382436

Checkpoint_seqno: 4

Checkpoint_group_size: 64

Checkpoint_group_bitmap:

3 rows in set (0.00 sec)

Page 14: Mysql56 replication

2. New Multi-threaded Slaves

빠르다!!!

Database 단위.... -_-; Distribution ???

- CPU: 2 sockets, 6 cores with hyper-threading, 2930 MHz. - OS: 64-bit Oracle Enterprise Linux 6.1

- Memory: 48 GB

- sysbench unit test with multiple schema

Page 15: Mysql56 replication

INDEX

1. New Crash-Safe Slaves

2. New Multi-threaded Slaves

3. New Time-delayed Replication

4. New Optimized Row-based Replication

5. New Replication Checksums

6. New Global Transactions Identifiers (GTIDs)

Page 16: Mysql56 replication

3. New Time-delayed Replication

mysql> stop slave;

Query OK, 0 rows affected (0.04 sec)

mysql> CHANGE MASTER TO MASTER_DELAY =60;

Query OK, 0 rows affected (0.06 sec)

mysql> start slave;

Query OK, 0 rows affected, 1 warning (0.06 sec)

Page 17: Mysql56 replication

3. New Time-delayed Replication

mysql> show slave status\G

*************************** 1. row ***************************

Master_Log_File: mysql-bin.000005

Read_Master_Log_Pos: 2652

Relay_Log_File: db-ha-db2-relay-bin.000002

Relay_Log_Pos: 314

Relay_Master_Log_File: mysql-bin.000005

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Exec_Master_Log_Pos: 2396

SQL_Delay: 60

SQL_Remaining_Delay: 33

Slave_SQL_Running_State: Waiting until MASTER_DELAY seconds after master executed event

1 row in set (0.00 sec)

Page 18: Mysql56 replication

3. New Time-delayed Replication

Drop 을 막을 수 있다…

서비스 이용에는... -_-;

Page 19: Mysql56 replication

INDEX

1. New Crash-Safe Slaves

2. New Multi-threaded Slaves

3. New Time-delayed Replication

4. New Optimized Row-based Replication

5. New Replication Checksums

6. New Global Transactions Identifiers (GTIDs)

Page 20: Mysql56 replication

4. New Optimized Row-based Replication

my.cnf

binlog_row_image=MINMAL

# default FULL

# full : Log all columns

# minimal : Log only changed columns, and columns needed to identify rows

# noblob : Log all columns, except for unneeded BLOB and TEXT columns

Page 21: Mysql56 replication

4. New Optimized Row-based Replication

mysql> reset master;

Query OK, 0 rows affected (0.08 sec)

mysql> show master status;

+------------------+----------+--------------+------------------+-------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+-------------------+

| mysql-bin.000001 | 151 | | | |

+------------------+----------+--------------+------------------+-------------------+

1 row in set (0.00 sec)

mysql> show session variables like 'binlog_row_image';

+------------------+-------+

| Variable_name | Value |

+------------------+-------+

| binlog_row_image | FULL |

+------------------+-------+

1 row in set (0.00 sec)

mysql> update sss set k=10 where id=1;

Query OK, 1 row affected (0.01 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> show master status;

+------------------+----------+--------------+------------------+----------------------------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+----------------------------------------+

| mysql-bin.000001 | 511 | | | c35b769a-8fac-11e2-a667-00a0d1e293e2:1 |

+------------------+----------+--------------+------------------+----------------------------------------+

1 row in set (0.00 sec)

Page 22: Mysql56 replication

4. New Optimized Row-based Replication

mysql> set session binlog_row_image='MINIMAL';

Query OK, 0 rows affected (0.00 sec)

mysql> reset master;

Query OK, 0 rows affected (0.01 sec)

mysql> show master status;

+------------------+----------+--------------+------------------+-------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+-------------------+

| mysql-bin.000001 | 151 | | | |

+------------------+----------+--------------+------------------+-------------------+

1 row in set (0.00 sec)

mysql> update sss set k=11 where id=1;

Query OK, 1 row affected (0.02 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> show master status;

+------------------+----------+--------------+------------------+----------------------------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+----------------------------------------+

| mysql-bin.000001 | 399 | | | c35b769a-8fac-11e2-a667-00a0d1e293e2:1 |

+------------------+----------+--------------+------------------+----------------------------------------+

1 row in set (0.00 sec)

Page 23: Mysql56 replication

4. New Optimized Row-based Replication

mysql> show session variables like 'binlog_row_image';

+------------------+-------+

| Variable_name | Value |

+------------------+-------+

| binlog_row_image | FULL |

+------------------+-------+

1 row in set (0.00 sec)mysql> update sss set k=12 where id=1;

Query OK, 1 row affected (0.01 sec)

Rows matched: 1 Changed: 1 Warnings: 0

### UPDATE `ttt`.`sss`

### WHERE

### @1=1

### @2=11

### @3=''

### @4='qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt'

### SET

### @1=1

### @2=12

### @3=''

### @4='qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt'

# at 728

mysql> show session variables like 'binlog_row_image';

+------------------+---------+

| Variable_name | Value |

+------------------+---------+

| binlog_row_image | MINIMAL |

+------------------+---------+

1 row in set (0.00 sec)mysql> update sss set k=11 where id=1;

Query OK, 1 row affected (0.02 sec)

Rows matched: 1 Changed: 1 Warnings: 0

### UPDATE `ttt`.`sss`

### WHERE

### @1=1

### SET

### @2=11

# at 368

Page 24: Mysql56 replication

4. New Optimized Row-based Replication

CREATE TABLE `t1` (

`a` int(11) NOT NULL DEFAULT '0',

`b` int(11) DEFAULT NULL,

`c` char(10) DEFAULT NULL,

PRIMARY KEY (`a`)

)

update t1 set b=10 where a=1;

### UPDATE `ttt`.`t1`

### WHERE

### @1=1

### SET

### @2=10

CREATE TABLE `t2` (

`a` int(11) NOT NULL DEFAULT '0',

`b` int(11) DEFAULT NULL,

`c` char(10) DEFAULT NULL,

PRIMARY KEY (`a`),

KEY `b` (`b`)

)

update t2 set b=10 where b=1;

### UPDATE `ttt`.`t2`

### WHERE

### @1=101

### SET

### @2=10

CREATE TABLE `t3` (

`a` int(11) DEFAULT NULL,

`b` int(11) DEFAULT NULL,

`c` char(10) DEFAULT NULL

)

update t3 set b=10 where a=1;

### UPDATE `ttt`.`t3`

### WHERE

### @1=1

### @2=100

### @3='aaaaa'

### SET

### @2=10

Page 25: Mysql56 replication

4. New Optimized Row-based Replication

스마트해진 ROW format

PK가 필요함 !!!

Page 26: Mysql56 replication

INDEX

1. New Crash-Safe Slaves

2. New Multi-threaded Slaves

3. New Time-delayed Replication

4. New Optimized Row-based Replication

5. New Replication Checksums

6. New Global Transactions Identifiers (GTIDs)

Page 27: Mysql56 replication

5. New Replication Checksums

MASTER SLAVE

binary log

relay log

I/O thread

SQL thread

Dump thread

binlog_checksum Default:CRC32 {NONE|CRC32}

master_verify_checksum Default:OFF {0|1}

slave_sql_verify_checksum Default:0 {0|1}

Page 28: Mysql56 replication

5. New Replication Checksums

mysql> show binlog events in 'mysql-bin.000007' from 191;

+------------------+-----+------------+-----------+-------------+--------------------------------------------------------------------+

| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |

+------------------+-----+------------+-----------+-------------+--------------------------------------------------------------------+

| mysql-bin.000007 | 191 | Gtid | 1234 | 239 | SET @@SESSION.GTID_NEXT= 'c35b769a-8fac-11e2-a667-00a0d1e293e2:39' |

| mysql-bin.000007 | 239 | Query | 1234 | 316 | BEGIN |

| mysql-bin.000007 | 316 | Query | 1234 | 418 | use `ttt`; insert into ttt values (12345) |

| mysql-bin.000007 | 418 | Xid | 1234 | 449 | COMMIT /* xid=1053612 */ |

+------------------+-----+------------+-----------+-------------+--------------------------------------------------------------------+

4 rows in set (0.00 sec)

Binlog 수정

mysql> show binlog events in 'mysql-bin.000007' from 191;

+------------------+-----+------------+-----------+-------------+--------------------------------------------------------------------+

| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |

+------------------+-----+------------+-----------+-------------+--------------------------------------------------------------------+

| mysql-bin.000007 | 191 | Gtid | 1234 | 239 | SET @@SESSION.GTID_NEXT= 'c35b769a-8fac-11e2-a667-00a0d1e293e2:39' |

| mysql-bin.000007 | 239 | Query | 1234 | 316 | BEGIN |

| mysql-bin.000007 | 316 | Query | 1234 | 418 | use `ttt`; insert into ttt values (12341) |

| mysql-bin.000007 | 418 | Xid | 1234 | 449 | COMMIT /* xid=1053612 */ |

+------------------+-----+------------+-----------+-------------+--------------------------------------------------------------------+

4 rows in set (0.00 sec)

mysql> SET GLOBAL MASTER_VERIFY_CHECKSUM=1;

Query OK, 0 rows affected (0.00 sec)

mysql> show binlog events in 'mysql-bin.000007' from 191;

ERROR 1220 (HY000): Error when executing command SHOW BINLOG EVENTS: Wrong offset or I/O error

#130327 20:59:04 server id 1234 end_log_pos 418 CRC32 0x171597fb Query thread_id=148 exec_time=0 error_code=0

use `ttt`/*!*/;

SET TIMESTAMP=1364385544/*!*/;

insert into ttt values (12645)

/*!*/;

# at 418

Page 29: Mysql56 replication

5. New Replication Checksums

MASTER SLAVE

binary log

relay log

I/O thread

SQL thread

Dump thread

장애부분 최소화

느려요~

Page 30: Mysql56 replication

INDEX

1. New Crash-Safe Slaves

2. New Multi-threaded Slaves

3. New Time-delayed Replication

4. New Optimized Row-based Replication

5. New Replication Checksums

6. New Global Transactions Identifiers (GTIDs)

Page 31: Mysql56 replication

6. New Global Transactions Identifiers (GTIDs)

my.cnf

log-bin

log-slave-updates

gtid-mode=ON

disable-gtid-unsafe-statements

mysql> show master status\G

*************************** 1. row ***************************

File: mysql-bin.000007

Position: 449

Binlog_Do_DB:

Binlog_Ignore_DB:

Executed_Gtid_Set: c35b769a-8fac-11e2-a667-00a0d1e293e2:1-39

1 row in set (0.00 sec)

mysql> show slave status\G

Retrieved_Gtid_Set: c35b769a-8fac-11e2-a667-00a0d1e293e2:38-45

Executed_Gtid_Set: 6873760e-8fb3-11e2-a693-00a0d1e291dc:1-2,

c35b769a-8fac-11e2-a667-00a0d1e293e2:1-61152

Page 32: Mysql56 replication

6. New Global Transactions Identifiers (GTIDs)

Page 33: Mysql56 replication

6. New Global Transactions Identifiers (GTIDs)

Page 34: Mysql56 replication
Page 35: Mysql56 replication

고맙습니다