Top Banner
café.naver.com/mysqlpg 1 Spider Architecture 날짜 : 2016.03.21 Ver. 1.0 작성 : DB실 전수진
56

Spider Setup with AWS/sandbox

Apr 10, 2017

Download

Engineering

I Goo Lee
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

1

Spider Architecture

날짜 : 2016.03.21

Ver. 1.0

작성 : DB실 전수진

Page 2: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Spider Setup

Architecture

Topology

Agenda

Page 3: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Spider Setup

Architecture

Topology

Agenda

Page 4: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Setup

Page 5: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Setup

Page 6: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Setup

■ Server Spec

Page 7: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Setup

■ MySQL Install Sandbox : http://mysqlsandbox.net/

Page 8: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Setup

■ MySQL Install Step 1. 사전 요구 프로그램 설치 sudo su - yum install -y gcc automake autoconf libtool make cpan libstdc* yum install -y perl-CPAN yum install -y --skip-broken perl* cpan YAML

Page 9: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Setup

■ MySQL Install Step 2. 그룹(mysql)/계정(maria) 생성 sudo su - mkdir -p /usr1/program mkdir -p /usr1/mysql/dba/tools groupadd -g 900 mysql cat /etc/group | grep -E 'mysql|maria' useradd maria -g mysql -d /home/maria -u 901 -c mysql_user echo 'maria:oracle' | chpasswd cat /etc/passwd | grep -E 'mysql|maria' chown -R maria:mysql /usr1 ls -l /usr1

Page 10: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Setup

■ MySQL Install Step 3. Sandbox Download & Compile sudo su - cd /usr1/program wget http://search.cpan.org/CPAN/authors/id/G/GM/GMAX/MySQL-Sandbox-3.1.05.tar.gz ls -l MySQL-Sandbox* tar xvfz MySQL-Sandbox-3.1.05.tar.gz cd MySQL-Sandbox-3.1.05 perl Makefile.PL make && make test make install

Page 11: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Setup

■ MySQL Install Step 4. MariaDB 10.1 (SpiderNode) / MySQL 5.7 (DataNode) Binary Download su - maria cd /usr1/program/ wget http://ftp.kaist.ac.kr/mariadb//mariadb-10.1.12/bintar-linux-glibc_214-x86_64/mariadb-10.1.12-linux-glibc_214-x86_64.tar.gz tar xvfz mariadb-10.1.12-linux-glibc_214-x86_64.tar.gz mv mariadb-10.1.12-linux-glibc_214-x86_64 /usr1/mysql/10.1.12 wget https://downloads.mariadb.com/archives/mysql-5.7/mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz tar zxvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz mv mysql-5.7.11-linux-glibc2.5-x86_64 /usr1/mysql/5.7.11 ls -l /usr1/mysql chown -R maria:mysql /usr1

Page 12: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Setup

■ MySQL Install Step 5. Multi Instance Install (Spider : 4, Data : 6) su - maria cd /usr1/mysql mkdir -p /usr1/mysql/sandboxes make_multiple_sandbox -r spider_node 10.1.12 --upper_directory=/usr1/mysql/sandboxes --how_many_nodes=4 make_multiple_sandbox -r data_node 5.7.11 --upper_directory=/usr1/mysql/sandboxes --how_many_nodes=6 ps -ef | awk -F ' ' '{print $2, $9;}' | grep mysqld_safe 6479 /usr1/mysql/10.1.12/bin/mysqld_safe … 7604 /usr1/mysql/5.7.11/bin/mysqld_safe … netstat -nap | grep LISTEN | grep mysql

Page 13: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Setup

■ MySQL Install Step 5. Multi Instance Install # Port 변경 (Spider Node) cd /usr1/mysql/sandboxes/spider_node && ./stop_all cd /usr1/mysql/sandboxes/spider_node/node1 && ./change_ports 3306 cd /usr1/mysql/sandboxes/spider_node/node2 && ./change_ports 3307 cd /usr1/mysql/sandboxes/spider_node/node3 && ./change_ports 9906 cd /usr1/mysql/sandboxes/spider_node/node4 && ./change_ports 9907 cd /usr1/mysql/sandboxes/spider_node && ./start_all cd /usr1/mysql/sandboxes/spider_node && ./status_all cd /usr1/mysql/sandboxes/spider_node && ./use_all -e " select version()" netstat -nap | grep LISTEN | grep mysql

3306

10001

10002

10003

Page 14: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Setup

■ MySQL Install Step 5. Multi Instance Install # Port 변경 (Data Node) cd /usr1/mysql/sandboxes/data_node && ./stop_all cd /usr1/mysql/sandboxes/data_node/node1 && ./change_ports 10001 cd /usr1/mysql/sandboxes/data_node/node2 && ./change_ports 10002 cd /usr1/mysql/sandboxes/data_node/node3 && ./change_ports 10003 cd /usr1/mysql/sandboxes/data_node/node4 && ./change_ports 20001 cd /usr1/mysql/sandboxes/data_node/node5 && ./change_ports 20002 cd /usr1/mysql/sandboxes/data_node/node6 && ./change_ports 20003 cd /usr1/mysql/sandboxes/data_node && ./start_all cd /usr1/mysql/sandboxes/data_node && ./status_all cd /usr1/mysql/sandboxes/data_node && ./use_all -e " select version()" netstat -nap | grep LISTEN | grep mysql

3306

10001

10002

10003

Page 15: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Setup

■ MySQL Install Step 6. Define an easy way to access the nodes from the MariaDB or MySQL client su - maria alias spider1='/usr1/mysql/10.1.12/bin/mysql --user=msandbox --password=msandbox --host=localhost --port=3306 --socket=/tmp/mysql_sandbox3306.sock' alias spider2='/usr1/mysql/10.1.12/bin/mysql --user=msandbox --password=msandbox --host=localhost --port=3307 --socket=/tmp/mysql_sandbox3307.sock' alias spider3='/usr1/mysql/10.1.12/bin/mysql --user=msandbox --password=msandbox --host=localhost --port=9906 --socket=/tmp/mysql_sandbox9906.sock' alias spider4='/usr1/mysql/10.1.12/bin/mysql --user=msandbox --password=msandbox --host=localhost --port=9907 --socket=/tmp/mysql_sandbox9907.sock' alias backend1='/usr1/mysql/5.7.11/bin/mysql --user=msandbox --password=msandbox --host=localhost --port=10001 --socket=/tmp/mysql_sandbox10001.sock' alias backend2='/usr1/mysql/5.7.11/bin/mysql --user=msandbox --password=msandbox --host=localhost --port=10002 --socket=/tmp/mysql_sandbox10002.sock' alias backend3='/usr1/mysql/5.7.11/bin/mysql --user=msandbox --password=msandbox --host=localhost --port=10003 --socket=/tmp/mysql_sandbox10003.sock' alias backend11='/usr1/mysql/5.7.11/bin/mysql --user=msandbox --password=msandbox --host=localhost --port=20001 --socket=/tmp/mysql_sandbox20001.sock' alias backend12='/usr1/mysql/5.7.11/bin/mysql --user=msandbox --password=msandbox --host=localhost --port=20002 --socket=/tmp/mysql_sandbox20002.sock' alias backend13='/usr1/mysql/5.7.11/bin/mysql --user=msandbox --password=msandbox --host=localhost --port=20003 --socket=/tmp/mysql_sandbox20003.sock'

$ spider1 -e "select version()" +-----------------+ | version() | +-----------------+ | 10.1.12-MariaDB | +-----------------+

$ backend1 -e "select version()" +------------+ | version() | +------------+ | 5.7.11-log | +------------+

Page 16: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Setup

■ MySQL Install Step 6. Define an easy way to access the nodes from the MariaDB or MySQL client su – maria cd /usr1/mysql/dba

Page 17: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Setup

Spider_node general_log

data_node1 general_log

data_node2 general_log

Page 18: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Setup

Page 19: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Spider Setup

Architecture

Topology

Agenda

Page 20: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ Type Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

# Federation # Sharding # High Availability

Page 21: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ Federation Without connection pool or MariaDB thread pool, HaProxy and Spider have been protecting the tcp socket overflow without specific TCP tuning.

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

backend1 << EOF DROP DATABASE IF EXISTS backend ; CREATE DATABASE backend; CREATE TABLE backend.sbtest ( id int unsigned NOT NULL AUTO_INCREMENT , k int unsigned NOT NULL DEFAULT '0' , c char(100) NOT NULL DEFAULT '' , pad char(60) NOT NULL DEFAULT '' , PRIMARY KEY (id) , KEY k (k) ) ENGINE=InnoDB; DESC backend.sbtest; EOF

Page 22: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ Federation

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

spider1 << EOF DROP SERVER IF EXISTS backend1; CREATE SERVER backend1 FOREIGN DATA WRAPPER mysql OPTIONS( HOST '127.0.0.1‘ , DATABASE 'backend‘ , USER 'msandbox‘ , PASSWORD 'msandbox‘ , PORT 10001); EOF ②

Page 23: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ Federation

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

spider1 << EOF CREATE DATABASE IF NOT EXISTS test; DROP TABLE IF EXISTS test.sbtest; CREATE TABLE test.sbtest ( id int unsigned NOT NULL AUTO_INCREMENT , k int unsigned NOT NULL DEFAULT '0' , c char(100) NOT NULL DEFAULT '' , pad char(60) NOT NULL DEFAULT '' , PRIMARY KEY (id) , KEY k (k) ) ENGINE=spider COMMENT='wrapper "mysql",srv "backend1"'; SELECT * FROM test.sbtest LIMIT 10; EOF

Page 24: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ Federation & HA

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

backend1 << EOF CREATE TABLE backend.sbtest ( id int unsigned NOT NULL AUTO_INCREMENT , k int unsigned NOT NULL DEFAULT '0' , c char(100) NOT NULL DEFAULT '' , pad char(60) NOT NULL DEFAULT '' , PRIMARY KEY (id) , KEY k (k) ) ENGINE=InnoDB; EOF backend2 << EOF … EOF backend3 << EOF … EOF

① ①

Page 25: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

spider1 << EOF CREATE SERVER backend1 FOREIGN DATA WRAPPER mysql OPTIONS( HOST '127.0.0.1‘ , DATABASE 'backend‘ , USER 'msandbox‘ , PASSWORD 'msandbox‘ , PORT 10001); CREATE SERVER backend2 FOREIGN DATA WRAPPER mysql … CREATE SERVER backend3 FOREIGN DATA WRAPPER mysql … EOF

■ Federation & HA

Page 26: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

spider1 << EOF CREATE DATABASE IF NOT EXISTS test; DROP TABLE IF EXISTS test.sbtest; CREATE TABLE test.sbtest ( id int unsigned NOT NULL AUTO_INCREMENT , k int unsigned NOT NULL DEFAULT '0' , c char(100) NOT NULL DEFAULT '' , pad char(60) NOT NULL DEFAULT '' , PRIMARY KEY (id) , KEY k (k) ) ENGINE=spider COMMENT='wrapper "mysql",srv "backend1 backend2 backend3"'; SELECT * FROM test.sbtest LIMIT 10; EOF

■ Federation & HA

Page 27: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

spider1 << EOF TRUNCATE TABLE test.sbtest; Insert into test.sbtest values (1, 100, 'A', 'A1'); Insert into test.sbtest values (2, 200, 'A', 'A1'); Insert into test.sbtest values (3, 300, 'A', 'A1'); Insert into test.sbtest values (4, 400, 'A', 'A1'); Insert into test.sbtest values (5, 500, 'A', 'A1'); SELECT * FROM test.sbtest;

EOF backend1 -e"select count(*) from backend.sbtest;" backend2 -e"select count(*) from backend.sbtest;" backend3 -e"select count(*) from backend.sbtest;" +----------+ | count(*) | +----------+ | 5 | +----------+

■ Federation & HA

동일한 데이터를 확인할 수 있음 !

Page 28: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

cd /usr1/mysql/sandboxes/data_node/node2 && ./stop spider1 -e "Insert into test.sbtest values (11, 1100, 'A', 'A1');" -- ERROR 1429 (HY000) at line 1: Unable to connect to foreign data source: backend2 backend1 -e"select count(*) from backend.sbtest;" -- 5 backend2 -e"select count(*) from backend.sbtest;" -- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql_sandbox10002.sock' (2) backend3 -e"select count(*) from backend.sbtest;" -- 5

■ Federation & HA

Datanode2 장애유발!

Page 29: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

■ Federation & HA

spider1 << EOF DROP TABLE IF EXISTS test.sbtest; CREATE TABLE test.sbtest ( id int unsigned NOT NULL AUTO_INCREMENT , k int unsigned NOT NULL DEFAULT '0' , c char(100) NOT NULL DEFAULT '' , pad char(60) NOT NULL DEFAULT '' , PRIMARY KEY (id) , KEY k (k) ) ENGINE=spider COMMENT='wrapper "mysql",srv "backend1 backend3"'; EOF spider1 -e "Insert into test.sbtest values (11, 1100, 'A', 'A1');" backend1 -e"select count(*) from backend.sbtest;" backend3 -e"select count(*) from backend.sbtest;" -- 6 -- 6

복구방법 :

테이블의 정의를 변경함

으로써 빠르게 복구 가능

Page 30: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

backend1 << EOF CREATE TABLE backend.sbtest ( id int unsigned NOT NULL AUTO_INCREMENT , k int unsigned NOT NULL DEFAULT '0' , c char(100) NOT NULL DEFAULT '' , pad char(60) NOT NULL DEFAULT '' , PRIMARY KEY (id) , KEY k (k) ) ENGINE=InnoDB;

EOF

backend2 << EOF CREATE TABLE backend.sbtest ( id int unsigned NOT NULL AUTO_INCREMENT , k int unsigned NOT NULL DEFAULT '0' , c char(100) NOT NULL DEFAULT '' , pad char(60) NOT NULL DEFAULT '' , PRIMARY KEY (id) , KEY k (k) ) ENGINE=InnoDB;

EOF

■ Sharding Data Sharding

② ①

Page 31: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ Sharding

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

spider1 << EOF CREATE SERVER backend1 FOREIGN DATA WRAPPER mysql OPTIONS( HOST '127.0.0.1‘ , DATABASE 'backend‘ , USER 'msandbox‘ , PASSWORD 'msandbox‘ , PORT 10001); CREATE SERVER backend2 FOREIGN DATA WRAPPER mysql OPTIONS( HOST '127.0.0.1‘ , DATABASE 'backend‘ , USER 'msandbox‘ , PASSWORD 'msandbox‘ , PORT 10002); EOF

③ ④

Page 32: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ Sharding

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

spider1 << EOF CREATE DATABASE IF NOT EXISTS test; CREATE TABLE test.sbtest ( id int unsigned NOT NULL AUTO_INCREMENT , k int unsigned NOT NULL DEFAULT '0' , c char(100) NOT NULL DEFAULT '' , pad char(60) NOT NULL DEFAULT '' , PRIMARY KEY (id) , KEY k (k) ) ENGINE=spider COMMENT='wrapper "mysql", table "sbtest"'

PARTITION BY KEY (id) ( PARTITION pt1 COMMENT = 'srv "backend1"' , PARTITION pt2 COMMENT = 'srv "backend2"' ); SELECT count(*) FROM test.sbtest LIMIT 10; EOF

Page 33: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ Sharding

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

spider1 << EOF TRUNCATE TABLE test.sbtest; Insert into test.sbtest values (1, 100, 'A', 'A1'); Insert into test.sbtest values (2, 200, 'A', 'A1'); Insert into test.sbtest values (3, 300, 'A', 'A1'); Insert into test.sbtest values (4, 400, 'A', 'A1'); Insert into test.sbtest values (5, 500, 'A', 'A1'); SELECT * FROM test.sbtest; EOF

backend1 -e"select count(*) from backend.sbtest;"

-- 3

backend2 -e"select count(*) from backend.sbtest;"

-- 2

Page 34: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ High Availability

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

backend1 << EOF CREATE TABLE backend.sbtest ( id int unsigned NOT NULL AUTO_INCREMENT , k int unsigned NOT NULL DEFAULT '0' , c char(100) NOT NULL DEFAULT '' , pad char(60) NOT NULL DEFAULT '' , PRIMARY KEY (id) , KEY k (k) ) ENGINE=InnoDB; CREATE TABLE backend_rpl.sbtest ( id int unsigned NOT NULL AUTO_INCREMENT , k int unsigned NOT NULL DEFAULT '0' , c char(100) NOT NULL DEFAULT '' , pad char(60) NOT NULL DEFAULT '' , PRIMARY KEY (id) , KEY k (k) ) ENGINE=InnoDB;

EOF

backend2 << EOF CREATE TABLE backend.sbtest ( id int unsigned NOT NULL AUTO_INCREMENT , k int unsigned NOT NULL DEFAULT '0' , c char(100) NOT NULL DEFAULT '' , pad char(60) NOT NULL DEFAULT '' , PRIMARY KEY (id) , KEY k (k) ) ENGINE=InnoDB; CREATE TABLE backend_rpl.sbtest ( id int unsigned NOT NULL AUTO_INCREMENT , k int unsigned NOT NULL DEFAULT '0' , c char(100) NOT NULL DEFAULT '' , pad char(60) NOT NULL DEFAULT '' , PRIMARY KEY (id) , KEY k (k) ) ENGINE=InnoDB;

EOF

② ①

back1 back1_rpl back2 back2_rpl

Page 35: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ High Availability

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

spider1 << EOF CREATE SERVER backend1 FOREIGN DATA WRAPPER mysql OPTIONS( HOST '127.0.0.1‘, DATABASE 'backend‘ , … , PORT 10001); CREATE SERVER backend1_rpl FOREIGN DATA WRAPPER mysql OPTIONS( HOST '127.0.0.1‘, DATABASE 'backend_rpl‘, … , PORT 10001); CREATE SERVER backend2 FOREIGN DATA WRAPPER mysql OPTIONS( HOST '127.0.0.1‘, DATABASE 'backend‘ , … , PORT 10002); CREATE SERVER backend2_rpl FOREIGN DATA WRAPPER mysql OPTIONS( HOST '127.0.0.1‘, DATABASE 'backend_rpl‘, … , PORT 10002); EOF

back1 back1_rpl back2 back2_rpl

④ ③

Page 36: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ High Availability

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

back1 back1_rpl back2 back2_rpl

spider1 << EOF CREATE DATABASE IF NOT EXISTS test; CREATE TABLE test.sbtest ( id int unsigned NOT NULL AUTO_INCREMENT , k int unsigned NOT NULL DEFAULT '0' , c char(100) NOT NULL DEFAULT '' , pad char(60) NOT NULL DEFAULT '' , PRIMARY KEY (id) , KEY k (k) ) ENGINE=spider COMMENT='wrapper "mysql", table "sbtest"' PARTITION BY KEY (id) ( PARTITION pt1 COMMENT = 'srv "backend1 backend2_rpl"' , PARTITION pt2 COMMENT = 'srv "backend2 backend1_rpl"' ); INSERT INTO test.sbtest select 10000001, 0, '' ,'replicas test'; EOF

Page 37: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ High Availability

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

back1 back1_rpl back2 back2_rpl

backend1 -e "SELECT * FROM backend.sbtest WHERE id=10000001"; +----------+---+---+---------------+ | id | k | c | pad | +----------+---+---+---------------+ | 10000001 | 0 | | replicas test | +----------+---+---+---------------+ backend2 -e "SELECT * FROM backend.sbtest where id=10000001"; backend2 -e "SELECT * FROM backend_rpl.sbtest where id=10000001"; +----------+---+---+---------------+ | id | k | c | pad | +----------+---+---+---------------+ | 10000001 | 0 | | replicas test | +----------+---+---+---------------+

Page 38: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ High Availability

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

back1 back1_rpl back2 back2_rpl

spider1 << EOF insert into test.sbtest values (1, 100, 'A', 'A1'); insert into test.sbtest values (2, 200, 'A', 'A1'); insert into test.sbtest values (3, 300, 'A', 'A1'); insert into test.sbtest values (4, 400, 'A', 'A1'); insert into test.sbtest values (5, 500, 'A', 'A1'); EOF backend1 -e "select (select count(*) from backend.sbtest) as cnt1 , (select count(*) from backend_rpl.sbtest) as cnt2" +------+------+ | cnt1 | cnt2 | +------+------+ | 4 | 2 | +------+------+

backend2 -e "select (select count(*) from backend.sbtest) as cnt1 , (select count(*) from backend_rpl.sbtest) as cnt2" +------+------+ | cnt1 | cnt2 | +------+------+ | 2 | 4 | +------+------+

4 4 2 2

Page 39: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ High Availability What is happening if we stop one backend?

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

back1 back1_rpl back2 back2_rpl

spider1 -e "SELECT * FROM test.sbtest where id=10000001"; +----------+---+---+---------------+ | id | k | c | pad | +----------+---+---+---------------+ | 10000001 | 0 | | replicas test | +----------+---+---+---------------+

cd /usr1/mysql/sandboxes/data_node/node1 && ./stop backend1 -e "SELECT * FROM backend.sbtest where id=10000001" -- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql_sandbox10001.sock'

spider1 -e "SELECT * FROM test.sbtest where id=10000001"; -- ERROR 1429 (HY000): Unable to connect to foreign data source: backend1_rpl

spider1 -e "SELECT * from mysql.spider_tables order by link_id, server";

cd /usr1/mysql/sandboxes/data_node/node1 && ./start spider1 -e "SELECT * FROM test.sbtest where id=10000001"; +----------+---+---+---------------+ | id | k | c | pad | +----------+---+---+---------------+ | 10000001 | 0 | | replicas test | +----------+---+---+---------------+

4 4 2 2

Page 40: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ High Availability What is happening if we stop one backend?

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

back1 back1_rpl back2 back2_rpl

-- Data Node Replica 모니터링 등록

spider1 << EOF DROP TABLE IF EXISTS test.sbtest; CREATE TABLE test.sbtest ( id int unsigned NOT NULL AUTO_INCREMENT … ) ENGINE=spider COMMENT='wrapper "mysql", table "sbtest"' PARTITION BY KEY (id) ( PARTITION pt1 COMMENT = 'srv "backend1 backend2_rpl", mbk "2", mkd "2", msi "1", link_status "0 0"' , PARTITION pt2 COMMENT = 'srv "backend2 backend1_rpl", mbk "2", mkd "2", msi "1", link_status "0 0"'

); CREATE SERVER mon FOREIGN DATA WRAPPER mysql OPTIONS ( HOST '127.0.0.1', DATABASE 'test', … , PORT 3306); INSERT INTO mysql.spider_link_mon_servers VALUES ('%','%','%',1,'mon‘ ,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,NULL,NULL); SELECT * FROM mysql.spider_link_mon_servers; SELECT spider_flush_table_mon_cache();

EOF

HA 모니터링을 관장할

서버의 @@Service_ID

- Spider_Node : 1, 2

- Data_Node : 101, 102

Node Status

1 : 정상, 3 : 중지

2 : 관리 작업 중

@@server_id = 1

@@server_id = 101 @@server_id = 102

Page 41: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ High Availability What is happening if we stop one backend?

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

back1 back1_rpl back2 back2_rpl

spider1 -e "SELECT * FROM test.sbtest where id=10000001"; +----------+---+---+---------------+ | id | k | c | pad | +----------+---+---+---------------+ | 10000001 | 0 | | replicas test | +----------+---+---+---------------+

cd /usr1/mysql/sandboxes/data_node/node1 && ./stop backend1 -e "SELECT * FROM backend.sbtest where id=10000001" -- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql_sandbox10001.sock'

spider1 -e "SELECT * FROM test.sbtest where id=10000001"; +----------+---+---+---------------+ | id | k | c | pad | +----------+---+---+---------------+ | 10000001 | 0 | | replicas test | +----------+---+---+---------------+

spider1 -e "SELECT * from mysql.spider_tables order by link_id, server"; +---------+--------------+--------------+-------------+ | link_id | server | table_name | link_status | +---------+--------------+--------------+-------------+ | 0 | backend1 | sbtest#P#pt1 | 3 | | 1 | backend1_rpl | sbtest#P#pt2 | 3 | | 0 | backend2 | sbtest#P#pt2 | 1 | | 1 | backend2_rpl | sbtest#P#pt1 | 1 | +---------+--------------+--------------+-------------+

데이터 조회는 되었지만,

실제는 fail 상태로 존재함

Page 42: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ High Availability What is happening if we stop one backend?

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

back1 back1_rpl back2 back2_rpl

cd /usr1/mysql/sandboxes/data_node/node1 && ./start spider1 << EOF select * from mysql.spider_tables order by link_id, server, table_name; -- link status 변경 : fail -> maintenance ALTER TABLE test.sbtest ENGINE=spider COMMENT='wrapper "mysql", table "sbtest"' PARTITION BY KEY (id) ( PARTITION pt1 COMMENT = 'srv "backend1 backend2_rpl", mbk "2", mkd "2", msi "1", link_status "2 0"' , PARTITION pt2 COMMENT = 'srv "backend2 backend1_rpl", mbk "2", mkd "2", msi "1", link_status "0 2"'

); select * from mysql.spider_tables order by link_id, server, table_name; +---------+--------------+--------------+-------------+ | link_id | server | table_name | link_status | +---------+--------------+--------------+-------------+ | 0 | backend1 | sbtest#P#pt1 | 2 | | 1 | backend1_rpl | sbtest#P#pt2 | 2 | | 0 | backend2 | sbtest#P#pt2 | 1 | | 1 | backend2_rpl | sbtest#P#pt1 | 1 | +---------+--------------+--------------+-------------+

Page 43: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ High Availability What is happening if we stop one backend?

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

back1 back1_rpl back2 back2_rpl

select * from mysql.spider_tables order by link_id, server, table_name; +---------+--------------+--------------+-------------+ | link_id | server | table_name | link_status | +---------+--------------+--------------+-------------+ | 0 | backend1 | sbtest#P#pt1 | 2 | | 1 | backend1_rpl | sbtest#P#pt2 | 2 | | 0 | backend2 | sbtest#P#pt2 | 1 | | 1 | backend2_rpl | sbtest#P#pt1 | 1 | +---------+--------------+--------------+-------------+

select spider_copy_tables('test.sbtest#P#pt1','1','0'); -- 1

select spider_copy_tables('test.sbtest#P#pt2','0','1'); -- 1

Page 44: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ High Availability What is happening if we stop one backend?

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

back1 back1_rpl back2 back2_rpl

-- link status 변경 : maintenance -> live ALTER TABLE test.sbtest ENGINE=spider COMMENT='wrapper "mysql", table "sbtest"' PARTITION BY KEY (id) ( PARTITION pt1 COMMENT = 'srv "backend1 backend2_rpl", mbk "2", mkd "2", msi "1", link_status "1 0"' , PARTITION pt2 COMMENT = 'srv "backend2 backend1_rpl", mbk "2", mkd "2", msi "1", link_status "0 1"'

); select * from mysql.spider_tables order by link_id, server, table_name; +---------+--------------+--------------+-------------+ | link_id | server | table_name | link_status | +---------+--------------+--------------+-------------+ | 0 | backend1 | sbtest#P#pt1 | 1 | | 1 | backend1_rpl | sbtest#P#pt2 | 1 | | 0 | backend2 | sbtest#P#pt2 | 1 | | 1 | backend2_rpl | sbtest#P#pt1 | 1 | +---------+--------------+--------------+-------------+

Page 45: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ High Availability

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

back1 back1_rpl back2 back2_rpl

spider1 << EOF insert into test.sbtest values (1, 100, 'A', 'A1'); insert into test.sbtest values (2, 200, 'A', 'A1'); insert into test.sbtest values (3, 300, 'A', 'A1'); insert into test.sbtest values (4, 400, 'A', 'A1'); insert into test.sbtest values (5, 500, 'A', 'A1'); EOF backend1 -e "select (select count(*) from backend.sbtest) as cnt1 , (select count(*) from backend_rpl.sbtest) as cnt2" +------+------+ | cnt1 | cnt2 | +------+------+ | 4 | 2 | +------+------+

backend2 -e "select (select count(*) from backend.sbtest) as cnt1 , (select count(*) from backend_rpl.sbtest) as cnt2" +------+------+ | cnt1 | cnt2 | +------+------+ | 2 | 4 | +------+------+

Page 46: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ High Availability

Reference : https://mariadb.com/kb/en/mariadb/spider-storage-engine-overview/

select link_id, server, table_name, link_status from mysql.spider_tables order by link_id, server, table_name

Page 47: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

■ High Availability

Page 48: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Architecture

Page 49: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Spider Setup

Architecture

Topology

Agenda

Page 50: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Topology

FrontDB

Master1 Slave1

Master2 Slave2

Master3 Slave3

Page 51: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Topology

FrontDB

Master1 Slave1

Master2 Slave2

Master3 Slave3

Master1 Slave1

Master2 Slave2

Master3 Slave3

CollectDB (ETL)

Page 52: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Topology

Master1 Slave1

Master2 Slave2

Master3 Slave3

FrontDB1

FrontDB2

CollectDB1 (admintool)

CollectDB2 (ETL)

Page 53: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Topology

Master3 Master3a

Master1 Master1a

Master2 Master2a

FrontDB1

FrontDB2

CollectDB

FrontDB

Master1 Slave1

Master2 Slave2

Master3 Slave3

Master1 Slave1

Master2 Slave2

Master3 Slave3

CollectDB (ETL)

Master1 Slave1

Master2 Slave2

Master3 Slave3

FrontDB1

FrontDB2

CollectDB1 (admintool)

CollectDB2 (ETL)

Page 54: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Topology

FrontDB

Master1 Slave1

Master2 Slave2

Master3 Slave3

Master1 Slave1

Master2 Slave2

Master3 Slave3

Master1 Slave1

Master2 Slave2

Master3 Slave3

FrontDB1

FrontDB2

Master1

Master1a

Master2

MAster2a

Master3

Master3a

FrontDB1

FrontDB2 &

CollectDB

CollectDB (ETL)

CollectDB1 (admintool)

CollectDB2 (ETL)

Master3 Master3a

Master1 Master1a

Master2 Master2a

FrontDB1

FrontDB2

Page 55: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg

Topology

FrontShard1 FrontShard2

Master1 Master1a

Master2 MAster2a

Spec : 12Core / 32GB

Spider : 1GB

Data1 : 6GB

Data2 : 6GB

DB Connection 수에 주의 !!!

Dev, QA Live 1단계

FrontShard1 FrontShard2

Master1 Master1a

Master2 MAster2a

DB 부하 및 서비스 오픈 전략에 맞춰 서버 배치 진행

Live 2단계

Page 56: Spider Setup with AWS/sandbox

café.naver.com/mysqlpg