MariaDB 10.0.10 㨠Spider ã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ã使ã£ã¦ã¿ã
MySQL ã® Sharding ç¨ã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ã§ãã Spider ã試ãã¦ã¿ã¾ããã
å
¬å¼ã®ãã¤ããªã«å梱ããã¦ãã MariaDB 10.0.10 ã使ã£ã¦ãã¾ãã
試ããç°å¢ã¯ CentOS 6.5 x86_64 ã§ãã
MariaDB ã®ã¤ã³ã¹ãã¼ã«
ã¾ã㯠MariaDB ãã¤ã³ã¹ãã¼ã«ããããã«ãyum ãªãã¸ããªå®ç¾©ãã¡ã¤ã«ãä½æãã¾ãã
# vi /etc/yum.repos.d/mariadb.repo
å 容ã¯ä»¥ä¸ã
# MariaDB 10.0 CentOS repository list - created 2014-04-02 07:21 UTC # http://mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.0/centos6-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 enable=0
ä¿åããã以ä¸ã®ããã« yum ã³ãã³ãã§ã¤ã³ã¹ãã¼ã«ãã¾ãã
# yum install -y --enablerepo=mariadb MariaDB-server MariaDB-client
ãã㧠MariaDB æ¬ä½ã®ã¤ã³ã¹ãã¼ã«ã¯å®äºã
mysqld_multi ã®è¨å®
Sharding ã試ãã®ã«è¤æ°å°ä»®æ³æ©ãç¨æãã¦ããããã§ãããä»åã¯æ¨æºã§ä»å±ãã¦ãã mysqld_multi ã³ãã³ãã使ç¨ãã¦è¤æ°ã¤ã³ã¹ã¿ã³ã¹ãç¨æãã¾ããã
ã¾ã㯠/etc/my.cnf.d/server.cnf ãç·¨éãã¾ãã
# vi /etc/my.cnf.d/server.cnf
mysqld ã»ã¯ã·ã§ã³ã«æåã³ã¼ãã®è¨å®ã追è¨ãã¦ããã¾ãã
[mysqld] character-set-server = utf8
次㯠/etc/my.cnf ãç·¨éã
# vi /etc/my.cnf
以ä¸ã追è¨ãã¾ãã
[mysqld_multi] mysqld = /usr/bin/mysqld_safe mysqladmin = /usr/bin/mysqladmin log = /var/lib/mysql/multi.log [mysqld1] port = 3306 datadir = /var/lib/mysql1 pid-file = /var/lib/mysql1/mysql.pid socket = /var/lib/mysql1/mysql.sock [mysqld2] port = 3307 datadir = /var/lib/mysql2 pid-file = /var/lib/mysql2/mysql.pid socket = /var/lib/mysql2/mysql.sock [mysqld3] port = 3308 datadir = /var/lib/mysql3 pid-file = /var/lib/mysql3/mysql.pid socket = /var/lib/mysql3/mysql.sock
æå㯠server.cnf ã¨åãæ§ã«å¥ãã¡ã¤ã«ã my.cnf.d 以ä¸ã«ä½æããããã« mysqld_multi ç¨ã®è¨å®ãæ¸ãã¦ã¿ãã®ã§ãããã©ããä½ãééã£ã¦ããã®ã mysqld_multi ãè¨å®ãä¸æãèªèãã¦ãããªãã£ãã®ã§ãããããªã /etc/my.cnf å ã«ç´æ¥è¨è¿°ãã¾ããã
è¨å®ãã¡ã¤ã«ãä¿åãããåã¤ã³ã¹ã¿ã³ã¹ç¨ã® datadir ãä½æãã¾ãã
# mysql_install_db --datadir=/var/lib/mysql1 --user=mysql # mysql_install_db --datadir=/var/lib/mysql2 --user=mysql # mysql_install_db --datadir=/var/lib/mysql3 --user=mysql # chown -R mysql:mysql /var/lib/mysql1 /var/lib/mysql2 /var/lib/mysql3
ããã§æºåã¯ã§ããã®ã§ã¤ã³ã¹ã¿ã³ã¹ãèµ·åãã¾ãã
# mysqld_multi start
ã³ã³ã½ã¼ã«ã«ã¯ä½ãåºã¾ããããããã»ã¹çã確èªããã¨ã¡ããã¨ä¸ã¤ã®ã¤ã³ã¹ã¿ã³ã¹ãèµ·åãã¦ããäºãåããã¾ãã
# ps -ef | grep [m]ysqld root 5963 1 0 21:41 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --port=3306 --datadir=/var/lib/mysql1 --pid-file=/var/lib/mysql1/mysql.pid --socket=/var/lib/mysql1/mysql.sock root 5970 1 0 21:41 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --port=3307 --datadir=/var/lib/mysql2 --pid-file=/var/lib/mysql2/mysql.pid --socket=/var/lib/mysql2/mysql.sock root 5983 1 0 21:41 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --port=3308 --datadir=/var/lib/mysql3 --pid-file=/var/lib/mysql3/mysql.pid --socket=/var/lib/mysql3/mysql.sock mysql 6364 5963 0 21:41 pts/0 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql1 --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql1/mariadb.err --pid-file=/var/lib/mysql1/mysql.pid --socket=/var/lib/mysql1/mysql.sock --port=3306 mysql 6366 5970 0 21:41 pts/0 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql2 --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql2/mariadb.err --pid-file=/var/lib/mysql2/mysql.pid --socket=/var/lib/mysql2/mysql.sock --port=3307 mysql 6372 5983 0 21:41 pts/0 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql3 --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql3/mariadb.err --pid-file=/var/lib/mysql3/mysql.pid --socket=/var/lib/mysql3/mysql.sock --port=3308 # netstat -tln | grep 330* tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:3308 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
ãã㧠MariaDB ã®æºåãåºæ¥ã¾ããã
Spider ãã¤ã³ã¹ãã¼ã«
ããã§ã¯ä¸ã¤ç®ã®ã¤ã³ã¹ã¿ã³ã¹(mysqld1) ã Spider ãã¼ãã¨ãã¦åããããã¨æãã¾ãã
mysql ã³ãã³ã㧠mysqld1 ã® sock ãã¡ã¤ã«ãæå®ãã¦æ¥ç¶ã
# mysql -uroot --socket=/var/lib/mysql1/mysql.sock
install_spider.sql ãå®è¡ã㦠Spider ã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ãã¤ã³ã¹ãã¼ã«ãã¾ãã
install_spider.sql 㯠/usr/share/mysql/ ã®ä¸ã«ããã¾ãã
MariaDB [(none)]> source /usr/share/mysql/install_spider.sql
SHOW ENGINES ã§è¿½å ããããã¨ã確èªãã¾ãã
MariaDB [(none)]> SHOW ENGINES; +--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+ | Engine | Support | Comment | Transactions | XA | Savepoints | +--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+ | SPIDER | YES | Spider storage engine | YES | YES | NO | | MRG_MyISAM | YES | Collection of identical MyISAM tables | NO | NO | NO | | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO | | BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO | | MyISAM | YES | MyISAM storage engine | NO | NO | NO | | InnoDB | DEFAULT | Percona-XtraDB, Supports transactions, row-level locking, and foreign keys | YES | YES | YES | | ARCHIVE | YES | Archive storage engine | NO | NO | NO | | FEDERATED | YES | FederatedX pluggable storage engine | YES | NO | YES | | PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO | | Aria | YES | Crash-safe tables with MyISAM heritage | NO | NO | NO | | CSV | YES | CSV storage engine | NO | NO | NO | +--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
ãã¼ã¿ãã¼ã(mysqld2, mysqld3) ã SERVER ã¨ãã¦ç»é²ãã¾ãã
MariaDB [(none)]> CREATE SERVER mysqld2 FOREIGN DATA WRAPPER mysql OPTIONS (USER 'spider', PASSWORD 'spider', HOST '127.0.0.1', PORT 3307); MariaDB [(none)]> CREATE SERVER mysqld3 FOREIGN DATA WRAPPER mysql OPTIONS (USER 'spider', PASSWORD 'spider', HOST '127.0.0.1', PORT 3308);
æ£å¸¸ã«ä½æãããäºã確èªã
MariaDB [(none)]> SELECT * FROM mysql.servers; +-------------+-----------+----+----------+----------+------+--------+---------+-------+ | Server_name | Host | Db | Username | Password | Port | Socket | Wrapper | Owner | +-------------+-----------+----+----------+----------+------+--------+---------+-------+ | mysqld2 | 127.0.0.1 | | spider | spider | 3307 | | mysql | | | mysqld3 | 127.0.0.1 | | spider | spider | 3308 | | mysql | | +-------------+-----------+----+----------+----------+------+--------+---------+-------+
ä¸æ¦ mysqld1 ãæãã¦ãSpider ç¨ã® DB ã¨ã¦ã¼ã¶ãåã¤ã³ã¹ã¿ã³ã¹ã«ä½æãã¾ãã
# mysql -uroot --socket=/var/lib/mysql1/mysql.sock -e "CREATE DATABASE example_db; GRANT ALL PRIVILEGES ON *.* TO 'spider'@'localhost' IDENTIFIED BY 'spider'; FLUSH PRIVILEGES;" # mysql -uroot --socket=/var/lib/mysql2/mysql.sock -e "CREATE DATABASE example_db; GRANT ALL PRIVILEGES ON *.* TO 'spider'@'localhost' IDENTIFIED BY 'spider'; FLUSH PRIVILEGES;" # mysql -uroot --socket=/var/lib/mysql3/mysql.sock -e "CREATE DATABASE example_db; GRANT ALL PRIVILEGES ON *.* TO 'spider'@'localhost' IDENTIFIED BY 'spider'; FLUSH PRIVILEGES;"
ä½æãã example_db ãæå®ãã¦å度 mysqld1 ã«æ¥ç¶ã
# mysql -uroot --socket=/var/lib/mysql1/mysql.sock example_db
example_db ä¸ã« SPIDER ã¨ã³ã¸ã³ãæå®ãã以ä¸ã®ãããªãã¹ãç¨ã®ãã¼ãã«ãä½æãã¾ãã
CREATE TABLE books ( id int AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, price int(11) NOT NULL default 0, created_at DATETIME NOT NULL, updated_at DATETIME, lock_version int(11) NOT NULL default 0, PRIMARY KEY (id) ) ENGINE = SPIDER DEFAULT CHARSET=utf8 PARTITION BY HASH(id) ( PARTITION p1 comment 'server "mysqld2", table "books"', PARTITION p2 comment 'server "mysqld3", table "books"' );
mysqld2, mysqld3 ã«ã¯åããã¼ãã«ã InnoDB ã§ä½æãã¾ãã
- mysqld2
# mysql -uroot --socket=/var/lib/mysql2/mysql.sock example_db
CREATE TABLE books ( id int AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, price int(11) NOT NULL default 0, created_at DATETIME NOT NULL, updated_at DATETIME, lock_version int(11) NOT NULL default 0, PRIMARY KEY (id) ) ENGINE = InnoDB DEFAULT CHARSET=utf8;
- mysqld3
# mysql -uroot --socket=/var/lib/mysql3/mysql.sock example_db
CREATE TABLE books ( id int AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, price int(11) NOT NULL default 0, created_at DATETIME NOT NULL, updated_at DATETIME, lock_version int(11) NOT NULL default 0, PRIMARY KEY (id) ) ENGINE = InnoDB DEFAULT CHARSET=utf8;
mysqld1 ã«æ¥ç¶ãããã¹ããã¼ã¿ãæå ¥ãã¦ã¿ã¾ãã
# mysql -uroot --socket=/var/lib/mysql1/mysql.sock example_db
INSERT INTO books(name, price, created_at) VALUES ('3æ¥ã§åããJava', 2500, NOW()); INSERT INTO books(name, price, created_at) VALUES ('3æ¥ã§åããRuby', 2300, NOW()); INSERT INTO books(name, price, created_at) VALUES ('ç¬ç¿ä»®æ³å', 5000, NOW()); INSERT INTO books(name, price, created_at) VALUES ('Javaå ¥é', 2000, NOW()); INSERT INTO books(name, price, created_at) VALUES ('å ¥éRuby', 2800, NOW()); INSERT INTO books(name, price, created_at) VALUES ('Effective Ruby', 4200, NOW()); INSERT INTO books(name, price, created_at) VALUES ('ãããRuby', 5800, NOW()); INSERT INTO books(name, price, created_at) VALUES ('Rubyå¾¹åºå ¥é', 3000, NOW()); INSERT INTO books(name, price, created_at) VALUES ('RubyããJavaã¸', 1800, NOW()); INSERT INTO books(name, price, created_at) VALUES ('ã¯ã©ã¦ãå¤§å ¨', 6000, NOW());
ããããã®ã¤ã³ã¹ã¿ã³ã¹ã§ã§ SELECT ãã¦ã¿ãã¨ä»¥ä¸ã®ãããªæãã§ããã
- mysqld1(SPIDER)
MariaDB [example_db]> select * from books order by id; +----+----------------------+-------+---------------------+------------+--------------+ | id | name | price | created_at | updated_at | lock_version | +----+----------------------+-------+---------------------+------------+--------------+ | 1 | 3æ¥ã§åããJava | 2500 | 2014-04-18 22:09:30 | NULL | 0 | | 2 | 3æ¥ã§åããRuby | 2300 | 2014-04-18 22:09:30 | NULL | 0 | | 3 | ç¬ç¿ä»®æ³å | 5000 | 2014-04-18 22:09:30 | NULL | 0 | | 4 | Javaå ¥é | 2000 | 2014-04-18 22:09:30 | NULL | 0 | | 5 | å ¥éRuby | 2800 | 2014-04-18 22:09:30 | NULL | 0 | | 6 | Effective Ruby | 4200 | 2014-04-18 22:09:30 | NULL | 0 | | 7 | ãããRuby | 5800 | 2014-04-18 22:09:30 | NULL | 0 | | 8 | Rubyå¾¹åºå ¥é | 3000 | 2014-04-18 22:09:30 | NULL | 0 | | 9 | RubyããJava㸠| 1800 | 2014-04-18 22:09:30 | NULL | 0 | | 10 | ã¯ã©ã¦ãå¤§å ¨ | 6000 | 2014-04-18 22:09:31 | NULL | 0 | +----+----------------------+-------+---------------------+------------+--------------+
- mysqld2
MariaDB [example_db]> select * from books order by id; +----+----------------------+-------+---------------------+------------+--------------+ | id | name | price | created_at | updated_at | lock_version | +----+----------------------+-------+---------------------+------------+--------------+ | 2 | 3æ¥ã§åããRuby | 2300 | 2014-04-18 22:09:30 | NULL | 0 | | 4 | Javaå ¥é | 2000 | 2014-04-18 22:09:30 | NULL | 0 | | 6 | Effective Ruby | 4200 | 2014-04-18 22:09:30 | NULL | 0 | | 8 | Rubyå¾¹åºå ¥é | 3000 | 2014-04-18 22:09:30 | NULL | 0 | | 10 | ã¯ã©ã¦ãå¤§å ¨ | 6000 | 2014-04-18 22:09:31 | NULL | 0 | +----+----------------------+-------+---------------------+------------+--------------+
- mysqld3
MariaDB [example_db]> select * from books order by id; +----+----------------------+-------+---------------------+------------+--------------+ | id | name | price | created_at | updated_at | lock_version | +----+----------------------+-------+---------------------+------------+--------------+ | 1 | 3æ¥ã§åããJava | 2500 | 2014-04-18 22:09:30 | NULL | 0 | | 3 | ç¬ç¿ä»®æ³å | 5000 | 2014-04-18 22:09:30 | NULL | 0 | | 5 | å ¥éRuby | 2800 | 2014-04-18 22:09:30 | NULL | 0 | | 7 | ãããRuby | 5800 | 2014-04-18 22:09:30 | NULL | 0 | | 9 | RubyããJava㸠| 1800 | 2014-04-18 22:09:30 | NULL | 0 | +----+----------------------+-------+---------------------+------------+--------------+
ã¡ããã¨ã¬ã³ã¼ããåæ£ããã¦ã¾ããã
ãããªæãã§ç°¡åã« Sharding ããäºãåºæ¥ã¾ããã
ããã£ãã¨ããã¨ã
å®ã¯éä¸ããã¹ããã¼ã¿ã INSERT ããæã§çµæ§ãããã¾ããã
å ¬å¼ããã¥ã¡ã³ãã®ã08_sharding.txtãããããã¤ãã®åèã«ããã¦é ãããµã¤ãã§ã¯ã以ä¸ã®è¨å®ãå ¥ãã¦ãã¾ããã
[mysqld1] ã»ã»ã» # spider spider_internal_xa=1 spider_semi_trx_isolation=2 spider_support_xa=0
ãããã®è¨å®ã¯ä»¥ä¸ã®ãããªæå³ã¨ã®ãã¨ã
- 08_sharding.txt
spider_internal_xa=1ã®è¨å®ãè¡ãã¨ã¯ã©ã¤ã¢ã³ãå´ã§ã®é常ã®ãã©ã³ã¶ã¯ã·ã§ã³ã®æä½ããå é¨çã«xaãã©ã³ã¶ã¯ã·ã§ã³ã®æä½ã«ç½®ãæããããspiderãã¼ãã«ã§è¤æ°ã®DBãå©ç¨ãã¦ãåææ´æ°ãå®ç¾ããã¾ãã
spider_semi_trx_isolation=2ã¯ã1SQLã®éã®ãã©ã³ã¶ã¯ã·ã§ã³éé¢ã¬ãã«ã®å¤æ´ãè¡ããã¨ã§ãsqlå®è¡ä¸ã«ä»ã®ã¯ã©ã¤ã¢ã³ãã«ããæ´æ°ãè¡ããã¦ãä¸è²«æ§ã®ããçµæãå¾ãããããã«ãã¾ããç¶æ³ã«å¿ãã¦spider_semi_trx_isolation=3ã®å©ç¨ãé¸æãã¦ãè¯ãã§ãããããªããspider_semi_trx_isolationã¯ãã©ã³ã¶ã¯ã·ã§ã³ããµãã¼ãããã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ã«ã®ã¿æå¹ã§ããã©ã³ã¶ã¯ã·ã§ã³ããµãã¼ãããªãMyISAMã®ãããªã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ã§ã¯spider_semi_table_lockãå©ç¨ãã¾ãã
ã»MySQLã¯ç¾å¨ï¼ã¤ä»¥ä¸ã®xaãã©ã³ã¶ã¯ã·ã§ã³ããµãã¼ãããã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ãå©ç¨ã§ãã¾ããã
ãSpiderã¨InnoDBãä½µç¨ããå ´åã¯ãã³ã³ãã£ã°ãã¡ã¤ã«ã«ãspider_support_xa=0ããè¨è¼ããSpiderã®xaãµãã¼ããç¡å¹ã«ãã¦ãã ããã
ãSpiderã®xaãµãã¼ããç¡å¹ã«ãªã£ã¦ãããinternal_xaãã¯å©ç¨å¯è½ã§ãã
http://d.hatena.ne.jp/tetsuyai/20110903/1317288617
説æãèªãã æããããã«ãå
¥ãã¦ãããæ¹ãè¯ããããªè¨å®ã§ãã
ã¨ããããã§ãæå㯠mysqld1 ã« Spider ã¨ã³ã¸ã³ãã¤ã³ã¹ãã¼ã«å¾ããããã®è¨å®ã追å ããmysqld1 ãåèµ·åãã¦ãã¾ããã
# mysqld_multi stop 1 # mysqld_multi start 1
ãã®ç¶æ ã§ãã¹ããã¼ã¿ã INSERT ããã¨ããã以ä¸ã®ãããªã¨ã©ã¼ãçºçã
MariaDB [example_db]> INSERT INTO books(name, price, created_at) VALUES ('3æ¥ã§åããJava', 2500, NOW()); ERROR 12606 (HY000): This xid member is already exist
ã¤ã³ã¹ã¿ã³ã¹ãåèµ·åããããæåããä½æãç´ããããã¦ãå ¨ã解æ¶ããªãã®ã§ããããã¨æã SELECT ããã¦ã¿ãã¨åããããªã¨ã©ã¼ãçºçã
MariaDB [example_db]> SELECT * FROM books; ERROR 12605 (HY000): This xid is already exist
ãã¼ãã»ã»ã»ä¸ä½ä½æ
ã ããï¼
ãããã㦠mysqld_multi ã§è©¦ãã¦ããã®ããããªãã£ãããããã ãããã
ããããã¨æ¤ç´¢ãã¦ã¿ããã§ãããçµå±åé¿çãè¦ã¤ãããªãã£ããããæçµçã«ã¯ä¸ã§ã¾ã¨ããæé ã®éãããããã®è¨å®ãå
¥ããªãããã«ããã¨ãããä¸æãåä½ããããã«ãªãã¾ããã
ãããã説æã«ããã°ããã㯠XA ãã©ã³ã¶ã¯ã·ã§ã³å¨ãã®è¨å®ã¨ã®äºãªã®ã§ãããããã¦ããããè¨å®ããªãã¨ãã©ã³ã¶ã¯ã·ã§ã³ã使ããªããªã£ã¦ãã¾ã£ããããã®ã§ããããã
æ°ã«ãªã£ãã®ã§ç¢ºèªãã¦ã¿ã¾ã
mysqld1 ã«æ¥ç¶ããé常ã®ãã©ã³ã¶ã¯ã·ã§ã³ãéå§ãã¾ãã
MariaDB [example_db]> begin;
å度åããã¹ããã¼ã¿ãæå ¥ã
INSERT INTO books(name, price, created_at) VALUES ('3æ¥ã§åããJava', 2500, NOW()); INSERT INTO books(name, price, created_at) VALUES ('3æ¥ã§åããRuby', 2300, NOW()); INSERT INTO books(name, price, created_at) VALUES ('ç¬ç¿ä»®æ³å', 5000, NOW()); INSERT INTO books(name, price, created_at) VALUES ('Javaå ¥é', 2000, NOW()); INSERT INTO books(name, price, created_at) VALUES ('å ¥éRuby', 2800, NOW()); INSERT INTO books(name, price, created_at) VALUES ('Effective Ruby', 4200, NOW()); INSERT INTO books(name, price, created_at) VALUES ('ãããRuby', 5800, NOW()); INSERT INTO books(name, price, created_at) VALUES ('Rubyå¾¹åºå ¥é', 3000, NOW()); INSERT INTO books(name, price, created_at) VALUES ('RubyããJavaã¸', 1800, NOW()); INSERT INTO books(name, price, created_at) VALUES ('ã¯ã©ã¦ãå¤§å ¨', 6000, NOW());
SELECT ããã¨å½ç¶ã§ãããã¼ã¿ã¯å¢ãã¦ãã¾ãã
MariaDB [example_db]> select * from books order by id; +----+----------------------+-------+---------------------+------------+--------------+ | id | name | price | created_at | updated_at | lock_version | +----+----------------------+-------+---------------------+------------+--------------+ | 1 | 3æ¥ã§åããJava | 2500 | 2014-04-18 22:09:30 | NULL | 0 | | 2 | 3æ¥ã§åããRuby | 2300 | 2014-04-18 22:09:30 | NULL | 0 | | 3 | ç¬ç¿ä»®æ³å | 5000 | 2014-04-18 22:09:30 | NULL | 0 | | 4 | Javaå ¥é | 2000 | 2014-04-18 22:09:30 | NULL | 0 | | 5 | å ¥éRuby | 2800 | 2014-04-18 22:09:30 | NULL | 0 | | 6 | Effective Ruby | 4200 | 2014-04-18 22:09:30 | NULL | 0 | | 7 | ãããRuby | 5800 | 2014-04-18 22:09:30 | NULL | 0 | | 8 | Rubyå¾¹åºå ¥é | 3000 | 2014-04-18 22:09:30 | NULL | 0 | | 9 | RubyããJava㸠| 1800 | 2014-04-18 22:09:30 | NULL | 0 | | 10 | ã¯ã©ã¦ãå¤§å ¨ | 6000 | 2014-04-18 22:09:31 | NULL | 0 | | 11 | 3æ¥ã§åããJava | 2500 | 2014-04-18 22:36:03 | NULL | 0 | | 12 | 3æ¥ã§åããRuby | 2300 | 2014-04-18 22:36:03 | NULL | 0 | | 13 | ç¬ç¿ä»®æ³å | 5000 | 2014-04-18 22:36:03 | NULL | 0 | | 14 | Javaå ¥é | 2000 | 2014-04-18 22:36:03 | NULL | 0 | | 15 | å ¥éRuby | 2800 | 2014-04-18 22:36:03 | NULL | 0 | | 16 | Effective Ruby | 4200 | 2014-04-18 22:36:03 | NULL | 0 | | 17 | ãããRuby | 5800 | 2014-04-18 22:36:03 | NULL | 0 | | 18 | Rubyå¾¹åºå ¥é | 3000 | 2014-04-18 22:36:03 | NULL | 0 | | 19 | RubyããJava㸠| 1800 | 2014-04-18 22:36:03 | NULL | 0 | | 20 | ã¯ã©ã¦ãå¤§å ¨ | 6000 | 2014-04-18 22:36:03 | NULL | 0 | +----+----------------------+-------+---------------------+------------+--------------+
ãã¼ã«ããã¯ãå®è¡ã
MariaDB [example_db]> rollback;
SELECT ãã¦ã¿ã¾ãã
MariaDB [example_db]> select * from books order by id; +----+----------------------+-------+---------------------+------------+--------------+ | id | name | price | created_at | updated_at | lock_version | +----+----------------------+-------+---------------------+------------+--------------+ | 1 | 3æ¥ã§åããJava | 2500 | 2014-04-18 22:09:30 | NULL | 0 | | 2 | 3æ¥ã§åããRuby | 2300 | 2014-04-18 22:09:30 | NULL | 0 | | 3 | ç¬ç¿ä»®æ³å | 5000 | 2014-04-18 22:09:30 | NULL | 0 | | 4 | Javaå ¥é | 2000 | 2014-04-18 22:09:30 | NULL | 0 | | 5 | å ¥éRuby | 2800 | 2014-04-18 22:09:30 | NULL | 0 | | 6 | Effective Ruby | 4200 | 2014-04-18 22:09:30 | NULL | 0 | | 7 | ãããRuby | 5800 | 2014-04-18 22:09:30 | NULL | 0 | | 8 | Rubyå¾¹åºå ¥é | 3000 | 2014-04-18 22:09:30 | NULL | 0 | | 9 | RubyããJava㸠| 1800 | 2014-04-18 22:09:30 | NULL | 0 | | 10 | ã¯ã©ã¦ãå¤§å ¨ | 6000 | 2014-04-18 22:09:31 | NULL | 0 | +----+----------------------+-------+---------------------+------------+--------------+
ã¡ããã¨ãã¼ã¿ã¯å·»ãæ»ã£ã¦ããããã§ãã
ã©ããã spider_internal_xa = 1 ãªã©ã®è¨å®ãå
¥ããªãã¦ããã¡ããã¨è¤æ°DBéã§ã®ãã©ã³ã¶ã¯ã·ã§ã³ã¯æå¹ã«ãªã£ã¦ããããã§ãã
ã¨ãããã¨ã¯ãããã¥ã¡ã³ãã«ã¯æ¸ãã¦ãããã©å¥ã«ãã®è¾ºã®è¨å®ã¯ä¸è¦ãã£ã¦äºã§ããã®ããªãï¼
ãã®è¾ºããã¾ãã¡ã¾ã è¯ãåãã£ã¦ããªãã§ãã
ãã ãé常㮠commit, rollback ã使ããã®ã§ããã° Rails çã®ãã¬ã¼ã ã¯ã¼ã¯ãããä½ãæèããã«ãã©ã³ã¶ã¯ã·ã§ã³ã使ãäºã¯åºæ¥ããã§ããã
ã¾ã¨ã
ãã®ä»ã試ããç¯å²ã§ã¯ mysqldump ãæ®éã«ä½¿ãããããã³ãããã®ã¤ã³ãã¼ããå
¨ãåé¡ããã¾ããã§ããã
å¾ã¯ãã¼ã¿ãã¼ã追å æã® Re-sharding ãã©ãããã®ãã¯æéã®ããæã«ã§ãæ¤è¨¼ãã¦ããããã¨ããã
Spider ã¯ä»¥åãã試ãã¦ã¿ããã£ããã§ããããããã£ã¦å
¬å¼ãã¤ããªã«å梱ãããã¨å°å
¥ã®æ·å±
ãä¸ãã£ã¦å¬ããã§ãã
å人çã«ä»ã¾ã§ DB 㯠MySQL ã使ãäºãå¤ãã£ããã§ããã次ã«æ°è¦ã« DB ãµã¼ãç«ã¦ãæ©ä¼ããã£ãã MariaDB ã使ãããã§ããã
ãã®ãã¡ VP ã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ãå梱ãããã¨ãããªã¼ã
åè
Spider Storage Engine Overview - MariaDB Knowledgebase
https://mariadb.com/kb/en/spider-storage-engine-overview/
æ¼¢(ãªãã³)ã®ã³ã³ãã¥ã¼ã¿é: å¿«é©ã¹ã±ã¼ã«ã¢ã¦ãçæ´»ã¸ã®ç¬¬ä¸æ©ãSPIDERã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ã使ã£ã¦ã¿ããï¼
http://nippondanji.blogspot.jp/2010/04/spider.html
MySQL Spiderã¨ã³ã¸ã³ã使ã£ã¦ã¿ããããã¼ã¿ãã¼ã¹ã·ã£ã¼ãã£ã³ã°(sharding)ã¨ã¯ã - æ°ã¾ã¾ã«æ¸ãã¦ã¿ã¾ããæ¥è¨
http://d.hatena.ne.jp/abcb2/20111010/1318224266