Product SiteDocumentation Site

DBScale 1.6.1

用​户​手​册​

技​术​特​点​、​系​统​软​硬​件​环​境​和​安​装​配​置​

版 1.6.1

北​京​万​里​开​源​软​件​有​限​公​司​


法律通告

©版​权​ 2016 北​京​万​里​开​源​软​件​有​限​公​司​
GreatTurbo 是​北​京​万​里​开​源​软​件​有​限​公​司​的​注​册​商​标​。​Linux是​Linus Torvalds先​生​的​注​册​商​标​。​所​有​其​它​商​标​归​其​相​应​的​所​有​者​所​有​。​
2017年​02月​
摘要
本​文​档​主​要​介​绍​了​万​里​开​源​软​件​有​限​公​司​分​布​式​数​据​库​中​间​件​产​品​ DBScale1.6.1 版​本​的​技​术​特​点​、​运​行​的​软​硬​件​环​境​、​如​何​进​行​安​装​以​及​详​细​的​配​置​说​明​。​

1. DBScale介​绍​
1.1. 使​用​环​境​架​构​
1.2. 支​持​的​数​据​库​
1.3. 功​能​特​性​
2. 安​装​使​用​
2.1. 安​装​准​备​
2.1.1. 系​统​环​境​
2.1.2. 数​据​库​配​置​要​求​
2.1.3. 数​据​库​账​户​配​置​说​明​
2.1.4. 支​持​的​硬​件​和​操​作​系​统​平​台​
2.1.5. 注​意​事​项​
2.2. 安​装​DBScale
2.3. 安​装​license
2.3.1. 获​取​license文​件​
2.3.2. 安​装​license文​件​
2.4. 安​装​后​端​数​据​库​集​群​
2.5. DBScale quick start
2.5.1. 读​写​分​离​集​群​quick start
2.5.2. 分​表​集​群​quick start
2.6. 启​动​前​预​检​查​
2.7. 启​停​DBScale
2.7.1. 启​动​DBScale
2.7.2. 停​止​DBScale
2.8. DBScale 集​群​按​需​安​装​使​用​全​流​程​示​例​
2.8.1. 配​置​主​机​ host 文​件​
2.8.2. 后​端​数​据​库​服​务​ MySQL 配​置​安​装​
2.8.3. DBScale 安​装​配​置​
2.9. DBScale使​用​限​制​与​建​议​
2.10. DBScale 云​上​安​装​的​注​意​事​项​
2.10.1. DBScale 在​青​云​安​装​的​注​意​事​项​
3. 配​置​
3.1. DBScale 配​置​概​述​
3.2. 命​令​行​参​数​
3.3. 配​置​文​件​选​项​
3.3.1. main section
3.3.2. driver section
3.3.3. black-white section
3.3.4. data-server section
3.3.5. data-source section
3.3.6. partition-scheme section
3.3.7. catalog section
3.3.8. schema section
3.3.9. table section
3.3.10. read-only-procedure section
3.4. 完​整​配​置​文​件​示​例​
3.4.1. 配​置​需​求​描​述​与​分​析​
3.4.2. 配​置​文​件​示​例​
4. 性​能​调​优​
4.1. 会​话​/语​句​内​存​相​关​配​置​
4.2. 数​据​导​入​/插​入​相​关​配​置​
4.3. 自​增​表​性​能​调​优​的​相​关​配​置​
4.4. 连​接​池​相​关​调​优​参​数​
4.5. 线​程​池​相​关​调​优​参​数​
4.6. 表​池​相​关​调​优​参​数​
4.7. 其​他​对​性​能​影​响​的​相​关​main配​置​
4.8. 读​写​分​离​与​读​负​载​均​衡​调​优​
4.9. 分​表​调​优​
4.9.1. 分​片​列​选​取​
4.9.2. 分​片​表​SQL调​优​
4.9.3. 分​片​表​高​级​调​优​
5. 数​据​导​入​导​出​
5.1. 数​据​导​入​
5.2. 数​据​导​出​
6. 日​志​
6.1. 日​志​文​件​ rotate
6.2. DBScale 日​志​文​件​说​明​
6.3. DBScale 慢​日​志​
6.4. DBScale 审​计​日​志​
7. DBScale 管​理​命​令​
7.1. DBScale 管​理​工​具​帮​助​
7.2. DBScale 运​行​状​态​与​参​数​
7.2.1. 查​看​ DBScale 集​群​状​态​
7.2.2. 查​看​ DBScale 参​数​值​
7.2.3. 在​线​设​置​DBScale配​置​选​项​
7.2.4. DBScale 维​护​的​ mysql session 变​量​值​
7.3. DBSCALE SHOW 语​句​
7.3.1. 查​看​ DBScale 版​本​信​息​
7.3.2. 查​看​ DBScale 进​程​所​在​机​器​的​主​机​名​
7.3.3. 查​看​ DBScale 安​装​路​径​和​日​志​文​件​路​径​
7.3.4. 查​看​ DBScale IP黑​白​名​单​
7.3.5. 查​看​在​事​务​状​态​中​已​执​行​的​ SQL 语​句​
7.3.6. 查​看​所​有​数​据​节​点​
7.3.7. 查​看​数​据​源​信​息​
7.3.8. 查​看​PARTITION_SCHEME
7.3.9. 查​看​表​所​在​位​置​
7.3.10. 查​看​ metadata source 的​失​败​的​SQL语​句​
7.3.11. 查​看​每​个​session的​使​用​内​存​数​
7.3.12. 查​看​用​户​状​态​
7.3.13. 查​看​用​户​详​细​状​态​
7.3.14. 查​看​用​户​锁​表​状​态​
7.3.15. 查​看​ innodb/tokudb 锁​等​待​
7.3.16. 查​看​上​一​条​语​句​的​执​行​时​间​细​节​
7.3.17. 查​看​连​接​池​状​态​
7.3.18. 查​看​连​接​池​版​本​
7.3.19. 查​看​线​程​池​状​态​
7.3.20. 查​看​ SQL 语​句​的​预​估​影​响​行​数​
7.3.21. 查​看​后​端​工​具​线​程​
7.3.22. 查​看​指​定​表​分​片​信​息​
7.3.23. 查​看​一​个​指​定​分​区​表​的​信​息​
7.3.24. 查​看​SHARD分​片​表​SHARD分​片​分​布​
7.3.25. 查​看​分​片​表​虚​拟​分​片​分​布​
7.3.26. 查​看​所​有​的​shard分​片​表​
7.3.27. 查​看​未​自​动​恢​复​的​故​障​分​布​式​事​务​信​息​
7.3.28. 查​看​跨​节​点​ JOIN 相​关​状​态​。​
7.3.29. 查​看​等​待​清​理​的​ SHARD 表​
7.3.30. 查​看​用​户​是​否​具​有​执​行​ DDL 语​句​的​权​限​
7.3.31. 查​看​库​级​别​权​限​设​置​
7.3.32. 查​看​表​级​别​权​限​设​置​
7.3.33. 查​看​当​前​ dbscale swap工​作​线​程​组​运​行​状​况​
7.3.34. 查​看​当​前​ DBScale 在​运​行​过​程​中​记​录​到​的​最​近​10条​比​较​重​要​的​警​告​。​
7.3.35. 查​看​某​张​自​增​分​片​表​的​当​前​自​增​值​。​
7.3.36. 查​看​消​息​订​阅​平​台​ server 任​务​状​态​
7.3.37. 查​看​消​息​订​阅​平​台​ client 任​务​状​态​
7.3.38. 查​看​消​息​订​阅​平​台​ server 任​务​关​联​的​所​有​ client 任​务​的​状​态​
7.3.39. 查​看​schema数​据​域​
7.4. DBSCALE DYNAMIC 语​句​
7.4.1. 在​线​动​态​添​加​一​个​数​据​节​点​
7.4.2. 在​线​动​态​删​除​一​个​数​据​节​点​
7.4.3. 在​线​动​态​添​加​数​据​源​
7.4.4. 在​线​删​除​数​据​源​
7.4.5. 在​线​动​态​添​加​数​据​空​间​
7.4.6. 在​线​为​主​从​集​群​添​加​ Slave 节​点​
7.4.7. 在​线​从​主​从​集​群​删​除​ Slave 节​点​
7.4.8. 在​线​手​动​进​行​主​从​切​换​
7.4.9. 在​线​设​置​ replication 数​据​源​ load_balance 策​略​
7.4.10. 在​线​调​整​ MultipleMaster 数​据​源​的​ active 节​点​
7.4.11. 在​线​动​态​删​除​一​个​分​片​策​略​
7.4.12. 在​线​调​整​数​据​源​内​某​个​ Server DataSource 的​权​重​
7.4.13. 在​线​调​某​张​自​增​分​片​表​的​自​增​值​
7.4.14. 在​线​调​SCHEMA的​pushdown_procedure行​为​
7.4.15. 在​线​调​整​IP黑​白​名​单​
7.5. 数​据​迁​移​相​关​命​令​
7.5.1. 在​线​迁​移​数​据​
7.5.2. 清​理​等​待​清​理​的​ SHARD 表​
7.6. DBScale 状​态​清​理​/刷​新​/重​置​命​令​
7.6.1. 刷​新​连​接​池​版​本​
7.6.2. 重​置​资​源​池​最​大​资​源​数​
7.6.3. 清​理​跨​节​点​ JOIN 临​时​表​
7.6.4. 清​理​ zookeeper 中​的​配​置​文​件​相​关​信​息​
7.6.5. 清​理​未​自​动​恢​复​的​故​障​分​布​式​事​务​信​息​
7.7. 异​步​操​作​管​理​命​令​
7.7.1. 查​看​异​步​操​作​命​令​
7.7.2. 异​步​操​作​控​制​
7.8. 消​息​订​阅​平​台​相​关​命​令​
7.9. 多​dbscale集​群​相​关​命​令​
7.10. 其​他​管​理​命​令​
7.10.1. 默​认​ session 变​量​动​态​管​理​
7.10.2. 设​置​某​一​用​户​的​优​先​级​
7.10.3. 阻​塞​表​请​求​
7.10.4. DBScale 执​行​命​令​信​号​
7.10.5. 保​存​ DBScale 的​配​置​信​息​
7.10.6. 通​过​机​器​名​与​连​接​id获​取​持​有​这​个​连​接​的​ DBScale session id值​
7.10.7. 在​dataserver端​执​行​特​定​命​令​
7.10.8. 在​线​获​取​数​据​一​致​性​点​
7.10.9. 扩​展​ EXPLAIN 语​句​
8. DBScale 权​限​认​证​
8.1. DBScale 权​限​认​证​概​述​
8.2. 库​级​别​的​权​限​设​置​
8.3. 表​级​别​的​权​限​设​置​
8.4. 设​置​用​户​对​ DDL 语​句​的​执​行​权​限​
8.5. IP 黑​白​名​单​
8.6. ACL混​合​演​示​示​例​
8.7. DBScale 集​群​密​码​修​改​
9. DBScale 外​部​工​具​
9.1. DBScale 集​群​数​据​备​份​工​具​
9.2. DBScale 集​群​数​据​恢​复​工​具​
9.3. jemalloc
9.4. dbscale-online-schema-change
9.5. mysql_auto_install
9.6. 集​群​rebalance工​具​
10. DBScale 数​据​源​
10.1. server 类​型​
10.2. read-only 类​型​
10.3. share_disk 类​型​
10.4. load_balance 类​型​
10.5. multiple_master 类​型​
10.6. rwsplit 类​型​
10.7. replication 类​型​
10.7.1. 主​从​复​制​功​能​
10.7.2. 读​写​分​离​功​能​
10.7.3. 故​障​切​换​
11. DBScale 分​片​表​
11.1. 分​片​表​概​述​
11.2. DBScale 分​区​方​式​
11.2.1. Hash 分​区​方​式​
11.2.2. Mod 分​区​方​式​
11.2.3. Range 分​区​方​式​
11.2.4. List 分​区​方​式​
11.2.5. 不​同​分​区​方​式​的​比​较​
11.3. DBScale 分​片​表​自​增​值​说​明​
11.3.1. DBScale 分​片​表​自​增​模​式​
11.3.2. 分​片​表​自​增​值​使​用​限​制​
11.3.3. LOAD DATA 自​增​检​查​开​关​
11.3.4. LAST_INSERT_ID() 函​数​开​关​
11.4. Shard 分​片​表​
11.4.1. Shard 分​区​的​相​关​配​置​
11.5. 将​普​通​表​调​整​为​分​片​表​的​方​法​
12. MySQL 数​据​库​管​理​语​句​
12.1. 账​户​管​理​语​句​
12.1.1. ALTER USER
12.1.2. CREATE USER
12.1.3. DROP USER
12.1.4. GRANT
12.1.5. RENAME USER
12.1.6. REVOKE
12.1.7. SET PASSWORD
12.1.8. FLUSH PRIVILEGES
12.2. 表​维​护​语​句​
12.2.1. ANALYZE TABLE
12.2.2. CHECK TABLE
12.2.3. CHECKSUM TABLE
12.2.4. REPAIR TABLE
12.3. 插​件​和​用​户​定​义​函​数​语​句​
12.3.1. CREATE FUNCTION for User-Defined Functions
12.3.2. DROP FUNCTION
12.3.3. INSTALL PLUGIN
12.3.4. UNINSTALL PLUGIN
12.4. SET 语​法​
12.5. SHOW 语​法​
12.5.1. SHOW AUTHORS
12.5.2. SHOW BINARY LOGS
12.5.3. SHOW BINLOG EVENTS
12.5.4. SHOW CHARACTER SET
12.5.5. SHOW COLLATION
12.5.6. SHOW COLUMNS
12.5.7. SHOW CONTRIBUTORS
12.5.8. SHOW CREATE DATABASE
12.5.9. SHOW EVENT
12.5.10. SHOW CREATE FUNCTION
12.5.11. SHOW CREATE PROCEDURE
12.5.12. SHOW CREATE TABLE
12.5.13. SHOW CREATE TRIGGER
12.5.14. SHOW CREATE VIEW
12.5.15. SHOW DATABASES
12.5.16. SHOW ENGINE
12.5.17. SHOW ENGINES
12.5.18. SHOW ERRORS
12.5.19. SHOW EVENTS
12.5.20. SHOW FUNCTION CODE
12.5.21. SHOW FUNCTION STATUS
12.5.22. SHOW GRANTS
12.5.23. SHOW INDEX
12.5.24. SHOW MASTER STATUS
12.5.25. SHOW OPEN TABLES
12.5.26. SHOW PLUGINS
12.5.27. SHOW PRIVILEGES
12.5.28. SHOW PROCEDURE CODE
12.5.29. SHOW PROCEDURE STATUS
12.5.30. SHOW PROCESSLIST
12.5.31. SHOW PROFILE
12.5.32. SHOW PROFILES
12.5.33. SHOW RELAYLOG EVENTS
12.5.34. SHOW SLAVE HOSTS
12.5.35. SHOW SLAVE STATUS
12.5.36. SHOW STATUS
12.5.37. SHOW TABLE STATUS
12.5.38. SHOW TABLES
12.5.39. SHOW TRIGGERS
12.5.40. SHOW VARIABLES
12.5.41. SHOW WARNINGS
12.6. 复​制​管​理​语​句​
12.7. 其​他​管​理​语​句​
12.7.1. BINLOG
12.7.2. CACHE INDEX
12.7.3. FLUSH
12.7.4. KILL
12.7.5. KILL QUERY
12.7.6. LOAD INDEX INTO CACHE
12.7.7. RESET
12.7.8. KEEPMASTER
13. DDL 语​句​
13.1. ALTER DATABASE
13.2. ALTER EVENT
13.3. ALTER LOGFILE GROUP
13.4. ALTER FUNCTION
13.5. ALTER PROCEDURE
13.6. ALTER SERVER
13.7. ALTER TABLE
13.8. ALTER TABLESPACE
13.9. ALTER VIEW
13.10. CREATE DATABASE
13.11. CREATE EVENT
13.12. CREATE FUNCTION
13.13. CREATE INDEX
13.14. CREATE LOGFILE GROUP
13.15. CREATE PROCEDURE
13.16. CREATE SERVER
13.17. CREATE TABLE
13.18. CREATE TABLESPACE
13.19. CREATE TRIGGER
13.20. CREATE VIEW
13.21. DROP DATABASE
13.22. DROP EVENT
13.23. DROP FUNCTION
13.24. DROP INDEX
13.25. DROP LOGFILE GROUP
13.26. DROP PROCEDURE
13.27. DROP SERVER
13.28. DROP TABLE
13.29. DROP TABLESPACE
13.30. DROP TRIGGER
13.31. DROP VIEW
13.32. RENAME TABLE
13.33. TRUNCATE TABLE
14. DML 语​句​
14.1. DBScale 操​作​的​表​类​型​
14.2. 执​行​数​据​空​间​
14.3. CALL 语​句​
14.4. DELETE 与​ UPDATE 语​句​
14.5. DO 语​句​
14.6. HANDLER 语​句​
14.7. INSERT/REPLACE 相​关​语​句​
14.8. LOAD DATA INFILE 语​句​
14.9. LOAD XML 语​句​
14.10. CREATE SELECT 语​句​
14.11. SELECT 语​句​
14.12. 子​查​询​
14.13. SELECT INTO OUTFILE 语​句​
14.14. PREPARE 语​句​
15. 事​务​和​锁​
15.1. START TRANSACTION, COMMIT 和​ ROLLBACK 语​句​
15.2. 不​能​回​滚​的​语​句​
15.3. 隐​式​提​交​语​句​
15.4. AUTOCOMMIT语​句​
15.5. SAVEPOINT, ROLLBACK TO SAVEPOINT 和​ RELEASE SAVEPOINT 语​句​
15.6. LOCK TABLES 和​ UNLOCK TABLES 语​句​
15.7. FLUSH TABLES 语​句​
15.8. 事​务​隔​离​级​别​
15.9. 跨​节​点​分​布​式​事​务​支​持​
15.10. XA 事​务​
15.11. Redo 不​安​全​语​句​
15.12. 面​向​人​工​补​偿​的​最​终​一​致​性​分​布​式​事​务​
16. 函​数​
16.1. 信​息​函​数​
16.1.1. FOUND_ROWS()
16.1.2. ROW_COUNT()
16.1.3. LAST_INSERT_ID()
16.1.4. 跨​节​点​JOIN中​的​function的​支​持​情​况​.
17. 高​级​特​性​
17.1. 读​写​分​离​
17.1.1. DBScale读​写​分​离​简​介​
17.1.2. DBScale读​写​分​离​高​级​配​置​
17.2. 视​图​
17.2.1. DBScale 视​图​简​介​
17.2.2. DBScale 视​图​配​置​和​使​用​
17.3. 存​储​过​程​
17.3.1. DBScale 存​储​过​程​简​介​
17.3.2. DBScale 存​储​过​程​示​例​
17.3.3. DBScale 存​储​过​程​使​用​限​制​
17.4. 高​可​用​
17.4.1. mariadb failover 异​常​处​理​
17.4.2. 手​动​ CHANGE MASTER
17.4.3. 动​态​增​减​ slave
17.4.4. 在​线​升​级​ DBScale 集​群​
17.4.5. 影​响​切​换​时​间​相​关​因​素​
17.5. mysql prepare协​议​配​置​
17.6. mysql prepare协​议​读​写​分​离​
17.6.1. DBScale mysql prepare协​议​读​写​分​离​功​能​使​用​限​制​
17.7. 在​线​添​加​表​配​置​
17.7.1. 在​线​添​加​非​分​片​表​
17.7.2. 在​线​添​加​分​片​表​
17.8. DBScale 迁​移​数​据​
17.8.1. DBScale 迁​移​命​令​
17.8.2. DBScale 迁​移​功​能​使​用​要​求​
17.8.3. DBScale 迁​移​功​能​使​用​限​制​
17.8.4. SHARD分​片​表​迁​移​与​查​看​场​景​描​述​
17.8.5. SPLIT 场​景​描​述​
17.8.6. DBScale 迁​移​场​景​描​述​
17.8.7. 两​级​复​制​场​景​下​分​片​表​的​扩​展​与​收​缩​例​子​:
17.9. 跨​节​点​JOIN
17.9.1. DBScale 跨​节​点​Join过​程​简​介​
17.9.2. DBScale 跨​节​点​Join的​种​类​
17.9.3. DBScale 跨​节​点​JOIN的​使​用​限​制​
17.9.4. DBScale 跨​节​点​JOIN的​使​用​建​议​
17.9.5. DBScale 跨​节​点​JOIN的​使​用​场​景​描​述​
17.9.6. 子​查​询​
17.9.7. DBScale 子​查​询​的​使​用​限​制​
17.9.8. 关​于​ dbscale_tmp 库​
18. 消​息​订​阅​平​台​
18.1. 启​停​消​息​订​阅​服​务​
18.1.1. 启​停​ server 服​务​
18.1.2. 启​停​ client 服​务​
18.2. Server 任​务​管​理​
18.2.1. 创​建​ server 任​务​
18.2.2. 启​动​ server 任​务​
18.2.3. 关​闭​ server 任​务​
18.2.4. 删​除​ server 任​务​
18.3. Client 任​务​管​理​
18.3.1. 创​建​ client 任​务​
18.3.2. 启​动​ client 任​务​
18.3.3. 关​闭​ client 任​务​
18.3.4. 删​除​ client 任​务​
18.4. 过​滤​器​
18.4.1. 普​通​表​过​滤​
18.4.2. 分​片​表​过​滤​
18.4.3. 模​式​表​过​滤​
18.4.4. 多​表​过​滤​
18.5. 任​务​展​示​与​持​久​化​
18.5.1. 任​务​的​持​久​化​
18.5.2. Server 任​务​展​示​
18.5.3. Client 任​务​展​示​
18.5.4. Server 任​务​关​联​所​有​ client 任​务​展​示​
18.6. 任​务​故​障​与​重​启​
18.7. 其​它​注​意​事​项​
19. 多​dbscale集​群​
19.1. 多​dbscale概​述​
19.2. 多​dbscale 集​群​安​装​配​置​
19.3. 多​dbscale集​群​启​停​
19.4. 多​dbscale集​群​管​理​操​作​
19.4.1. 查​看​多​dbscale集​群​当​前​调​度​节​点​信​息​
19.4.2. 查​看​多​dbscale集​群​所​有​调​度​节​点​信​息​
19.4.3. 停​止​调​度​节​点​
19.4.4. 多​dbscale模​式​下​的​用​户​会​话​管​理​
19.5. 多​dbscale模​式​下​的​sql执​行​影​响​
20. 常​见​故​障​与​处​理​
20.1. DBScale 常​见​故​障​列​表​
20.2. 修​改​ server id 导​致​mariadb集​群​主​从​复​制​断​开​
20.3. 小​内​存​环​境​下​DBScale启​动​失​败​,错​误​日​志​报​错​errno 11
20.4. 没​有​正​确​配​置​ wait_timeout导​致​的​错​误​
20.5. 文​件​句​柄​数​不​够​
20.6. license错​误​
20.7. 重​复​启​动​导​致​行​为​异​常​
20.8. 认​证​source 初​始​化​失​败​导​致​无​法​登​录​
20.9. 执​行​dbscale管​理​操​作​时​,报​没​有​权​限​错​误​
20.10. 语​句​部​分​解​析​
20.11. 客​户​端​有​时​候​连​不​上​dbscale,连​上​后​有​时​查​询​返​回​无​法​连​接​错​误​(10061)
20.12. 结​果​集​乱​码​
20.13. 对​分​片​表​执​行​大​结​果​集​的​order by或​group by查​询​失​败​
20.14. 重​启​dbscale后​没​有​刷​新​连​接​池​,出​现​ Communications link failure 错​误​
20.15. 复​杂​数​据​操​作​受​到​ max_allowed_packet 限​制​
20.16. 创​建​一​个​新​库​,然​后​use到​该​库​,进​行​操​作​报​错​说​“​No database selected”​
20.17. 巨​大​的​瞬​时​并​发​导​致​dbscale集​群​被​hold住​
20.18. 巨​大​的​瞬​时​登​录​并​发​导​致​dbscale集​群​丢​失​客​户​端​连​接​
20.19. 分​片​表​进​行​DML操​作​时​出​现​[Got error when refresh table info]错​误​信​息​
20.20. mariadb failover 异​常​处​理​
20.21. 端​口​绑​定​错​误​
20.22. pid文​件​无​法​写​入​
20.23. 插​入​失​败​报​错​Fail to find the partition key from table
20.24. CREATE TABLE或​者​CREATE TRIGER失​败​
20.25. 查​询​遇​到​Reach the max allowed single sort rows错​误​
20.26. 跨​节​点​ JOIN 获​取​临​时​表​失​败​
20.27. 达​到​最​大​的​排​序​数​量​错​误​
20.28. 复​制​管​理​相​关​的​语​句​执​行​失​败​,报​错​Unsupport replication related stmt
20.29. MySQL 临​时​文​件​未​被​清​理​,tmp 目​录​占​用​大​量​磁​盘​空​间​
20.30. 对​于​形​如​ 9xxx 的​错​误​号​的​说​明​
20.31. XA 事​务​在​ mysql5.7 下​ warning
20.32. Warn for : should increase the connection from ×× to ××
20.33. 迁​移​失​败​: plz check whether the table_name is same with pattern table name
20.34. 创​建​分​片​表​时​报​错​说​对​应​的​库​不​存​在​
20.35. dbscale 端​死​锁​现​象​,原​因​及​目​前​处​理​办​法​
20.36. 通​过​ DBScale 查​询​ information_schema 库​的​结​果​集​不​对​
20.37. 登​陆​集​群​后​执​行​任​何​SQL都​报​错​Access denied for user 'dbscale'@'%' to database 'information_schema'
20.38. 创​建​或​删​除​内​部​含​有​CALL语​句​的​存​储​过​程​时​提​示​被​被​调​用​的​储​过​程​不​存​在​。​
20.39. 在​认​证​ server 使​用​update修​改​用​户​host后​未​flush privileges导​致​show databases执​行​失​败​。​
20.40. 登​录​是​报​错​ Get a bad auth packet 。​
21. DBScale 错​误​列​表​
A. 联​系​我​们​
A.1. 我​们​需​要​反​馈​!
A.2. 技​术​支​持​

第 1 章 DBScale介​绍​

DBScale 是​一​款​分​布​式​数​据​库​中​间​件​软​件​,其​设​计​初​衷​就​是​为​了​解​决​大​数​据​量​、​高​负​载​下​的​数​据​分​布​问​题​。​
它​运​行​于​客​户​端​程​序​和​数​据​库​服​务​器​之​间​,通​过​截​取​客​户​端​程​序​发​往​数​据​库​服​务​器​的​信​息​,按​照​需​要​进​行​修​改​等​分​析​,然​后​转​发​给​相​应​的​数​据​库​服​务​器​;再​从​服​务​端​接​受​返​回​的​数​据​,转​发​给​对​应​的​客​户​端​程​序​。​
对​于​客​户​端​程​序​而​言​,DBScale 就​像​是​真​正​的​数​据​库​服​务​器​,而​没​有​必​要​去​知​道​真​正​的​数​据​存​储​位​置​,这​就​极​大​地​提​高​了​数​据​库​系​统​的​扩​展​性​:当​由​于​业​务​负​载​增​大​而​增​加​数​据​库​服​务​器​时​,只​需​要​修​改​ DBScale 的​配​置​,而​没​有​必​要​重​新​部​署​客​户​端​程​序​。​
除​了​对​数​据​分​布​进​行​处​理​外​,DBScale 还​可​以​对​各​种​故​障​进​行​处​理​,比​如​网​络​故​障​、​后​台​数​据​库​服​务​器​不​可​用​等​,保​证​整​个​业​务​系​统​的​稳​定​运​行​。​

1.1. 使​用​环​境​架​构​

DBScale 位​于​数​据​库​应​用​集​群​和​数​据​库​集​群​之​间​, 负​责​对​数​据​库​请​求​的​转​发​和​对​数​据​库​集​群​的​管​理​。​通​过​ DBScale 可​以​方​便​地​对​后​端​数​据​库​集​群​进​行​不​同​层​次​的​数​据​分​布​式​部​署​,并​在​此​基​础​上​提​供​读​写​分​离​、​并​行​计​算​、​高​可​用​以​及​高​容​错​,而​这​些​对​于​前​端​数​据​应​用​而​言​是​基​本​完​全​透​明​的​,从​而​极​大​地​提​高​可​数​据​集​群​的​性​能​、​可​扩​展​性​和​可​靠​性​。​
DBScale 使​用​架​构​
图 1.1. DBScale 使​用​架​构​

DBScale 支​持​的​数​据​分​布​式​部​署​主​要​分​为​ 3 个​层​次​:
  1. 库​级​别​的​数​据​分​布​式​部​署​,可​以​将​不​同​的​库​部​署​到​不​同​的​数​据​库​实​例​上​。​
  2. 表​级​别​的​数​据​分​布​式​部​署​,可​以​将​不​同​的​表​部​署​到​不​同​的​数​据​库​实​例​上​。​
  3. 行​级​别​的​数​据​分​布​式​部​署​,可​以​将​一​张​表​中​的​行​按​照​一​定​的​规​则​分​布​到​不​同​的​数​据​库​实​例​上​。​
由​于​ DBScale 是​基​于​数​据​库​底​层​通​讯​协​议​的​,所​以​任​何​采​用​该​数​据​库​客​户​端​ API 库​(c、​php 等​各​种​语​言​版​本​)、​连​接​器​(jdbc、​odbc 等​连​接​驱​动​)等​开​发​的​数​据​库​客​户​端​软​件​,都​可​以​与​ DBScale 通​讯​。​

1.2. 支​持​的​数​据​库​

目​前​ DBScale 主​要​支​持​的​是​开​源​的​ MySQL 数​据​库​和​分​支​版​本​MariaDB,主​要​版​本​包​括​4.1.x、​5.0.x、​5.1.x、​5.5.x、​5.6.x, 10.0.x。​
未​来​将​提​供​其​他​数​据​库​的​支​持​,如​ PostgreSQL, Oracle 等​。​

1.3. 功​能​特​性​

  • 读​写​分​离​
    DBScale 支​持​对​应​用​的​读​写​分​离​,该​功​能​基​于​ Master-Slave 复​制​环​境​,主​节​点​写​,从​节​点​读​。​从​节​点​可​以​任​意​扩​展​,因​此​提​高​了​数​据​库​系​统​处​理​能​力​,可​以​根​据​负​载​情​况​进​行​扩​展​。​
  • 负​载​均​衡​
    DBScale 基​于​ Master-Slave 复​制​环​境​提​供​读​操​作​的​负​载​均​衡​,读​操​作​在​从​节​点​间​进​行​负​载​均​衡​;DBScale 基​于​数​据​分​布​式​部​署​提​供​写​操​作​的​负​载​均​衡​,写​操​作​按​照​数​据​分​布​规​制​被​分​发​到​不​同​的​物​理​机​器​上​。​
  • 不​同​级​别​的​数​据​分​布​式​部​署​
    DBScale 提​供​了​ 3 个​级​别​的​数​据​分​布​式​部​署​: schema 级​别​的​分​布​式​部​署​、​table 级​别​的​分​布​式​部​署​、​table 内​行​数​据​的​ sharding。​这​ 3 种​分​布​式​部​署​方​式​可​以​同​时​使​用​,将​数​据​以​分​布​式​的​形​式​部​署​到​多​台​物​理​机​器​上​,通​过​并​行​计​算​极​大​地​提​高​集​群​的​吞​吐​能​力​。​
  • Failover
    DBScale 支​持​自​动​的​故​障​处​理​:
    1. SQL 语​句​执​行​的​故​障​重​试​
    2. 自​动​屏​蔽​故​障​节​点​和​延​迟​过​高​的​ slave
    3. 故​障​无​缝​切​换​,对​应​用​完​全​透​明​
    4. 故​障​自​动​重​新​选​主​,并​自​动​调​整​集​群​拓​扑​
    5. 故​障​节​点​恢​复​后​,自​动​将​其​加​入​集​群​
    6. mysql的​event的​主​备​自​动​切​换​
  • Replication 环​境​中​的​高​可​用​处​理​
    通​常​主​从​复​制​拓​扑​中​只​能​有​一​个​主​节​点​,所​以​存​在​单​点​问​题​。​DBScale 通​过​指​定​从​节​点​是​否​可​以​作​为​复​制​主​节​点​完​美​地​解​决​了​这​个​问​题​。​当​主​节​点​出​现​故​障​时​,DBScale 会​从​所​有​可​以​做​主​节​点​的​从​节​点​中​选​择​一​个​数​据​最​完​整​的​作​为​新​的​主​节​点​,并​自​动​调​整​复​制​拓​扑​关​系​中​的​其​他​节​点​从​新​主​节​点​复​制​数​据​。​当​故​障​主​节​点​恢​复​之​后​,DBScale 会​自​动​将​它​作​为​新​主​节​点​的​从​节​点​加​入​集​群​。​
    DBScale 支​持​故​障​切​换​后​的​回​切​,当​原​主​节​点​作​为​从​节​点​加​入​集​群​之​后​,DBScale会​在​集​群​数​据​稳​定​负​载​可​控​的​情​况​下​,支​持​通​过​管​理​命​令​将​集​群​的​工​作​主​节​点​切​换​回​原​主​节​点​,即​配​置​文​件​主​节​点​。​
  • 数​据​高​可​靠​与​冗​余​
    DBScale支​持​丰​富​灵​活​的​数​据​冗​余​策​略​,并​且​自​动​处​理​这​些​方​案​的​故​障​切​换​:
    1. 支​持​基​于​ master-slave 的​replication:异​步​与​半​同​步​,支​持​gtid
    2. 支​持​基​于​ galera 的​同​步​复​制​方​案​
    3. 支​持​支​持​共​享​存​储​,drbd,以​及​分​布​式​文​件​系​统​
    4. 提​供​基​于​半​同​步​+gtid的​数​据​故​障​切​换​"0"丢​失​高​可​用​方​案​
  • 灵​活​伸​缩​
    1. 支​持​在​线​scale-up扩​展​与​收​缩​。​
    2. 支​持​在​线​scale-out扩​展​与​收​缩​,支​持​数​据​在​线​迁​移​。​
  • 丰​富​的​分​区​表​功​能​支​持​
    1. 分​区​算​法​支​持​:hash, range, list, mod。​
    2. 分​区​列​支​持​表​达​式​计​算​。​
    3. 支​持​: 全​表​扫​描​、​order by、​group by、​having、​limit。​
    4. 支​持​简​单​聚​集​函​数​:min,max,count,sum,avg。​
    5. 支​持​UNION ALL。​
    6. 支​持​自​增​。​
    7. 支​持​常​见​DDL语​句​。​
  • 支​持​prepare语​句​
    1. 支​持​COM_QUERY的​prepare语​句​,包​括​跨​节​点​操​作​场​景​
    2. 支​持​binary协​议​的​prepare语​句​,包​括​跨​节​点​操​作​场​景​
    3. 支​持​prepare语​句​的​读​写​分​离​与​负​载​均​衡​
  • 支​持​事​务​与​锁​
    1. 支​持​auto_commit
    2. 支​持​一​阶​段​事​务​
    3. 提​供​基​于​XA的​两​阶​段​事​务​
    4. 支​持​lock tables语​句​,包​括​跨​节​点​操​作​场​景​
  • 支​持​SQL高​级​功​能​
    1. 支​持​视​图​,包​括​跨​节​点​操​作​场​景​。​目​前​视​图​只​支​持​ SELECT 查​询​操​作​,不​支​持​视​图​的​ INSERT、​UPDATE、​DELETE 操​作​。​
    2. 支​持​存​储​过​程​,包​括​跨​节​点​操​作​场​景​。​
    3. DBScale 支​持​found_rows, row_count, last_insert_id等​信​息​函​数​。​
  • 支​持​跨​节​点​操​作​
    1. 支​持​跨​节​点​的​结​果​集​合​并​。​
    2. 支​持​跨​节​点​的​子​查​询​,包​括​单​值​子​查​询​、​单​列​子​查​询​、​单​表​子​查​询​。​
    3. 支​持​跨​节​点​join。​
  • 支​持​行​列​混​合​集​群​
    DBScale后​端​可​以​同​时​部​署​基​于​mysql通​信​协​议​的​行​式​数​据​库​和​列​式​数​据​库​,DBScale支​持​在​这​2类​数​据​库​节​点​间​的​数​据​迁​移​、​数​据​定​位​、​任​务​调​度​处​理​等​操​作​。​
  • 提​供​丰​富​的​管​理​命​令​SQL扩​展​
    1. 支​持​慢​查​询​收​集​。​
    2. 支​持​在​线​DBScale参​数​修​改​。​
    3. 支​持​集​群​用​户​信​息​汇​总​查​看​。​
    4. 支​持​集​群​各​种​资​源​使​用​状​态​查​看​。​
  • 便​捷​管​理​与​运​维​
    1. 支​持​set 语​句​, 包​括​:用​户​变​量​支​持​和​session变​量​支​持​
    2. 支​持​kill 语​句​
    3. 支​持​grant,revoke 语​句​
    4. 支​持​mysqldump和​mydumper
    5. 支​持​select ... into outfile
    6. 支​持​mysqlimport和​load data [infile]
    7. 提​供​集​群​在​线​一​致​性​备​份​工​具​
    8. 支​持​COM_SHUTDOWN命​令​和​kill命​令​关​闭​DBScale
    9. 提​供​集​群​自​动​安​装​工​具​
    10. 提​供​基​于​zabbix的​集​群​监​控​平​台​
  • DBScale 的​高​可​用​
    主​备​模​式​的​DBScale 本​身​支​持​第​三​方​ HA 软​件​,如​ GreatTurbo HA。​
    多​dbscale模​式​通​过​前​端​部​署​负​载​均​衡​软​件​实​现​ DBScale 的​高​可​靠​,如​ LVS。​负​载​均​衡​软​件​本​身​的​高​可​靠​通​过​第​三​方​ HA 软​件​,如​ GreatTurbo HA。​

第 2 章 安​装​使​用​

2.1. 安​装​准​备​

2.1.1. 系​统​环​境​

操​作​系​统​:Linux 32/64 bit(各​种​发​行​版​本​,建​议​ kernel 为​ 2.6 版​本​);Window 暂​不​支​持​;
CPU:32bit/64bit 皆​可​,无​特​殊​要​求​; 建​议​采​用​ X86_64 架​构​ CPU。​
物​理​内​存​:无​特​殊​要​求​;越​大​越​好​。​
磁​盘​空​间​:无​特​殊​要​求​。​
RAID: 无​特​殊​要​求​。​
如​果​无​法​使​用​root用​户​启​动​dbscale,需​要​通​过​系​统​管​理​员​调​整​系​统​如​下​参​数​:
dbscale进​程​最​大​文​件​句​柄​数​,如​调​整​到​102400
系​统​的​tcp_max_syn_backlog,如​调​整​为​10240。​
系​统​的​somaxconn,如​调​整​为​10240。​
在​运​行​dbscale的​机​器​的​/etc/hosts文​件​中​配​置​所​有​集​群​相​关​机​器​。​

2.1.2. 数​据​库​配​置​要​求​

目​前​ DBScale 只​支​持​ MySQL/Percona 和​ MariaDB 数​据​库​。​
关​于​共​性​的​数​据​库​配​置​要​求​:
  1. 配​置​足​够​大​的​wait_timeout和​interactive_timeout, 例​如​2147483。​
  2. 配​置​大​小​写​不​敏​感​,lower_case_table_names=1。​
  3. 调​大​socket操​作​读​写​的​超​时​时​间​,net_write_timeout=1800, net_read_timeout=1800。​
  4. 配​置​max_allowed_packet >= 16M,确​保​后​端​所​有​节​点​该​值​配​置​一​致​。​
  5. 配​置​autocommit=1。​
  6. 配​置​ max_user_connections = 0, 配​置​ max_connections > server 的​连​接​池​资​源​最​大​值​ × 连​接​池​数​量​ + 100。​
关​于​ MySQL 数​据​库​:
  1. 版​本​至​少​ 5.0 版​本​,推​荐​ 5.6.12 或​以​上​版​本​;建​议​后​端​所​有​ MySQL 版​本​保​持​一​致​。​
  2. 建​议​确​保​后​端​所​有​ MySQL 处​理​能​力​一​致​。​至​少​要​确​保​对​于​一​个​分​片​表​的​各​个​分​片​ MySQL 的​处​理​能​力​一​致​或​基​本​相​当​。​
  3. 不​要​使​用​ ssl 协​议​,目​前​ DBScale 暂​不​支​持​。​
  4. 在​ Replicaion 环​境​中​,需​要​:
    • 如​使​用​主​从​复​制​需​开​启​ binlog 功​能​,建​议​设​置​为​行​级​复​制​。​
    • 启​用​设​置​项​ —​ log-slave-updates
    • 启​用​设​置​项​ —​ skip-slave-start,即​ slave 重​启​时​不​自​动​开​启​主​从​同​步​,否​则​若​现​ DBscale master 不​是​实​际​ master,有​可​能​造​成​数​据​不​一​致​。​
    • 如​果​使​用​ 5.6.12 及​以​上​版​本​,建​议​开​启​ GTID
    • 若​支​持​半​同​步​复​制​,需​要​在​ master 和​ slave 上​安​装​半​同​步​复​制​插​件​。​MySQL 默​认​超​时​时​间​为​10秒​,可​以​根​据​具​体​情​况​进​行​调​整​。​
    • 在​ DBScale 安​装​服​务​器​的​ /etc/hosts 文​件​内​配​置​好​所​有​后​端​数​据​库​集​群​所​在​服​务​器​的​ hostname 和​ ​IP,否​则​会​影​响​故​障​切​换​时​间​。​
    • DBScale 中​, 会​用​到​保​留​数​据​库​名​dbscale_tmp, 所​以​用​户​不​可​自​行​创​建​这​个​库​,同​时​必​须​启​用​设​置​项​ binlog-ignore-db=dbscale_tmp,并​且​配​置​ binlog-format=row。​DBScale 还​会​用​到​保​留​字​段​名​ dbscale_dup 和​ dbscale_key,用​户​不​可​使​用​该​两​个​字​段​作​为​分​区​列​配​置​分​区​表​。​
关​于​ MariaDB 数​据​库​:
  1. 版​本​至​少​ 10.0 版​本​,推​荐​ 10.0.15 或​以​上​版​本​;建​议​后​端​所​有​ MariaDB 版​本​保​持​一​致​。​
  2. 在​配​置​ MariaDB 主​从​模​式​时​,在​启​动​ DBScale 之​前​请​先​将​所​有​ MariaDB 数​据​库​做​ RESET MASTER 和​ RESET SLAVE 操​作​,并​确​保​ GTID 相​关​的​系​统​变​量​ (gtid_slave_pos, gtid_binlog_pos, gtid_current_pos) 都​处​于​初​值​状​态​。​
  3. 当​设​置​support-gtid=1时​,如​果​后​端​集​群​使​用​的​是​ MariaDB(10.0.2和​以​上​版​本​),并​且​在​ DBScale 中​使​用​两​层​复​制​的​部​署​拓​扑​,需​要​确​保​为​每​层​ MariaDB 分​配​一​个​不​同​的​domain ID (gtid_domain_id)。​例​如​复​制​拓​扑​:global_master->global_slave, global_master->partition_master1->partition_slave1, global_master->partition_master2->partition_slave2。​那​么​ global_master 和​ global_slave 需​配​置​相​同​的​domain ID 如​ 0,partition_master1 和​ partition_slave1 需​配​置​相​同​的​domain ID 如​ 1,partition_master2 和​ partition_slave2 需​配​置​相​同​的​domain ID 如​ 2。​
  4. 集​群​需​要​应​用​消​息​平​台​功​能​时​,需​要​添​加​配​置​,开​启​参​数​ gtid-ignore-duplicates。​

2.1.3. 数​据​库​账​户​配​置​说​明​

DBScale通​过​配​置​认​证​数​据​源​进​行​登​录​验​证​,参​见​authenticate-source。​所​以​客​户​端​登​录​的​账​户​都​是​配​置​在​认​证​数​据​源​中​的​账​户​,不​是​后​端​实​际​数​据​存​储​节​点​的​账​户​(当​然​配​置​成​一​样​也​是​可​以​的​)。​
用​户​名​为​dbscale和​root的​账​户​是​特​权​账​户​,其​中​dbscale和​root账​户​可​以​进​行​在​线​的​集​群​配​置​变​更​,此​外​root账​户​还​有​其​他​的​特​权​,参​考​enable-aclmax-conn-limit,和​dbscale-safe-sql-mode。​
所​以​要​限​制​dbscale和​root的​账​户​的​传​播​,原​则​上​只​有​集​群​DBA可​以​使​用​。​DBA使​用​root账​户​进​行​一​些​危​险​操​作​前​一​定​要​确​认​了​解​该​操​作​的​后​果​。​
创​建​客​户​端​登​录​的​账​户​时​ HOST 部​分​必​须​与​ DBScale 配​置​文​件​中​ dbscale-hosts 项​保​持​一​致​,推​荐​为​ DBScale 集​群​网​段​IP,dbscale-hosts 为​空​(默​认​值​)时​,请​使​用​%,创​建​后​端​实​际​数​据​存​储​节​点​的​账​户​时​建​议​ HOST 部​分​配​置​为​DBScale集​群​网​段​IP,如​:“​GRANT ALL ON *.* TO dbscale@'172.16.90.%';”​。​

2.1.4. 支​持​的​硬​件​和​操​作​系​统​平​台​

DBScale 软​件​运​行​于​主​流​ Linux 平​台​,以​及​主​流​硬​件​厂​商​的​服​务​器​平​台​(IA32、​EMT64、​AMD64 、​IA64、​PowerPC);支​持​当​前​几​乎​所​有​主​流​开​发​语​言​(C/C++、​C#、​VB、​Java、​Php、​Perl、​Python、​Ruby 等​)。​
主​要​操​作​系​统​和​硬​件​平​台​:
操​作​系​统​ 硬​件​平​台​
Red Hat Enterprise Linux 6 IA32, EMT64, AMD64
Red Hat Enterprise Linux 5 IA32, EMT64, AMD64
Red Hat Enterprise Linux 4 IA32, EMT64, AMD64, Intel IA64
Debian GNU/Linux 6 IA32, EMT64, AMD64
Debian GNU/Linux 5 IA32, EMT64, AMD64, Intel IA64
SuSE Enterprise Linux 11 IA32, EMT64, AMD64
SuSE Enterprise Linux 10 IA32, EMT64, AMD64, Intel IA64
FreeBSD 8 IA32, EMT64, AMD64
Oracle Linux 6 IA32, EMT64, AMD64
Oracle Linux 5 IA32, EMT64, AMD64
Oracle Linux 4 IA32, EMT64, AMD64, Intel IA64

2.1.5. 注​意​事​项​

使​用​ DBScale 之​前​请​与​ DBScale 工​程​师​确​认​ DBScale 的​功​能​列​表​,核​对​支​持​与​不​支​持​的​功​能​。​
目​前​ DBScale 对​ COM_CHANGE_USER 协​议​尚​未​支​持​,该​协​议​处​理​结​果​可​能​与​用​户​预​期​不​一​致​。​
运​行​ DBScale 过​程​中​,如​果​出​现​ 9 开​头​的​错​误​号​,即​形​如​ 9xxx 的​错​误​号​,DBScale 的​行​为​可​能​与​用​户​预​期​不​一​致​,请​参​考​第 20.30 节 “对​于​形​如​ 9xxx 的​错​误​号​的​说​明​”。​

2.2. 安​装​DBScale

目​前​ DBScale 主​要​支​持​的​是​ Linux 平​台​,以​ CentOS6.2 为​例​, 其​他​ linux 系​统​基​本​不​变​,请​酌​情​修​改​。​
软​件​包​名​称​: dbscale-version-os.tar.gz, 其​中​ VERSION 指​具​体​的​版​本​号​;OS 指​明​本​版​本​所​支​持​的​操​作​系​统​平​台​及​ CPU 架​构​类​型​。​
例​如​:dbscale-1.2-centos6.2-x86_64.tar.gz
表​明​该​安​装​包​中​ DBScale 的​版​本​为​ 1.2,所​支​持​的​操​作​系​统​为​ 64 位​的​ CentOS6.2。​
该​压​缩​包​中​主​要​包​含​了​一​些​可​执​行​程​序​、​配​置​、​以​及​服​务​脚​本​,以​及​ 3 个​子​目​录​: libs、​extra、​和​ha_script。​
  • 当​前​目​录​中​包​含​了​ DBScale 的​可​执​行​文​件​dbscale,两​个​示​例​配​置​文​件​(dbscale-rwsplit.conf 和​ dbscale-sharding.conf) 以​及​ DBScale 的​服​务​脚​本​dbscale-service.sh 和​ 日​志​rotate相​关​的​脚​本​。​
    还​有​一​些​可​执​行​程​序​,如​集​群​安​装​预​检​查​程​序​ pre_check。​
    还​有​集​群​自​动​安​装​脚​本​auto_install.sh。​
    还​有​集​群​跨​节​点​join函​数​相​关​配​置​文​件​function_type.txt。​
  • libs 目​录​中​包​含​了​该​安​装​包​ dbscale 运​行​过​程​中​所​需​要​的​动​态​库​文​件​
  • extra 目​录​中​包​含​了​一​些​工​具​脚​本​,如​集​群​自​动​安​装​脚​本​
  • ha_script 目​录​中​包​含​了​集​群​使​用​第​3方​高​可​靠​软​件​,如​ turboHA,时​所​用​的​相​关​脚​本​。​
具​体​安​装​过​程​如​下​:
shell> tar zxvf dbscale-version-os.tar.gz
shell> ln -s dbscale-version-os [%DBSCALE_HOME%]
shell> cd [%DBSCALE_HOME%]
shell> chmod a+x dbscale

2.3. 安​装​license

License是​DBScale软​件​的​使​用​授​权​,它​限​制​了​DBScale使​用​的​机​器​、​后​端​节​点​数​、​以​及​使​用​时​间​。​

2.3.1. 获​取​license文​件​

首​先​是​获​取​机​器​硬​件​码​。​在​运​行​DBScale的​机​器​上​执​行​如​下​命​令​:
 shell> cd [%DBSCALE_HOME%]
shell> ./dbscale-service.sh fetch_hard_code

或

shell> ./get_hardid
然​后​记​录​下​屏​幕​下​方​生​成​的​硬​件​码​,如​下​是​生​成​的​硬​件​码​示​例​:
 Hardware ID: 74fe13JGQWVK
最​后​将​生​成​的​硬​件​码​发​给​ DBScale 工​程​师​以​生​成​相​应​的​license文​件​。​

2.3.2. 安​装​license文​件​

生​成​的​license文​件​以​“​.lic”​为​后​缀​名​,如​“​soft.lic”​。​
安​装​过​程​就​是​将​该​文​件​拷​贝​到​检​测​目​录​“​/etc/dbscale/lic/”​:
 shell> mkdir -p /etc/dbscale/lic
shell> cp soft.lic /etc/dbscale/lic

2.4. 安​装​后​端​数​据​库​集​群​

后​端​ MySQL 集​群​可​以​使​用​自​动​安​装​脚​本​ auto_install.sh 进​行​安​装​,使​用​方​法​为​:
./auto_install.sh -d dbscale.conf -m mysql.conf
dbscale.conf 用​于​配​置​ data_server 相​关​参​数​。​(可​以​直​接​使​用​DBScale的​配​置​文​件​。​)
mysql.conf 用​于​配​置​每​个​ MySQL 实​例​安​装​相​关​参​数​:
mysql section
  • package_path
    Option-File Format package_path=#
    Type string
    Multiple N
    Description 本​地​安​装​包​路​径​
  • package_name
    Option-File Format package_name=#
    Type string
    Multiple N
    Description 本​地​安​装​包​文​件​名​
  • package_dir
    Option-File Format package_dir=#
    Type string
    Multiple N
    Description 安​装​包​解​压​后​目​录​名​
data-server section
  • need_install
    Option-File Format need_install=#
    Type int
    Multiple N
    Default 1
    Range 0,1
    Description 是​否​需​要​安​装​ MySQL
    0 表​示​不​需​要​安​装​,1 表​示​需​要​安​装​
  • need_package
    Option-File Format need_package=#
    Type int
    Multiple N
    Default 1
    Range 0,1
    Description 是​否​需​要​拷​贝​安​装​包​至​远​端​服​务​器​
    0 表​示​不​需​要​拷​贝​,1 表​示​需​要​拷​贝​
  • create_data_dir_only
    Option-File Format create_data_dir_only=#
    Type int
    Multiple N
    Default 0
    Range 0,1
    Description 是​否​只​创​建​一​个​空​ data 目​录​
    如​果​目​录​已​存​在​且​不​为​空​,则​返​回​错​误​。​
  • package_path
    Option-File Format package_path=#
    Type string
    Multiple N
    Description 远​端​主​机​上​ MySQL 安​装​包​路​径​
    如​果​ need_package=1,则​拷​贝​安​装​包​至​该​目​录​。​
  • force_install
    Option-File Format force_install=#
    Type int
    Multiple N
    Default 1
    Range 0,1,2
    Description 强​制​安​装​选​项​
    若​ MySQL 安​装​目​录​已​存​在​:value=0,返​回​错​误​;value=1,若​ MySQL 处​于​运​行​状​态​,则​不​进​行​安​装​,否​则​重​新​安​装​;value=2,删​除​该​目​录​,重​新​安​装​。​
  • source_conf
    Option-File Format source_conf=#
    Type string
    Multiple N
    Description MySQL 配​置​文​件​名​
  • target_conf
    Option-File Format target_conf=#
    Type string
    Multiple N
    Description 拷​贝​至​远​端​主​机​上​的​ MySQL 配​置​文​件​名​

2.5. DBScale quick start

本​节​将​介​绍​如​何​快​速​上​手​dbscale集​群​,主​要​包​括​2个​典​型​的​集​群​部​署​场​景​:读​写​分​离​集​群​、​以​及​分​表​集​群​。​

2.5.1. 读​写​分​离​集​群​quick start

本​节​将​介​绍​如​何​使​用​安​装​包​中​的​dbscale-rwsplit.conf示​例​配​置​文​件​,快​速​搭​建​上​手​一​个​读​写​分​离​集​群​。​并​给​出​该​类​集​群​的​后​续​学​习​的​参​考​链​接​。​
dbscale-rwsplit.conf配​置​文​件​描​述​了​一​个​一​主​一​备​一​从​的​3节​点​读​写​分​离​集​群​。​为​了​搭​建​该​集​群​,我​们​需​要​先​安​装​3个​mysql实​例​(可​以​位​于​不​同​的​OS,也​可​以​在​一​个​OS中​,但​如​果​需​要​测​试​集​群​节​点​故​障​切​换​的​话​,建​议​使​用​不​同​的​OS,物​理​机​或​虚​拟​机​都​可​以​)。​这​3个​实​例​是​集​群​的​数​据​节​点​,请​按​需​配​置​mysql的​参​数​,例​如​innodb_buffer_pool_size。​ mysql实​例​的​安​装​请​注​意​第 2.1.2 节 “数​据​库​配​置​要​求​”中​的​配​置​要​求​。​如​果​是​安​装​在​不​同​的​OS,注​意​调​整​或​关​闭​防​火​墙​,确​保​dbscale所​在​节​点​可​以​登​陆​这​些​数​据​库​实​例​。​
除​安​装​3个​数​据​节​点​的​mysql实​例​,我​们​还​需​额​外​安​装​2个​mysql实​例​,作​为​集​群​的​元​数​据​节​点​。​这​2个​节​点​的​mysql配​置​建​议​配​的​简​单​一​些​,它​们​基​本​不​需​要​消​耗​计​算​和​存​储​资​源​,通​常​可​以​和​数​据​节​点​复​用​OS。​例​如​一​台​64G内​存​的​PC server,我​们​要​安​装​一​个​数​据​节​点​和​一​个​元​数​据​节​点​,我​们​可​以​给​数​据​节​点​分​配​45G内​存​,给​元​数​据​节​点​4G内​存​。​
选​定​dbscale的​安​装​目​录​,然​后​在​该​目​录​解​压​dbscale的​安​装​包​,进​行​如​何​安​装​配​置​调​整​:
  1. 将​dbscale-rwsplit.conf文​件​重​命​名​为​dbscale.conf。​并​对​其​中​的​数​据​库​的​ip和​端​口​进​行​修​改​。​用​3个​数​据​节​点​的​ip和​端​口​替​换​配​置​文​件​dbscale.conf中​“​data-server master1”​、​“​data-server master2“​、​和​”​data-server slave1“​的​host和​port参​数​的​值​。​使​用​2个​元​数​据​节​点​的​ip和​端​口​替​换​配​置​文​件​dbscale.conf中​的​“​data-server auth1”​和​“​data-server auth2”​中​的​host和​port参​数​的​值​。​
  2. 如​果​需​要​在​mysql上​使​用​半​同​步​复​制​,请​先​参​考​mysql手​册​在​mysql上​安​装​半​同​步​复​制​插​件​,然​后​将​配​置​文​件​dbscale.conf中​的​“​#semi-sync-on = 1”​的​注​释​符​“​#”​去​掉​。​
  3. 在​后​端​mysql上​创​建​dbscale用​户​,密​码​设​定​为​dbscale_password。​示​例​命​令​如​下​“​grant all on *.* to 'dbscale'@'%' identified by 'dbscale_password';”​。​如​果​使​用​其​它​密​码​,请​注​意​修​改​配​置​文​件​dbsale.conf中​配​置​的​密​码​dbscale_password。​
  4. 示​例​配​置​中​dbscale的​端​口​为​3307,如​需​调​整​,请​修​改​配​置​文​件​dbscale.conf中​“​driver mysql”​配​置​域​下​的​port。​
本​quick start不​包​含​dbscale节​点​的​高​可​靠​。​dbscale节​点​本​身​的​高​可​靠​可​以​联​系​DBScale工​程​师​安​装​TurboHA,或​者​自​行​使​用​其​他​高​可​靠​软​件​如​keepalived。​
完​成​dbscale配​置​之​后​,使​用​root用​户​在​dbscale安​装​目​录​执​行​“​./dbscale-service start”​启​动​dbscale集​群​(确​保​mysql已​经​先​启​动​配​置​完​成​)。​
启​动​成​功​后​,可​以​使​用​mysql命​令​行​客​户​端​进​行​登​陆​,示​例​命​令​为​“​mysql -udbscale -pdbscale_password -h127.0.0.1 -P3307”​。​
至​此​读​写​分​离​的​quick start集​群​安​装​完​毕​,后​续​的​使​用​可​以​参​考​如​下​链​接​:

2.5.2. 分​表​集​群​quick start

本​节​将​介​绍​如​何​使​用​安​装​包​中​的​dbscale-sharding.conf示​例​配​置​文​件​,快​速​搭​建​上​手​一​个​分​表​集​群​。​并​给​出​该​类​集​群​的​后​续​学​习​的​参​考​链​接​。​
dbscale-sharding.conf配​置​文​件​描​述​了​3数​据​分​片​的​sharding集​群​,每​个​分​片​包​含​一​份​数​据​冗​余​。​配​置​文​件​中​已​经​配​置​了​一​个​test.part_.*的​pattern分​片​表​,分​区​列​为​id,即​所​有​test库​下​以​part_开​头​的​表​都​被​配​置​为​了​分​片​表​,且​分​区​列​为​id。​
为​了​搭​建​该​集​群​,我​们​需​要​先​安​装​6个​mysql实​例​(可​以​位​于​不​同​的​OS,也​可​以​在​一​个​OS中​,但​如​果​需​要​测​试​集​群​节​点​故​障​切​换​的​话​,建​议​使​用​不​同​的​OS,物​理​机​或​虚​拟​机​都​可​以​)。​这​6个​实​例​是​集​群​的​数​据​节​点​,请​按​需​配​置​mysql的​参​数​,例​如​innodb_buffer_pool_size。​ mysql实​例​的​安​装​请​注​意​第 2.1.2 节 “数​据​库​配​置​要​求​”中​的​配​置​要​求​。​如​果​是​安​装​在​不​同​的​OS,注​意​调​整​或​关​闭​防​火​墙​,确​保​dbscale所​在​节​点​可​以​登​陆​这​些​数​据​库​实​例​。​
如​果​觉​得​将​备​节​点​单​独​占​用​一​台​机​器​太​浪​费​资​源​,可​以​考​虑​循​环​备​份​的​部​署​方​式​,例​如​分​片​1部​署​在​机​器​1、​分​片​2部​署​在​机​器​2、​分​片​3部​署​在​机​器​3上​、​而​分​片​1的​备​部​署​在​机​器​2上​、​分​片​2的​备​部​署​在​机​器​3上​、​分​片​3的​备​部​署​在​机​器​1上​。​
除​安​装​6个​数​据​节​点​的​mysql实​例​,我​们​还​需​额​外​安​装​2个​mysql实​例​,作​为​集​群​的​元​数​据​节​点​。​这​2个​节​点​的​mysql配​置​建​议​配​的​简​单​一​些​,它​们​基​本​不​需​要​消​耗​计​算​和​存​储​资​源​,通​常​可​以​和​数​据​节​点​复​用​OS。​例​如​一​台​64G内​存​的​PC server,我​们​要​安​装​一​个​数​据​主​节​点​,一​个​数​据​备​节​点​和​一​个​元​数​据​节​点​,我​们​可​以​给​数​据​节​点​分​配​25G内​存​,给​元​数​据​节​点​4G内​存​。​
选​定​dbscale的​安​装​目​录​,然​后​在​该​目​录​解​压​dbscale的​安​装​包​,进​行​如​何​安​装​配​置​调​整​:
  1. 将​dbscale-sharding.conf文​件​重​命​名​为​dbscale.conf。​并​对​其​中​的​数​据​库​的​ip和​端​口​进​行​修​改​。​用​6个​数​据​节​点​的​ip和​端​口​替​换​配​置​文​件​dbscale.conf中​“​data-server par_master1”​、​“​data-server par_master2“​、​“​data-server par_master3”​、​“​data-server par_slave1”​、​“​data-server par_slave2”​、​和​“​data-server par_slave3”​的​host和​port参​数​的​值​。​使​用​2个​元​数​据​节​点​的​ip和​端​口​替​换​配​置​文​件​dbscale.conf中​的​“​data-server auth1”​和​“​data-server auth2”​中​的​host和​port参​数​的​值​。​
    注​意​,如​果​测​试​高​可​靠​的​话​,不​要​将​一​个​分​片​的​主​节​点​和​备​节​点​部​署​在​同​一​台​机​器​上​,例​如​par_master1和​par_slave1。​
  2. 如​果​需​要​在​mysql上​使​用​半​同​步​复​制​,请​先​参​考​mysql手​册​在​mysql上​安​装​半​同​步​复​制​插​件​,然​后​将​配​置​文​件​dbscale.conf中​的​“​#semi-sync-on = 1”​的​注​释​符​“​#”​去​掉​。​
  3. 在​后​端​mysql上​创​建​dbscale用​户​,密​码​设​定​为​dbscale_password。​示​例​命​令​如​下​“​grant all on *.* to 'dbscale'@'%' identified by 'dbscale_password';”​。​如​果​使​用​其​它​密​码​,请​注​意​修​改​配​置​文​件​dbsale.conf中​配​置​的​密​码​dbscale_password。​
  4. 示​例​配​置​中​dbscale的​端​口​为​3307,如​需​调​整​,请​修​改​配​置​文​件​dbscale.conf中​“​driver mysql”​配​置​域​下​的​port。​
本​quick start不​包​含​dbscale节​点​的​高​可​靠​。​dbscale节​点​本​身​的​高​可​靠​可​以​联​系​DBScale工​程​师​安​装​TurboHA,或​者​自​行​使​用​其​他​高​可​靠​软​件​如​keepalived。​
完​成​dbscale配​置​之​后​,使​用​root用​户​在​dbscale安​装​目​录​执​行​“​./dbscale-service start”​启​动​dbscale集​群​(确​保​mysql已​经​先​启​动​配​置​完​成​)。​
启​动​成​功​后​,可​以​使​用​mysql命​令​行​客​户​端​进​行​登​陆​,示​例​命​令​为​“​mysql -udbscale -pdbscale_password -h127.0.0.1 -P3307”​。​
登​录​集​群​后​,可​以​创​建​一​张​分​片​表​,并​插​入​数​据​:
use test;
create table part_tb1 (id int, c char(10));
insert into part_tb1 values (1,"a"),(2,"b"),(3,"c"),(4,"d"),(5,"e"),(6,"f"),(7,"g"),(8,"i"),(9,"j");
select *, @@server_id from part_tb1;
通​过​返​回​的​server_id我​们​可​以​看​出​数​据​在​分​片​表​集​群​的​实​际​分​布​。​
至​此​读​写​分​离​的​quick start集​群​安​装​完​毕​,后​续​的​使​用​可​以​参​考​如​下​链​接​:

2.6. 启​动​前​预​检​查​

集​群​提​供​ pre_check 程​序​进​行​初​次​安​装​的​启​动​前​预​检​查​,将​安​装​包​中​的​ pre_check 程​序​拷​贝​到​ dbscale.conf 所​在​目​录​,然​后​执​行​ ./pre_check 进​行​集​群​节​点​状​态​检​查​。​

2.7. 启​停​DBScale

2.7.1. 启​动​DBScale

启​动​ DBScale 之​前​需​要​确​认​后​端​数​据​库​集​群​已​经​启​动​,并​且​正​确​配​置​了​ DBScale 的​配​置​文​件​dbscale.conf。​关​于​配​置​文​件​的​配​置​请​参​考​第 3 章 配​置​。​关​于​集​群​调​优​请​参​考​第 4 章 性​能​调​优​。​后​端​数​据​库​集​群​的​配​置​以​及​ DBScale 的​配​置​示​例​见​第 2.8 节 “DBScale 集​群​按​需​安​装​使​用​全​流​程​示​例​”
启​动​必​须​在​ DBScale 可​执​行​文​件​所​在​目​录​。​由​于​需​要​设​置​单​进​程​最​大​句​柄​数​以​及​ backlog 和​ LD_LIBRARY_PATH 环​境​变​量​,启​动​过​程​需​要​超​级​管​理​员​或​ sudo 权​限​。​
启​动​过​程​建​议​使​用​服​务​脚​本​ dbscale-service.sh,该​服​务​脚​本​内​容​如​下​(DBSCALE_PATH 为​ DBScale 所​在​位​置​):
#!/bin/bash

PROG=dbscale
DBSCALE_PATH=/path/to/dbscale # Need to modify
DBSCALE_PID_FILE=$DBSCALE_PATH/dbscale.pid
DBSCALE_PID=`cat $DBSCALE_PID_FILE 2>/dev/null`

check_pid() {
    [ -z $1 ] && return 1
    [ -d "/proc/$1" ] && return 0 || return 1
}

dbscale_start() {
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DBSCALE_PATH/libs
    cd $DBSCALE_PATH
    ./$PROG &
}

dbscale_stop() {
    kill -TERM $DBSCALE_PID >/dev/null 2>&1
    sleep 2
    if check_pid $DBSCALE_PID && sleep 10 && check_pid $DBSCALE_PID
    then
        kill -KILL $DBSCALE_PID >/dev/null 2>&1
    fi
}

case "$1" in
    start)
        if ! check_pid $DBSCALE_PID
        then
            echo -e "Starting DBScale...\c"
            dbscale_start
            sleep 2
            DBSCALE_PID=`cat $DBSCALE_PID_FILE 2>/dev/null`
            check_pid $DBSCALE_PID && echo "done." || echo "fail."
        else
            echo "DBScale has already been running."
        fi
        ;;
    stop)
        if check_pid $DBSCALE_PID
        then
            echo -e "Stoping DBScale...\c"
            dbscale_stop
            check_pid $DBSCALE_PID && echo "fail." || echo "done."
        else
            echo "DBScale is not running."
        fi
        ;;
    status)
        if check_pid $DBSCALE_PID
        then
            echo "DBScale is running."
            exit 0
        else
            echo "DBScale is not running."
            exit 1
        fi
        ;;
    *)
        echo "Usage: $0 {start|stop|status}"
        exit 1
esac
exit 0
该​服​务​脚​本​将​ DBScale 可​执​行​文​件​依​赖​的​动​态​库​文​件​目​录​ libs 添​加​到​系​统​环​境​变​量​ LD_LIBRARY_PATH 中​,然​后​在​ DBScale 可​执​行​文​件​所​在​目​录​启​动​ DBScale。​
建​议​在​服​务​脚​本​中​将​单​进​程​最​大​句​柄​数​调​整​为​ 10240, backlog 调​整​为​ 1024, 最​大​连​接​数​调​整​为​10240。​方​法​为​:修​改​服​务​脚​本​中​的​ dbscale_start() 函​数​,在​函​数​中​添​加​如​下​两​条​命​令​:
ulimit -n 10240
echo 1024 > /proc/sys/net/ipv4/tcp_max_syn_backlog
echo 10240 > /proc/sys/net/core/somaxconn
DBScale 强​制​使​用​ jemalloc 工​具​,DBScale 安​装​包​内​会​包​含​ libjemalloc.so, 使​用​如​下​命​令​来​引​用​ jemalloc。​
 export LD_PRELOAD=$DBSCALE_PATH/libs/libjemalloc.so
运​行​./dbscale-service.sh start来​启​动​ DBScale。​
DBScale 启​动​成​功​后​会​生​成​ pid 文​件​和​日​志​文​件​。​pid 和​日​志​文​件​的​位​置​是​可​配​的​,默​认​情​况​下​ pid 文​件​ dbscale.pid 位​于​执​行​目​录​中​,日​志​文​件​ dbscale.log 位​于​ /var/log 目​录​中​。​
关​于​日​志​文​件​的​使​用​以​及​ rotate 配​置​请​参​考​第 6 章 日​志​。​

2.7.2. 停​止​DBScale

运​行​ ./dbscale-service.sh stop 来​停​止​程​序​。​

2.8. DBScale 集​群​按​需​安​装​使​用​全​流​程​示​例​

本​示​例​从​集​群​规​划​、​后​端​mysql集​群​的​自​动​安​装​、​dbscale集​群​配​置​、​以​及​简​单​测​试​全​流​程​的​安​装​示​例​。​其​中​包​含​了​带​全​局​表​的​两​级​复​制​集​群​的​配​置​规​划​以​及​集​群​自​动​安​装​工​具​的​使​用​。​
根​据​业​务​需​求​配​置​ DBScale 的​配​置​文​件​ dbscale.conf 以​及​后​端​数​据​库​集​群​主​从​复​制​关​系​。​关​于​配​置​文​件​的​配​置​参​考​第 3 章 配​置​。​以​下​是​后​端​数​据​库​集​群​安​装​配​置​、​主​从​复​制​关​系​配​置​示​例​以​及​相​应​ DBScale 配​置​文​件​。​
(121-3308 表​示​ IP 地​址​为​ xxx.xxx.xxx.121,端​口​为​ 3308 的​数​据​库​服​务​。​)
后​端​数​据​库​集​群​分​布​
图 2.1. 后​端​数​据​库​集​群​分​布​

后​端​数​据​库​集​群​分​布​如​图​,四​台​服​务​器​ 121-124,每​台​服​务​器​上​启​两​个​数​据​库​实​例​,端​口​分​别​为​ 3308,3309,DBScale 端​口​号​为​ 3307 置​于​ 121 上​,123 上​ DBScale 作​为​ standby。​
后​端​数​据​库​集​群​主​从​复​制​关​系​
图 2.2. 后​端​数​据​库​集​群​主​从​复​制​关​系​

整​个​集​群​分​为​两​层​,上​一​层​为​全​局​表​层​,包​含​了​全​局​master节​点​124-3308和​全​局​slave节​点​121-3309。​第​二​层​为​分​区​表​层​,包​含​了​3个​分​区​。​第​一​个​分​区​的​分​区​master为​121-3308,slave为​122-3309。​第​二​个​分​区​的​分​区​master为​122-3308,slave为​123-3309.第​三​个​分​区​的​分​区​master为​123-3308,slave为​124-3309。​
每​个​分​区​的​master通​过​主​从​复​制​从​全​局​master进​行​全​局​表​的​数​据​同​步​。​

2.8.1. 配​置​主​机​ host 文​件​

修​改​集​群​所​有​主​机​的​ /etc/hosts 文​件​,添​加​如​下​信​息​:
10.3.20.121 cms_db1
10.3.20.122 cms_db2
10.3.20.123 cms_db3
10.3.20.124 cms_db4

2.8.2. 后​端​数​据​库​服​务​ MySQL 配​置​安​装​

使​用​如​下​配​置​准​备​ mysql的​配​置​文​件​ my1.cnf ~ my8.cnf,port,basedir,datadir,server_id 需​要​根​据​具​体​情​况​进​行​修​改​,集​群​内​ server_id 不​能​重​复​。​
# Example MySQL config file
#
# The following options will be passed to all MySQL clients
[client]
port      = 3308
socket    = /tmp/mysqld.sock
# Here follows entries for some specific programs

# The MySQL server
[mysqld]
# Basic Settings
port      = 3308 
basedir   = /home/db/mysql
datadir   = /home/db/mysql/datadir 
tmpdir    = /tmp
socket    = /tmp/mysqld.sock

lower-case-table-names = 1
gtid-mode              = on
enforce-gtid-consistency
skip-name-resolve
skip-slave-start
log-slave-updates

# Binlog Settings
log-bin
log_slave_updates
server_id     = 1
binlog-format = row

# Connection Settings
back_log        = 1024
max_connections = 2000
wait_timeout    = 31536000

# Cache Settings
table_open_cache = 2400
sort_buffer_size = 2M
join_buffer_size = 8M
query_cache_size = 256M
query_cache_type = 0

# MyISAM Settings
key_buffer_size      = 8M
read_buffer_size     = 2M
read_rnd_buffer_size = 8M

# Innodb Settings
innodb_file_per_table          = true
innodb_file_format             = Barracuda
innodb_data_file_path          = ibdata1:200M:autoextend
innodb_flush_log_at_trx_commit = 0
innodb_flush_method            = O_DIRECT
innodb_log_buffer_size         = 64M
innodb_log_file_size           = 512M
innodb_log_files_in_group      = 4
innodb_read_io_threads         = 16
innodb_write_io_threads        = 16
innodb_buffer_pool_instances   = 6
innodb_buffer_pool_size        = 6G
innodb_doublewrite             = 0
innodb_support_xa              = 0
innodb_sync_spin_loops         = 64
innodb_thread_concurrency      = 20

# I/O Tuning for SSD
#innodb_io_capacity              = 1000
#innodb_flush_neighbors          = 0
##innodb_flush_neighbor_pages    = none
#innodb_adaptive_flushing        = off
#innodb_change_buffering         = none
#innodb_adaptive_flushing_method = keep_average
#innodb_read_ahead               = 0

[mysqldump]
quick
max_allowed_packet = 16M
socket             = /tmp/mysqld.sock
修​改​使​用​自​动​安​装​脚​本​需​要​用​到​的​配​置​文​件​ dbscale.conf,mysql.conf:
dbscale.conf(可​直​接​使​用​DBScale的​配​置​文​件​,自​动​安​装​脚​本​会​自​动​读​取​配​置​文​件​中​关​于​mysql server的​配​置​信​息​)
mysql.conf
[mysql]
package_path  = /home/test/mysql-package
package_name = mysql.tar.gz
package_dir  = mysql-5.6.12-linux-glibc2.5-x86_64

[data-server global_master]
need_install  = 1
need_package  = 1
package_path  = /tmp
force_install = 1
source_conf   = my1.cnf
target_conf   = /usr/local/mysql/my1.cnf

[data-server partition1_master]
need_install  = 1
need_package  = 1
package_path  = /tmp
force_install = 1
source_conf   = my2.cnf
target_conf   = /usr/local/mysql/my2.cnf

[data-server partition2_master]
need_install  = 1
need_package  = 1
package_path  = /tmp
force_install = 1
source_conf   = my3.cnf
target_conf   = /usr/local/mysql/my3.cnf

[data-server partition3_master]
need_install  = 1
need_package  = 1
package_path  = /tmp
force_install = 1
source_conf   = my4.cnf
target_conf   = /usr/local/mysql/my4.cnf

[data-server global_slave]
need_install  = 1
need_package  = 1
package_path  = /tmp
force_install = 1
source_conf   = my5.cnf
target_conf   = /usr/local/mysql/my5.cnf

[data-server partition1_slave]
need_install  = 1
need_package  = 1
package_path  = /tmp
force_install = 1
source_conf   = my6.cnf
target_conf   = /usr/local/mysql/my6.cnf

[data-server partition2_slave]
need_install  = 1
need_package  = 1
package_path  = /tmp
force_install = 1
source_conf   = my7.cnf
target_conf   = /usr/local/mysql/my7.cnf

[data-server partition3_slave]
need_install  = 1
need_package  = 1
package_path  = /tmp
force_install = 1
source_conf   = my8.cnf
target_conf   = /usr/local/mysql/my8.cnf
将​写​好​的​ MySQL 配​置​文​件​ my1.cnf - my8.cnf 放​到​安​装​脚​本​所​在​目​录​下​,使​用​自​动​安​装​脚​本​ auto_install.sh 安​装​后​端​ MySQL 实​例​:
./auto_install.sh -d dbscale.conf -m mysql.conf

2.8.3. DBScale 安​装​配​置​

参​考​第 2.2 节 “安​装​DBScale”安​装​ DBScale 以​及​第 2.3 节 “安​装​license ”安​装​ license 。​认​证​数​据​源​配​置​时​的​注​意​事​项​请​参​考​authenticate-source。​配​置​ DBScale 配​置​文​件​ dbscale.conf ,示​例​如​下​:
[main]
driver = mysql
log-level = INFO
log-file = dbscale.log
admin-user = dbscale
admin-password = dbscale
authenticate-source = auth
#enable-xa-transaction=1
support-gtid=1
max-replication-delay = 5000

connection-pool-admin-interval=60
conn-pool-num=7
thread-pool-min=30
thread-pool-max=1000
thread-pool-low=50
handler-thread-pool-num=7
backlog = 10240
use-partial-parse = 1
lower-case-table-names = 1

[data-source auth]
type = replication
user = dbscale
password = dbscale
master = auth_master-30-1000-50-400
slave = auth_slave-30-1000-50-400

[driver mysql]
type = MySQLDriver
port = 3307
bind-address = 0.0.0.0

[catalog def]
data-source = rep

[table mom.mom_merch_base]
type = partition
partition-scheme = part
partition-key = mer_in_id
independence = 0

[partition-scheme part]
partition = par1_rep
partition = par2_rep
partition = par3_rep

[data-source rep]
type = replication
user = dbscale
password = dbscale
master = global_master-30-1000-50-400
slave = global_slave-30-1000-50-400
slave-source = par1_rep
slave-source = par2_rep
slave-source = par3_rep

[data-source par1_rep]
type = replication
user = dbscale
password = dbscale
master = partition1_master-30-1000-50-400
slave = partition1_slave-30-1000-50-400

[data-source par2_rep]
type = replication
user = dbscale
password = dbscale
master = partition2_master-30-1000-50-400
slave = partition2_slave-30-1000-50-400

[data-source par3_rep]
type = replication
user = dbscale
password = dbscale
master = partition3_master-30-1000-50-400
slave = partition3_slave-30-1000-50-400

[data-server global_master]
host = 10.3.20.124
port = 3308
user = dbscale
password = dbscale
remote-user = root
remote-password = abc123

[data-server partition1_master]
host = 10.3.20.121
port = 3308
user = dbscale
password = dbscale
remote-user = root
remote-password = abc123

[data-server partition2_master]
host = 10.3.20.122
port = 3308
user = dbscale
password = dbscale
remote-user = root
remote-password = abc123

[data-server partition3_master]
host = 10.3.20.123
port = 3308
user = dbscale
password = dbscale
remote-user = root
remote-password = abc123

[data-server global_slave]
host = 10.3.20.121
port = 3309
user = dbscale
password = dbscale
remote-user = root
remote-password = abc123

[data-server partition1_slave]
host = 10.3.20.122
port = 3309
user = dbscale
password = dbscale
remote-user = root
remote-password = abc123

[data-server partition2_slave]
host = 10.3.20.123
port = 3309
user = dbscale
password = dbscale
remote-user = root
remote-password = abc123

[data-server partition3_slave]
host = 10.3.20.124
port = 3309
user = dbscale
password = dbscale
remote-user = root
remote-password = abc123

[data-server auth_master]
host = 10.3.20.124
port = 13308
user = dbscale
password = dbscale
remote-user = root
remote-password = abc123

[data-server auth_slave]
host = 10.3.20.121
port = 13309
user = dbscale
password = dbscale
remote-user = root
remote-password = abc123
参​考​第 2.7.1 节 “启​动​DBScale”启​动​ DBScale 。​
检​测​ DBScale 工​作​状​态​是​否​正​确​:登​录​ DBScale ,执​行​语​句​
CREATE DATABASE mom;
USE mom;
CREATE TABLE mom_merch_base(mer_in_id INT, data INT);
CREATE TABLE global_table(c INT);
INSERT INTO mom_merch_base VALUES(1,1);
INSERT INTO global_table VALUES(1);
执​行​ SHOW TABLES; 确​认​表​已​经​创​建​,执​行​ SELECT * FROM mom_merch_base; SELECT * FROM global_table; 确​认​表​数​据​正​确​。​
登​录​后​台​所​有​ MySQL 执​行​ SHOW TABLES; 确​认​全​局​表​正​确​创​建​,执​行​ SELECT * FROM global_table; 确​认​全​局​表​数​据​正​确​。​
登​录​后​台​所​有​分​区​表​ master 和​ slave 节​点​所​在​ MySQL 服​务​执​行​ SHOW TABLES; 确​认​分​区​表​正​确​创​建​,执​行​ SELECT * FROM mon_merch_base; 确​认​分​区​表​数​据​正​确​。​
检​测​ DBScale 工​作​正​常​后​删​除​测​试​表​:
DROP TABLE mom_merch_base;
DROP TABLE global_table;

2.9. DBScale使​用​限​制​与​建​议​

DBScale目​前​有​如​下​使​用​限​制​与​建​议​:
  1. 不​能​以​dbscale开​头​作​为​表​名​和​库​名​。​
  2. 库​名​、​表​名​、​列​名​中​不​能​包​含​字​符​ ”​.”​。​
  3. 对​于​用​``声​明​的​数​据​库​对​象​名​,不​支​持​在​``中​再​使​用​`。​例​如​dbscale的​解​析​器​不​支​持​如​下​sql语​句​ select 1 as ```a`;
  4. 禁​止​直​接​操​作​集​群​的​系​统​库​,包​括​dbscale开​头​的​库​、​以​及​mysql库​。​
  5. 禁​止​直​接​连​接​集​群​后​端​节​点​进​行​数​据​操​作​,所​有​操​作​需​要​走​集​群​的​dbscale节​点​。​
  6. 通​常​业​务​表​引​擎​最​好​统​一​, 建​议​都​使​用​innodb引​擎​。​
    但​对​于​两​级​复​制​的​场​景​,常​见​的​部​署​方​式​是​全​局​表​使​用​innodb引​擎​,而​分​片​表​使​用​tokudb引​擎​。​
    建​议​建​表​时​直​接​指​定​引​擎​。​
  7. 表​要​有​主​键​或​者​索​引​(无​关​数​据​量​大​小​)。​对​于​innodb表​,建​议​使​用​主​键​。​对​于​tokudb表​建​议​不​要​使​用​主​键​或​唯​一​键​,但​一​定​要​有​索​引​。​
  8. DBScale 不​保​证​跨​数​据​库​实​例​的​外​键​约​束​的​正​确​性​, 建​表​时​最​好​不​要​指​定​. 如​果​主​键​或​唯​一​键​不​是​分​区​列​,不​能​在​全​局​保​证​唯​一​性​约​束​。​
  9. 禁​止​使​用​create select来​创​建​表​。​
  10. 禁​止​创​建​临​时​表​。​
  11. 禁​止​在​事​务​中​使​用​存​储​过​程​的​cursor。​
  12. 登​陆​dbscale后​默​认​的​当​前​schema是​information_schema,该​行​为​与​mysql是​不​一​致​的​,所​以​如​果​没​有​制​定​schema登​陆​之​后​直​接​操​作​表​不​会​报​ no database selected的​错​误​,而​是​Access denied。​所​以​进​行​表​操​作​前​需​先​use到​对​应​的​库​下​。​
  13. 对​于​MySQL的​DML语​句​的​使​用​限​制​请​参​考​第 14 章 DML 语​句​。​
    其​中​load data能​够​支​持​多​字​符​的​ FIELDS TERMINATED 和​LINES TERMINATED 作​为​分​隔​符​,但​两​者​的​首​字​符​不​能​相​同​,load data其​他​相​关​的​使​用​限​制​请​参​考​第 14.8 节 “LOAD DATA INFILE 语​句​”;
    其​中​update/delete不​支​持​同​时​修​改​/删​除​多​张​表​,update/delete其​他​相​关​的​使​用​限​制​请​参​考​第 14.4 节 “DELETE 与​ UPDATE 语​句​”;
    其​中​select语​句​相​关​的​使​用​限​制​请​参​考​第 14.11 节 “SELECT 语​句​”;
  14. 不​支​持​flush tables with read lock 以​外​的​flush语​句​。​
  15. 对​于​MySQL的​管​理​语​句​的​使​用​限​制​请​参​考​第 12 章 MySQL 数​据​库​管​理​语​句​。​
    其​中​set语​句​不​支​持​set global, set的​其​他​使​用​限​制​参​考​第 12.4 节 “SET 语​法​”。​
    不​支​持​kill query,只​支​持​kill。​
  16. 对​于​MySQL的​DDL语​句​的​使​用​限​制​请​参​考​第 13 章 DDL 语​句​。​
  17. 对​于​MySQL的​权​限​认​证​的​使​用​限​制​请​参​考​第 8 章 DBScale 权​限​认​证​。​
  18. 分​区​表​pattern模​式​不​要​有​重​复​, 也​就​是​一​个​表​名​不​能​匹​配​多​个​pattern。​
  19. 业​务​启​动​后​如​需​要​创​建​新​库​(该​库​需​要​分​布​式​部​署​,且​未​在​dbscale配​置​文​件​中​配​置​), 需​要​先​修​改​配​置​(改​配​置​文​件​重​启​或​动​态​修​改​配​置​),然​后​再​创​建​。​
  20. 如​果​需​要​修​改​一​张​表​的​拓​扑​,需​要​先​DROP这​张​表​,修​改​配​置​重​启​或​动​态​调​整​后​再​进​行​新​建​。​
  21. 动​态​操​作​后​需​要​相​应​调​整​配​置​文​件​。​
  22. DBScale Function 方​面​的​使​用​与​限​制​请​参​考​第 16.1 节 “信​息​函​数​”。​
  23. 当​ dbscale 处​于​事​务​状​态​,如​果​执​行​语​句​失​败​,dbscale的​默​认​行​为​是​回​滚​整​个​事​务​. 当​ dbscale 在​锁​状​态​下​, 如​果​后​端​某​台​机​器​宕​机​, DBScale 会​自​动​做​切​换​, 但​是​此​时​的​锁​状​态​可​能​是​不​完​整​的​, 不​会​在​新​切​换​的​机​器​上​加​锁​。​DBScale 可​以​通​过​动​态​设​置​选​项​ enable-auto-unlock-during-error 来​控​制​锁​状​态​下​出​错​的​行​为​.该​选​项​控​制​ DBScale 在​锁​状​态​下​,如​果​执​行​语​句​失​败​,是​否​自​动​执​行​ unlock 操​作​。​

2.10. DBScale 云​上​安​装​的​注​意​事​项​

2.10.1. DBScale 在​青​云​安​装​的​注​意​事​项​

DBScale 目​前​暂​时​无​法​识​别​青​云​ RDS 后​端​ server 的​切​换​行​为​,切​换​行​为​被​浮​动​ IP 屏​蔽​了​,DBScale 仅​能​判​定​其​为​网​络​抖​动​,相​关​改​进​的​开​发​工​作​正​在​进​行​中​。​
目​前​,青​云​ RDS 后​端​ server 切​换​时​可​能​带​着​一​些​正​在​执​行​中​的​连​接​,这​些​连​接​被​带​到​ slave 上​后​可​能​继​续​修​改​数​据​,导​致​主​从​双​写​的​问​题​,相​关​改​进​的​开​发​工​作​正​在​进​行​中​;由​于​被​带​到​ slave 上​的​连​接​需​要​等​到​ wait_timeout 时​间​之​后​才​能​释​放​,在​此​期​间​ slave 的​连​接​数​会​被​部​分​占​用​,导​致​ DBScale 有​可​能​无​法​创​建​到​青​云​后​端​ RDS 的​连​接​,所​以​建​议​在​青​云​上​部​署​ DBScale 集​群​时​将​ wait_timeout 适​当​调​小​,以​减​少​上​述​情​况​下​连​接​被​占​用​的​时​间​。​

第 3 章 配​置​

本​章​将​详​细​介​绍​如​何​使​用​命​令​行​参​数​和​配​置​文​件​对​ DBScale 进​行​配​置​。​
DBScale选​项​汇​总​:
名​称​ 命​令​行​参​数​ 配​置​文​件​选​项​
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x x
x x
x x
x
x
x
x
x
x
x
x
x
x
x x
x
x
x
x
x
x
x
x
x
x
x x
x x
x x
x
x
x
x
x
x
x
x
x
x
x
x x
x x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x x
x x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x x
x
x
x
x
x
x
x
x x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x

3.1. DBScale 配​置​概​述​

DBScale 配​置​主​要​通​过​命​令​行​参​数​和​配​置​文​件​两​种​方​式​。​
命​令​行​参​数​提​供​了​一​些​简​单​配​置​选​项​,主​要​是​定​义​ DBScale 相​关​的​配​置​文​件​、​pid 文​件​、​以​及​日​志​文​件​的​位​置​,除​此​之​外​命​令​行​参​数​还​提​供​了​ DBScale 的​ help 和​版​本​信​息​。​
绝​大​部​分​的​配​置​需​要​在​配​置​文​件​中​完​成​。​DBScale 配​置​文​件​为​ dbscale.cnf,通​常​情​况​下​该​文​件​位​于​ dbscale 的​执​行​目​录​,但​可​以​通​过​命​令​行​参​数​ config-file 指​定​到​其​他​路​径​。​
DBScale 的​配​置​文​件​为​标​准​的​ INI 配​置​文​件​由​ section 和​ option 构​成​。​
主​要​的​ section:
类​名​称​ 是​否​有​实​例​名​称​ 说​明​
main N 包​含​了​ DBScale 的​全​局​配​置​选​项​
catalog Y 包​含​了​ catalog 数​据​空​间​的​配​置​选​项​
black-white N DBScale 的​黑​白​名​单​列​表​
data-source Y 包​含​了​数​据​源​的​配​置​选​项​
data-server Y 包​含​了​ server 信​息​的​配​置​选​项​
driver Y 包​含​了​后​端​数​据​库​集​群​类​型​,以​及​ DBScale 对​外​的​提​供​服​务​接​口​相​关​的​选​项​
partition-scheme Y 包​含​了​分​区​规​划​的​配​置​选​项​
read-only-procedure N 需​要​发​往​读​写​分​离​集​群​中​读​节​点​的​存​储​过​程​列​表​
schema Y 包​含​了​ schema 数​据​空​间​的​配​置​选​项​
table Y 包​含​了​ table 数​据​空​间​的​配​置​选​项​
DBScale 中​除​了​ main section , read-only-procedure section , black-white外​,其​他​的​ section 都​有​实​例​名​称​。​实​例​名​称​使​用​来​区​分​同​一​种​类​型​ section 的​不​同​配​置​实​例​。​例​如​:[schema db1] 和​ [schema db2]两​个​ section 分​别​包​含​的​是​对​ db1 和​ db2 两​个​ schema 的​配​置​信​息​。​
section 的​“​类​名​称​+实​例​名​称​”​为​该​ section 的​名​称​,DBScale 不​允​许​有​两​个​同​名​的​ section 存​在​。​
section 中​的​实​例​名​称​中​不​能​包​含​特​殊​字​符​‘​*’​。​
除​了​ main 和​ driver 两​类​ section 外​,其​他​的​ section 都​是​用​来​描​述​ DBScale 如​何​组​织​和​管​理​后​端​的​数​据​库​集​群​:
  • data-server 定​义​了​后​端​ server 即​数​据​库​实​例​的​物​理​分​布​信​息​,主​要​包​括​了​用​于​创​建​数​据​库​连​接​所​需​的​相​关​选​项​。​
  • 在​ data-server 的​基​础​上​, data-source 描​述​了​ DBScale 如​何​去​组​织​和​管​理​数​据​源​。​所​谓​的​数​据​源​就​是​提​供​数​据​库​连​接​用​来​具​体​执​行​客​户​端​请​求​的​一​组​数​据​库​实​例​。​在​ data-source 中​定​义​了​这​组​数​据​库​实​例​的​组​织​结​构​以​及​相​应​的​工​作​模​式​,例​如​基​于​主​从​复​制​的​读​写​分​离​。​
  • DBScale的​数​据​空​间​与​数​据​库​中​的​数​据​空​间​相​相​对​应​,如​表​、​库​等​。​每​个​数​据​空​间​中​都​会​包​含​一​个​数​据​源​。​数​据​源​指​明​了​数​据​空​间​中​的​数​据​保​存​再​哪​个​数​据​源​上​。​。​例​如​: table 数​据​空​间​[table test.t1]包​含​了​数​据​源​ data-source1,即​data-source1提​供​了​test.t1这​个​表​数​据​空​间​的​数​据​,所​以​ DBScale 会​使​用​ data-source1 中​的​数​据​库​连​接​来​处​理​表​ test.t1 相​关​的​请​求​。​DBScale 支​持​的​数​据​空​间​有​ catalog、​schema、​table。​粒​度​小​的​数​据​空​间​在​执​行​过​程​中​会​优​先​被​查​找​。​当​ DBScale 要​执​行​一​条​ sql 语​句​的​时​候​,它​会​先​找​该​语​句​相​关​的​ table 是​否​有​定​义​好​的​表​数​据​空​间​,如​果​没​有​就​找​该​表​所​在​的​ schema 是​否​有​定​义​好​的​库​数​据​空​间​,如​果​还​是​没​有​就​使​用​ catalog 数​据​空​间​中​的​数​据​源​。​
  • 当​涉​及​到​分​区​表​的​时​候​,就​需​要​定​义​分​区​规​划​ partition-scheme。​partition-scheme 是​一​组​ data-source,每​个​ datasouce 只​可​以​访​问​分​区​表​的​部​分​数​据​,data-source 与​ data-source 之​间​没​有​交​集​,只​有​它​们​合​到​一​起​才​能​访​问​到​分​区​表​的​全​部​数​据​。​所​以​可​以​将​ partition-scheme 看​成​是​一​种​特​殊​的​数​据​源​。​
  • 默​认​情​况​下​,如​果​存​储​过​程​可​以​直​接​发​到​单​个​数​据​源​上​执​行​,DBScale 会​默​认​将​其​发​往​该​数​据​源​的​写​节​点​上​执​行​(比​如​读​写​分​离​或​主​从​复​制​等​数​据​源​),为​了​降​低​写​节​点​的​压​力​,如​果​用​户​确​认​该​存​储​过​程​不​包​含​写​操​作​,此​时​就​可​以​通​过​配​置​ read-only-procedure 来​强​制​将​该​存​储​过​程​发​往​该​数​据​源​的​读​节​点​,注​意​参​数​形​式​必​须​包​含​ schema 名​称​,即​ procedure-name = db_name.procedure_name 的​形​式​,未​列​出​的​存​储​过​程​将​被​ DBScale 视​为​需​要​发​往​写​节​点​。​

3.2. 命​令​行​参​数​

使​用​方​式​为​ :
shell> dbscale [option]
目​前​支​持​的​命​令​行​参​数​主​要​有​:
  • config-file
    Command-Line Format --config-file=#
    Type string
    Multiple Value N
    Default Value Dbscale.conf
    Description 指​定​配​置​文​件​的​位​置​
  • driver
    Command-Line Format --driver=#
    Option-File Format driver=#
    Type string
    Multiple Value N
    Default Value 无​
    Description 使​用​那​个​配​置​文​件​中​那​个​ driver section 配​置​实​例​。​该​选​项​的​值​为​对​应​ driver section 配​置​实​例​的​实​例​名​称​。​
  • help
    Command-Line Format --help
    Description 打​印​帮​助​信​息​
  • include-file
    Command-Line Format --include-file=#
    Option-File Format include-file=#
    Type string
    Multiple Value Y
    Default Value 无​
    Description 指​定​ include 的​配​置​文​件​路​径​
    DBScale 在​主​配​置​文​件​的​基​础​上​,支​持​ include 其​他​子​配​置​文​件​。​被​ include-file 指​定​的​子​配​置​文​件​名​可​以​是​任​意​后​缀​文​件​名​。​ 在​所​有​的​配​置​文​件​范​围​内​,不​允​许​出​现​同​名​的​ section。​
    提​供​子​配​置​文​件​主​要​是​为​了​便​于​配​置​文​件​的​管​理​,同​时​避​免​单​一​配​置​文​件​过​大​过​于​复​杂​。​例​如​:可​以​将​具​体​的​ data-space、​data-source 和​ data-server 的​配​置​按​业​务​分​散​到​不​同​的​子​配​置​文​件​中​。​
  • include-dir
    Command-Line Format --include-dir=#
    Option-File Format include-dir=#
    Type string
    Multiple Value Y
    Default Value 无​
    Description 指​定​ include 配​置​文​件​的​目​录​路​径​。​
    不​同​于​ include-file 选​项​,include-dir 指​定​的​是​一​个​配​置​文​件​目​录​,该​目​录​下​的​配​置​文​件​必​须​以​“​.conf”​结​尾​。​类​似​于​ include-file,在​所​有​的​配​置​文​件​范​围​内​,不​允​许​出​现​同​名​的​ section。​
  • log-level
    Command-Line Format --log-level=#
    Option-File Format log-level=#
    Type string
    Multiple Value N
    Default Value 无​
    Range ERROR WARN INFO DEBUG
    DynamicSet Y
    Description 日​志​级​别​
  • log-file
    Command-Line Format --log-file=#
    Option-File Format log-file=#
    Type string
    Multiple Value N
    Default Value 无​
    Description 指​定​日​志​文​件​的​输​出​位​置​
  • pid-file
    Command-Line Format --pid-file=#
    Option-File Format pid-file=#
    Type string
    Multiple Value N
    Default Value 无​
    Description 指​定​ pid 文​件​的​输​出​位​置​
  • version
    Command-Line Format --version
    Description 打​印​版​本​信​息​

3.3. 配​置​文​件​选​项​

3.3.1. main section

"main" section 主​要​定​义​了​ DBScale 运​行​过​程​中​所​需​要​一​些​全​局​的​选​项​。​
  • driver
    同​命​令​行​参​数​中​的​ driver
  • include-file
    同​命​令​行​参​数​中​的​ include-file
  • include-dir
    同​命​令​行​参​数​中​的​ include-dir
  • log-level
    同​命​令​行​参​数​中​的​ log-level
  • log-file
    同​命​令​行​参​数​中​的​ log-file
  • pid-file
    同​命​令​行​参​数​中​的​ pid-file
  • admin-user
    Option-File Format admin-user=#
    Type string
    Multiple N
    Default Value root
    Scope GLOBAL
    DynamicSet N
    Description 管​理​连​接​的​用​户​名​。​
    为​了​便​于​对​后​端​数​据​库​集​群​的​管​理​,DBScale 会​为​每​个​ data-server 创​建​一​个​管​理​连​接​。​通​过​该​连​接​,DBScale 可​以​获​取​后​端​数​据​库​实​例​的​状​态​,并​且​执​行​管​理​命​令​。​管​理​连​接​的​创​建​需​要​用​户​名​和​密​码​,用​户​名​由​ admin-user 给​出​,密​码​由​ admin-password 给​出​。​
    当​需​要​修​改​ admin-user 或​者​ admin-password 时​,需​要​先​停​止​ dbscale 进​程​,然​后​修​改​配​置​文​件​,之​后​才​可​以​在​后​端​所​有​数​据​库​实​例​上​(复​制​集​群​只​需​要​在​主​节​点​上​做​)进​行​ CREATE USER/ALTER USER 等​相​关​修​改​,最​后​再​重​新​启​动​ dbscale 进​程​。​
  • admin-password
    Option-File Format admin-password=#
    Type string
    Multiple N
    Default Value ""
    Scope GLOBAL
    DynamicSet N
    Description 管​理​连​接​的​密​码​
    关​于​管​理​连​接​,详​见​ admin-user。​
  • always-reset-session-var
    Option-File Format always-reset-session-var=#
    Type int
    Multiple N
    Range 0, 1
    Default Value 0
    Scope GLOBAL
    DynamicSet Y
    Description 是​否​每​次​获​取​新​连​接​执​行​语​句​前​,都​重​置​这​条​连​接​的​ session 变​量​, 默​认​值​为​0,也​就​是​不​开​启​。​如​果​出​现​连​接​的​session变​量​与​保​存​的​变​量​值​不​同​现​象​,可​以​将​这​个​值​设​置​为​1,那​么​所​有​连​接​都​会​重​置​session变​量​值​。​将​值​设​置​为​1后​,因​为​要​额​外​发​送​语​句​,所​以​性​能​会​下​降​,建​议​默​认​不​开​启​。​这​个​选​项​可​以​动​态​配​置​。​
  • authenticate-source
    Option-File Format authenticate-source=#
    Type string
    Multiple N
    Range 配​置​文​件​中​的​ data-source 实​例​名​
    Scope GLOBAL
    DynamicSet N
    Description DBScale 的​登​录​认​证​数​据​源​。​
    DBScale 总​是​从​ authenticate-source 指​定​的​数​据​源​取​连​接​来​执​行​客​户​端​的​登​录​认​证​请​求​。​
    DBScale 不​允​许​ authenticate-source 所​指​定​的​数​据​源​被​用​于​除​登​录​认​证​以​外​的​用​途​,即​该​数​据​源​不​能​被​配​置​到​任​何​数​据​空​间​或​ partiton-scheme 下​,否​则​ DBScale 会​在​启​动​的​时​候​报​错​。​但​可​以​与​config-source共​用​,参​考​配​置​config-source。​。​
    DBScale 默​认​不​允​许​认​证​数​据​源​与​其​他​用​于​存​储​数​据​的​数​据​源​共​用​数​据​库​实​例​,且​默​认​要​求​认​证​数​据​源​必​须​为​主​从​复​制​类​型​的​数​据​源​。​如​果​想​关​闭​这​两​个​限​制​,请​参​考​配​置​选​项​restrict-auth-source-topo。​关​闭​该​选​项​后​,如​果​认​证​数​据​源​不​与​其​他​数​据​源​共​用​数​据​库​实​例​,有​可​能​导​致​ USE DATABASE 语​句​失​败​。​
    DBScale 禁​止​使​用​odbc数​据​源​作​为​ authenticate-source。​
  • auto-inc-lock-mode
    Option-File Format auto-inc-lock-mode=#
    Type int
    Multiple N
    Default 2
    Range 0,1,2
    Scope GLOBAL
    DynamicSet N
    Description DBScale的​ AUTO_INCREMENT 字​段​的​锁​模​式​。​
    0 表​示​TRADITIONAL,1 表​示​CONSECUTIVE,2 表​示​INTERLEAVED。​
    DBScale 自​增​字​段​的​锁​模​式​配​置​与​MySQL的​3种​模​式​对​应​,但​目​前​ TRADITIONAL 和​ CONSECUTIVE 的​实​际​实​现​和​效​果​是​一​样​的​。​
    INTERLEAVED 模​式​下​,因​为​获​取​自​增​值​会​频​繁​执​行​获​取​锁​操​作​,会​影​响​性​能​,DBScale 有​做​优​化​,当​一​个​客​户​端​对​一​张​表​进​行​三​次​以​上​自​增​插​入​操​作​,DBScale 会​一​次​性​为​这​个​客​户​端​分​配​ 10 个​自​增​值​,来​避​免​锁​竞​争​,多​客​户​端​插​入​时​会​导​致​自​增​值​不​连​续​,但​是​会​保​证​自​增​值​的​唯​一​,提​高​效​率​。​
  • auto-space-level
    Option-File Format auto-space-level=#
    Type int
    Multiple N
    Default 0
    Range 0,1
    Scope GLOBAL
    DynamicSet Y
    Description DBScale自​动​创​建​dataspace的​模​式​。​
    0 表​示​ DBScale 将​不​会​隐​式​地​自​动​创​建​dataspace,所​有​dataspace需​要​提​前​创​建​或​通​过​特​定​的​create table扩​展​语​法​进​行​创​建​。​
    1 表​示​ DBScale 会​自​动​地​为​ create database 语​句​创​建​的​dataspace 数​据​域​分​配​一​个​数​据​源​,数​据​源​将​轮​循​地​使​用​最​后​一​个​配​置​的​partition_scheme中​的​source。​
  • backend-sql-net-timeout
    Option-File Format backend-sql-net-timeout=#
    Type int
    Multiple N
    Default Value 5 (s)
    Range >0
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 后​台​操​作​的​SQL的​超​时​时​间​,例​如​获​取​表​的​元​数​据​信​息​。​
  • backend-thread-pool-max
    Option-File Format backend-thread-pool-max=#
    Type int
    Multiple N
    Default Value 2048
    Range >=1
    Scope GLOBAL
    DynamicSet N
    Description 后​端​线​程​池​的​最​大​线​程​数​。​
  • backend-thread-pool-min
    Option-File Format backend-thread-pool-min=#
    Type int
    Multiple N
    Default Value 10
    Range >=1
    Scope GLOBAL
    DynamicSet N
    Description 后​端​线​程​池​的​初​始​线​程​数​。​
  • backend-thread-pool-low
    Option-File Format backend-thread-pool-low=#
    Type int
    Multiple N
    Default Value 100
    Range >=1
    Scope GLOBAL
    DynamicSet N
    Description 后​端​线​程​池​的​低​阀​值​线​程​数​。​
  • backend-thread-pool-num
    Option-File Format backend-thread-pool-num=#
    Type int
    Multiple N
    Default Value 1
    Range >=1
    Scope GLOBAL
    DynamicSet N
    Description 后​端​线​程​池​的​数​量​。​如​果​配​置​这​个​值​为​大​于​1,请​注​意​后​端​线​程​池​内​的​线​程​总​数​最​小​是​ backend-thread-pool-num×backend-thread-pool-min,最​大​是​ backend-thread-pool-num×backend-thread-pool-max。​
  • backlog
    Option-File Format backlog=#
    Type int
    Multiple N
    Default 500
    Range >0
    Scope GLOBAL
    DynamicSet N
    Description 配​置​ DBScale 的​ backlog 值​
    该​值​用​于​配​置​ DBScale 的​ backlog 大​小​,默​认​值​为​5,在​并​发​量​较​大​时​,建​议​调​大​该​值​。​
  • check-auto-increment-value
    Option-File Format check-auto-increment-value=#
    Type unsigned int
    Multiple N
    Default Value 1
    Scope GLOBAL
    DynamicSet Y
    Description 在​对​分​片​表​自​增​表​的​自​增​列​给​定​值​的​插​入​中​,dbscale是​否​进​行​自​增​合​法​性​检​查​。​1为​默​认​值​,表​示​开​启​;0表​示​关​闭​。​
    在​对​分​片​表​自​增​表​的​自​增​列​给​定​值​的​插​入​中​,默​认​情​况​下​dbscale不​允​许​插​入​一​个​小​于​dbscale当​前​维​护​的​自​增​偏​移​量​的​值​。​用​户​可​以​通​过​ check-auto-increment-value=0 关​闭​这​个​检​查​。​关​闭​之​后​,可​能​会​导​致​没​有​给​定​自​增​值​的​insert语​句​应​为​duplicate key错​误​插​入​失​败​,这​时​候​DBA可​以​使​用​命​令​ DBSCALE SHOW AUTO_INCREMENT OFFSET FOR table_name; 第 7.3.35 节 “查​看​某​张​自​增​分​片​表​的​当​前​自​增​值​。​” 和​ DBSCALE DYNAMIC SET table_name AUTO_INCREMENT OFFSET TO auto_increment_value; 第 7.4.13 节 “在​线​调​某​张​自​增​分​片​表​的​自​增​值​” 对​dbscale的​自​增​偏​移​量​进​行​查​看​调​整​,使​之​足​够​大​以​跳​过​可​能​的​插​入​冲​突​区​。​
  • check-master-sync
    Option-File Format check-master-sync=#
    Type unsigned int
    Multiple N
    Default Value 1
    Scope GLOBAL
    DynamicSet Y
    Description 在​切​换​新​ master 节​点​时​, 检​测​新​ master 节​点​上​收​到​的​ binlog 是​否​已​经​都​应​用​完​成​, 如​果​未​应​用​完​则​等​待​, 该​参​数​支​持​动​态​控​制​。​1为​默​认​值​,表​示​开​启​;0表​示​关​闭​。​
  • close-load-conn
    Option-File Format close-load-conn=#
    Type int
    Multiple N
    Range 0,1
    Scope GLOBAL
    DynamicSet Y
    Description 是​否​关​闭​执​行​过​ LOAD 数​据​操​作​连​接​。​
    当​在​一​个​事​务​内​修​改​大​量​数​据​时​(比​如​ LOAD DATA),后​端​ server 会​创​建​若​干​临​时​文​件​,这​些​文​件​将​持​续​占​用​后​端​ server 的​存​储​空​间​,直​到​相​关​连​接​被​释​放​。​为​了​及​时​清​理​这​些​临​时​文​件​,可​以​开​启​ DBScale 的​ close-load-conn 参​数​,使​得​ DBScale 在​执​行​完​ LOAD DATA 操​作​后​,及​时​关​闭​相​关​连​接​。​该​问​题​影​响​ mariadb,MySQL 5.6.17 之​前​版​本​以​及​ MySQL 5.7。​
  • cluster-user
    Option-File Format cluster-user=#
    Type string
    Multiple N
    Default Value root
    Scope GLOBAL
    DynamicSet N
    Description 多​dbscale集​群​各​调​度​节​点​间​进​行​互​相​访​问​的​用​户​名​。​与​cluster-password 配​合​使​用​。​
  • cluster-password
    Option-File Format cluster-password=#
    Type string
    Multiple N
    Default Value ""
    Scope GLOBAL
    DynamicSet N
    Description 多​dbscale集​群​各​调​度​节​点​间​进​行​互​相​访​问​的​密​码​。​与​cluster-user 配​合​使​用​。​
  • config-source
    Option-File Format config-source=#
    Type string
    Multiple N
    Range 配​置​文​件​中​的​ data-source 实​例​名​
    Scope GLOBAL
    DynamicSet N
    Description DBScale 的​记​录​动​态​配​置​数​据​源​。​
    DBScale 总​是​从​ config-source 指​定​的​数​据​源​取​连​接​来​记​录​动​态​修​改​的​ DBScale 配​置​。​
    在​迁​移​过​程​中​,DBScale 会​自​动​创​建​数​据​空​间​与​分​区​策​略​,并​在​ config-source 指​定​的​数​据​源​上​保​存​这​些​改​变​,然​后​在​ DBScale 重​启​后​读​取​这​些​配​置​。​
  • connection-pool-manage-interval
    Option-File Format connection-pool-manage-interval=#
    Type int
    Multiple N
    Default Value 5 (s)
    Range >0
    Scope GLOBAL
    DynamicSet N
    Description DBScale 的​连​接​池​进​行​管​理​操​作​的​间​隔​
    连​接​池​是​ DBScale 最​主​要​的​资​源​池​之​一​,它​维​护​着​ DBScale 与​后​端​数​据​库​实​例​之​间​的​数​据​库​连​接​。​每​隔​ connection-pool-manage-interval 秒​,DBScale 就​会​对​连​接​池​进​行​一​次​管​理​操​作​,例​如​进​行​连​接​清​理​。​管​理​操​作​过​程​中​ DBScale 会​对​连​接​池​上​锁​,所​以​该​选​项​不​宜​设​置​过​小​。​
  • connection-timeout
    Option-File Format connection-timeout=#
    Type int
    Multiple N
    Default Value 5 (s)
    Range >0
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 连​接​后​端​数​据​库​服​务​器​的​超​时​时​间​
    该​参​数​主​要​控​制​DBScale创​建​与​后​端​数​据​库​服​务​器​通​信​的​连​接​时​的​超​时​时​间​。​
  • conn-pool-num
    Option-File Format conn-pool-num=#
    Type int
    Multiple N
    Default Value 1
    Range >0
    Scope GLOBAL
    DynamicSet N
    Description DBScale 中​每​个​ server 配​置​的​连​接​池​个​数​。​
    调​大​该​参​数​有​助​于​减​少​ DBScale 集​群​连​接​池​的​锁​竞​争​,提​高​系​统​的​并​发​性​。​需​要​注​意​的​是​,配​置​该​参​数​之​后​,每​个​ server 的​实​际​连​接​数​为​“​每​个​连​接​池​中​连​接​数​”​ * “​conn-pool-num”​;每​个​连​接​池​中​的​连​接​数​参​考​ server [data-source.server]。​
  • cross-node-join-method
    Option-File Format cross-node-join-method=#
    Type int
    Multiple N
    Default Value 0
    Range 0,1
    Scope SESSION
    DynamicSet Y
    Description DBScale 执​行​跨​节​点​ join 时​使​用​的​方​式​。​
    0 为​使​用​创​建​临​时​表​存​储​中​间​结​果​集​的​方​式​来​执​行​ join 语​句​,1 为​使​用​创​建​ federated 临​时​表​的​方​式​来​执​行​ join 语​句​。​
  • current-status-command-file
    Option-File Format current-status-command-file=#
    Type string
    Multiple N
    Default Value flush_command
    Scope GLOBAL
    DynamicSet N
    Description 当​ DBScale 出​现​故​障​时​,无​法​登​陆​ DBScale, 可​以​使​用​信​号​(kill -10 dbscale.pid)让​ DBScale 来​执​行​一​些​收​集​命​令​, 将​命​令​保​存​在​ current-status-command-file 这​个​文​件​中​, 命​令​执​行​的​结​果​将​保​存​在​文​件​ current-status-result-file 中​。​
    目​前​支​持​的​命​令​有​:
    dbscale show user status;
    dbscale show thread pool info;
    dbscale show connection pool;
    DBScale set 命令, 如 dbscale set instance log_level='INFO';
    
  • current-status-result-file
    Option-File Format current-status-result-file=#
    Type string
    Multiple N
    Default Value dbscale_current_status_result
    Scope GLOBAL
    DynamicSet N
    Description 当​ DBScale 出​现​故​障​时​,无​法​登​陆​ DBScale, 可​以​使​用​信​号​(kill -10 dbscale.pid)让​ DBScale 来​执​行​一​些​收​集​命​令​, 将​命​令​保​存​在​ current-status-command-file 这​个​文​件​中​, 命​令​执​行​的​结​果​将​保​存​在​文​件​ current-status-result-file 中​。​
  • datasource-in-one
    Option-File Format datasource-in-one=#
    Type int
    Multiple N
    Default Value 1
    Range 0,1
    Scope GLOBAL
    DynamicSet N
    Description auth-source,config-source,metadata-source是​否​使​用​同​一​个​数​据​源​,0为​不​使​用​,1为​使​用​。​
    Restriction 置​为​1后​,不​用​再​配​置​config-source,metadata-source选​项​,但​是​auth-source不​能​与​其​他​source共​用​server. 如​果​不​开​启​该​选​项​,那​么​通​过​ DBScale 对​ information_schema 库​的​查​询​操​作​都​不​保​证​结​果​集​的​正​确​性​
  • default-login-schema
    Option-File Format default-login-schema=#
    Type string
    Multiple N
    Default Value information_schema
    Scope GLOBAL
    DynamicSet N
    Description 客​户​端​连​接​DBScale时​若​没​有​指​定​schema,则​使​用​此​选​项​的​值​
    客​户​端​连​接​DBScale时​若​没​有​指​定​schema,则​DBScale会​使​用​此​选​项​的​值​作​为​用​户​登​录​的​schema。​
    该​默​认​登​录​ schema 不​可​以​被​ drop。​
  • default-packet-size
    Option-File Format default-packet-size=#
    Type unsigned int
    Multiple N
    Default Value 1024
    Scope GLOBAL
    DynamicSet N
    Description DBScale 收​包​缓​冲​区​大​小​。​
    DBScale 收​包​缓​冲​大​小​,默​认​大​小​为​1024字​节​,即​1KB。​
  • default-user-priority
    Option-File Format default-user-priority=#
    Type int
    Multiple N
    Default Value 1
    Scope GLOBAL
    DynamicSet N
    Description 在​不​为​用​户​设​置​优​先​级​的​情​况​下​,用​户​的​默​认​优​先​级​。​
    DBScale 可​以​指​定​默​认​的​用​户​优​先​级​,在​不​为​有​个​用​户​设​置​优​先​级​的​情​况​下​,该​用​户​的​优​先​级​为​默​认​优​先​级​。​
  • default-session-variables
    Option-File Format default-session-variables=#:#:#:#
    Type string
    Multiple N
    Default Value CHARACTER_SET_CLIENT:CHARACTER_SET_RESULTS: CHARACTER_SET_CONNECTION:NET_READ_TIMEOUT: TIME_ZONE:SQL_SAFE_UPDATES:SQL_MODE: TX_ISOLATION:SQL_SELECT_LIMIT: AUTO_INCREMENT_INCREMENT: AUTO_INCREMENT_OFFSET:NET_WRITE_TIMEOUT: MAX_SORT_LENGTH
    Scope GLOBAL
    DynamicSet N
    Description 设​置​默​认​ session 变​量​,默​认​ session 变​量​的​值​和​验​证​服​务​器​的​初​始​ session 变​量​相​同​。​
    DBScale 可​以​指​定​默​认​的​ session 变​量​,使​每​次​用​户​登​录​时​的​ session 变​量​和​验​证​服​务​器​的​默​认​ session 变​量​相​同​。​若​某​ session 变​量​未​做​该​设​置​,则​用​户​每​次​登​录​时​的​默​认​ session 变​量​的​值​不​确​定​。​
    上​表​中​的​默​认​值​是​dbscale肯​定​会​维​护​的​列​表​,用​户​可​以​通​过​设​置​“​default-session-variables”​参​数​添​加​额​外​需​要​维​护​的​列​表​。​变​了​“​TX_READ_ONLY”​并​不​在​dbscale的​默​认​维​护​列​表​中​,因​为​mysql5.5并​没​有​这​个​参​数​,当​用​户​使​用​mysql5.6即​以​后​版​本​,以​及​maridb10.0及​以​上​版​本​时​,可​以​通​过​default-session-variables配​置​上​“​TX_READ_ONLY”​, 例​如​ default-session-variables = TX_READ_ONLY。​
  • do-audit-log
    Option-File Format do-audit-log=#
    Type string
    Multiple Value N
    Default Value (不​记​录​任​何​ audit 日​志​)
    Range SELECT,DDL
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 的​审​计​日​志​开​关​。​
    DBScale 在​运​行​过​程​中​会​进​行​ SQL 审​计​,审​计​的​语​句​类​型​根​据​设​置​的​值​确​定​。​审​计​日​志​文​件​名​称​为​ DBScale 日​志​名​称​后​面​加​ '_audit',位​置​跟​ DBScale 日​志​相​同​。​
    目​前​只​支​持​登​录​、​SELECT 和​ DDL 的​ audit 日​志​记​录​。​其​中​登​录​不​需​设​置​ do-audit-log 。​
    例​如​,可​以​在​配​置​文​件​的​ [main] section 定​义​要​记​录​ DDL 语​句​的​ audit 日​志​,方​式​如​下​
    [main]
    do-audit-log=DDL
    也​可​以​在​配​置​文​件​的​ [main] section 定​义​要​记​录​ SELECT 和​ DDL 语​句​的​ audit 日​志​,方​式​如​下​
    [main]
    do-audit-log=SELECT,DDL
    在​ DBScale 运​行​过​程​中​,可​以​动​态​调​整​要​记​录​ audit 日​志​的​语​句​类​型​。​例​如​,动​态​调​整​为​只​记​录​ SELECT 语​句​的​ audit 日​志​。​方​式​如​下​
    DBSCALE SET GLOBAL do_audit_log="SELECT";
    也​可​以​关​闭​ audit 日​志​,方​式​如​下​
    DBSCALE SET GLOBAL do_audit_log="";
    只​有​ root 和​ dbscale 用​户​可​以​在​线​调​整​该​参​数​值​。​
    审​计​日​志​内​容​为​ xml 标​签​的​形​式​,其​主​干​格​式​与​ Percona 审​计​插​件​的​内​容​格​式​一​致​,示​例​如​下​
    <AUDIT_RECORD>
      <NAME></NAME>
      <RECORD>2_1477733204121</RECORD>
      <TIMESTAMP>2016-10-29 12:27:30.346482</TIMESTAMP>
      <COMMAND_CLASS></COMMAND_CLASS>
      <CONNECTION_ID>1</CONNECTION_ID>
      <STATUS>0</STATUS>
      <SQLTEXT>create table tt (c1 int)</SQLTEXT>
      <USER>root</USER>
      <HOST>root@localhost</HOST>
      <OS_USER></OS_USER>
      <IP>127.0.0.1</IP>
      <DB>db1</DB>
    </AUDIT_RECORD>
  • dynamic-change-active-wait
    Option-File Format dynamic-change-active-wait=#
    Type int
    Multiple N
    Default Value 2s
    Scope GLOBAL
    DynamicSet Y
    Description 设​置​当​进​行​在​线​调​整​ MultipleMaster 数​据​源​的​ Active 数​据​源​时​,如​果​涉​及​的​节​点​有​连​接​在​使​用​时​的​检​查​周​期​。​
    在​ DBScale 中​进​行​在​线​动​态​调​整​ MultipleMaster 数​据​源​的​ Active 数​据​源​时​,如​果​涉​及​到​的​节​点​正​在​有​连​接​被​使​用​,则​会​周​期​的​检​查​直​到​没​有​连​接​时​才​进​行​调​整​,这​个​选​项​就​是​设​置​这​个​检​查​的​周​期​值​的​,单​位​为​秒​。​
  • dynamic-remove-slave-wait
    Option-File Format dynamic-remove-slave-wait=#
    Type int
    Multiple N
    Default Value 2s
    Scope GLOBAL
    DynamicSet Y
    Description 设​置​进​行​在​线​删​除​从​节​点​时​,如​果​删​除​的​节​点​有​连​接​在​使​用​时​的​检​查​周​期​。​
    在​ DBScale 中​进​行​在​线​动​态​删​除​一​个​从​节​点​时​,如​果​删​除​的​从​节​点​正​在​有​连​接​被​使​用​,则​会​周​期​的​检​查​直​到​没​有​连​接​时​才​进​行​删​除​,这​个​选​项​就​是​设​置​这​个​检​查​的​周​期​值​的​,单​位​为​秒​。​
  • enable-block-table
    Option-File Format enable-block-table=#
    Type int
    Multiple N
    Default Value 0
    Range 0,1
    Scope GLOBAL
    DynamicSet N
    Description DBScale是​否​支​持​阻​塞​表​请​求​命​令​, 同​时​该​选​项​为​迁​移​功​能​的​开​关​, 该​选​项​可​以​动​态​配​置​。​
    0 为​不​允​许​;1 为​允​许​。​
  • enable-listener-off
    Option-File Format enable-listener-off=#
    Type int
    Multiple N
    Default Value 0
    Range 0,1
    Scope GLOBAL
    DynamicSet Y
    Description DBScale是​否​允​许​libevent的​监​听​线​程​参​与​事​件​的​消​费​。​
    0 为​不​允​许​;1 为​允​许​。​该​参​数​只​有​在​enable-session-swap=1的​模​式​才​会​被​使​用​。​
  • enable-record-query-time
    Option-File Format enable-record-query-time=#
    Type int
    Multiple N
    Default Value 1
    Range 0,1
    Scope GLOBAL
    DynamicSet Y
    Description DBScale是​否​记​录​sql语​句​的​执​行​时​间​。​
    0 为​不​记​录​;1 记​录​。​该​参​数​影​响​dbscale show user status中​执​行​时​间​的​输​出​。​
  • enable-get-rep-connection
    Option-File Format enable-get-rep-connection=#
    Type int
    Multiple N
    Default Value 0
    Range 0,1
    Scope GLOBAL
    DynamicSet Y
    Description DBScale是​否​允​许​在​分​片​source的​master节​点​主​从​复​制​异​常​后​提​供​服​务​。​
    0 为​不​允​许​;1 为​允​许​。​该​参​数​在​partition master与​global_master 主​从​异​常​导​致​partition表​不​可​用​时​,需​要​恢​复​服​务​,可​以​设​置​为​1, partition master将​仍​然​可​以​获​取​连​接​。​
  • enable_receive_next_header
    Option-File Format enable_receive_next_header=#
    Type unsigned int
    Multiple N
    Default Value 1
    Scope GLOBAL
    DynamicSet N
    Description DBScale 是​否​开​启​收​包​时​是​否​收​取​下​一​个​包​头​信​息​。​
    DBScale 是​否​在​收​包​时​,收​取​下​一​个​包​的​包​头​数​据​,用​于​优​化​收​包​时​间​。​
  • enable-session-swap
    Option-File Format enable-session-swap=#
    Type int
    Multiple N
    Default Value 1
    Range 0,1
    Scope GLOBAL
    DynamicSet N
    Description DBScale 是​否​在​客​户​端​session空​闲​的​时​候​将​其​从​工​作​线​程​中​换​出​。​
    0 为​一​个​客​户​端​session独​占​一​个​工​作​线​程​;1 为​客​户​端​session共​享​工​作​线​程​池​中​的​工​作​线​程​,当​某​个​客​户​端​session空​闲​的​时​候​它​就​会​交​出​当​前​工​作​线​程​的​使​用​权​。​
    开​启​session swap之​后​,Thread_Pool客​户​端​登​录​线​程​池​的​最​大​值​需​要​根​据​业​务​系​统​可​能​出​现​的​瞬​时​最​大​并​发​登​录​进​行​调​整​,由​参​数​backend-thread-pool-max控​制​。​通​常​建​议​至​少​配​置​为​峰​值​的​20%。​
    开​启​session swap之​后​,若​ DBScale 因​为​某​种​原​因​导​致​集​群​无​法​登​陆​, 可​以​连​接​ "dbscale_admin" 库​, 连​接​该​库​的​连​接​会​被​任​务​是​管​理​连​接​,不​会​进​行​ swap 操​作​。​
  • enable-session-swap-during-execution
    Option-File Format enable-session-swap-during-execution=#
    Type int
    Multiple N
    Default Value 1
    Range 0,1
    Scope GLOBAL
    DynamicSet N
    Description DBScale 是​否​在​客​户​端​session空​闲​的​时​候​将​其​从​工​作​现​场​中​换​出​。​
    只​有​enable-session-swap的​情​况​下​,该​参​数​才​起​作​用​。​
    0 为​一​个​sql语​句​执​行​过​程​中​将​独​占​工​作​线​程​;1 为​sql语​句​执​行​过​程​中​,当​它​等​待​服​务​端​返​回​结​果​集​的​时​候​,它​可​能​会​交​出​当​前​工​作​线​程​的​使​用​权​;是​否​swap由​dbscale根​据​执​行​语​句​的​复​杂​程​度​决​定​。​
    开​启​enable-session-swap和​enable-session-swap-during-execution后​,如​果​突​然​出​现​巨​大​的​客​户​端​并​发​请​求​,且​这​些​请​求​操​作​的​数​据​源​相​同​,可​能​会​导​致​该​数​据​源​的​连​接​资​源​被​瞬​间​耗​尽​并​是​工​作​线​程​阻​塞​在​获​取​连​接​处​,最​终​导​致​集​群​吞​吐​骤​降​。​所​以​建​议​在​session swap模​式​下​,数​据​源​的​连​接​池​最​大​值​配​置​至​少​设​置​为​峰​值​的​30%。​例​如​理​论​上​最​多​可​能​有​10000个​数​据​库​并​发​访​问​操​作​数​据​源​S1,那​么​S1的​单​server的​连​接​池​最​大​值​要​配​置​为​3000(如​果​conn-pool-num=10,那​么​配​置​为​300)。​
  • enable-last-insert-id
    Option-File Format enable-last-insert-id=#
    Type int
    Multiple N
    Default Value 0
    Range 0,1
    Scope GLOBAL
    DynamicSet N
    Description 是​否​开​启​对​ LAST_INSERT_ID 这​个​函​数​的​支​持​。​
    开​启​ LAST_INSERT_ID 函​数​支​持​后​,将​对​修​改​语​句​,如​多​行​插​入​,的​效​率​产​生​一​定​影​响​,主​要​是​添​加​了​更​多​的​检​查​和​元​数​据​维​护​工​作​。​
  • enable-multiple-stmt-check
    Option-File Format enable-multiple-stmt-check=#
    Type int
    Multiple N
    Default Value 1
    Range 0,1
    Scope SESSION
    DynamicSet Y
    Description 是​否​开​启​对​多​语​句​的​检​查​,1为​开​启​,0为​不​开​启​。​在​开​启​状​态​下​,当​语​句​部​分​解​析​时​,如​果​语​句​中​间​存​在​分​号​,或​者​\G,\g时​,dbscale认​为​sql为​多​语​句​,并​抛​出​不​支​持​异​常​。​在​不​开​启​状​态​下​,则​不​认​为​是​多​语​句​,将​语​句​直​接​发​往​后​端​。​
    enable-multiple-stmt-check参​数​支​持​session级​别​在​线​修​改​。​语​句​如​下​:
    DBSCALE SET SESSION enable_multiple_stmt_check=[1|0]
    针​对​如​下​错​误​的​CREATE TABLE语​句​,在​开​启​部​分​解​析​的​前​提​下​,效​果​如​下​:
    DBSCALE SET SESSION enable_multiple_stmt_check=1;
    CREATE TABLE t1 (c1 INT COMMENT "1;2", c2 ssss);
    ERROR : The SQL is not supported by DBScale. Not support multiple stmt in partial parse.
    DBSCALE SET SESSION enable_multiple_stmt_check=0;
    CREATE TABLE t1 (c1 INT COMMENT "1;2", c2 ssss);
    ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ssss)' at line 1
  • enable-auto-unlock-during-error
    Option-File Format enable-auto-unlock-during-error=#
    Type int
    Multiple N
    Default Value 0
    Range 0,1
    Description DBScale 在​锁​状​态​下​,如​果​执​行​语​句​失​败​,是​否​允​许​自​动​执​行​ unlock 操​作​, 该​选​项​支​持​动​态​设​置​。​
  • enable-xa-transaction
    Option-File Format enable-xa-transaction=#
    Type int
    Multiple N
    Default Value 0
    Range 0,1
    Scope GLOBAL
    DynamicSet N
    Description 是​否​开​启​ XA 事​务​模​式​。​
    由​于​目​前​ DBScale 在​ XA 事​务​模​式​下​不​支​持​ savepoint,所​以​在​ enable-xa-transaction 为​ 1 时​,选​项​ use-savepoint 将​被​忽​略​。​
  • exiting-timeout
    Option-File Format exiting-timeout=#
    Type int
    Multiple N
    Default Value 5
    Range >=0
    Scope GLOBAL
    DynamicSet Y
    Description DBScale等​待​客​户​端​请​求​的​周​期​。​
    DBScale 工​作​线​程​采​用​阻​塞​超​时​模​式​等​待​客​户​端​请​求​,超​时​时​间​由​参​数​ exiting-timeout 确​定​。​当​超​时​发​生​时​工​作​线​程​会​检​测​当​前​DBscale工​作​状​态​,如​果​正​常​就​继​续​下​一​个​周​期​的​超​时​等​待​,如​果​处​于​退​出​状​态​将​不​再​等​待​和​读​取​客​户​端​请​求​,处​理​线​程​退​出​。​
  • federated-join-addr
    Option-File Format federated-join-addr=#
    Type string
    Multiple N
    Default Value 127.0.0.1
    Range IP address
    Scope GLOBAL
    DynamicSet N
    Description DBScale 所​在​机​器​ IP。​
    若​配​置​ DBScale 执​行​跨​节​点​ join 的​方​式​为​创​建​ federated 临​时​表​的​方​式​,则​需​要​配​置​ DBScale 的​ IP 地​址​供​ DBScale 执​行​跨​节​点​ join 语​句​时​使​用​。​
  • flush-all-conn-in-group
    Option-File Format flush-all-conn-in-group=#
    Type string
    Multiple N
    Default Value 0
    Range 0,1
    Scope GLOBAL
    DynamicSet Y
    Description 当​检​测​到​网​络​抖​动​,即​临​时​性​ping失​败​,dbscale会​将​对​应​server的​连​接​池​进​行​刷​新​,如​果​flush-all-conn-in-group=1 那​么​和​该​server同​在​一​个​复​制​组​的​其​他​server的​连​接​池​也​会​被​刷​新​,否​则​只​刷​新​检​测​到​临​时​性​ping失​败​的​server的​连​接​池​。​
  • get-connection-retry-times
    Option-File Format get-connection-retry-times=#
    Type int
    Multiple N
    Default Value 20
    Range >=0
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 从​一​个​ data-source 中​获​取​连​接​的​最​大​重​试​次​数​。​
    当​ data-source 处​于​无​法​提​供​服​务​的​状​态​时​(相​应​的​ data-server 宕​机​或​该​ data-source 正​处​于​变​更​状​态​,如​重​新​选​主​),从​该​ data-source 获​取​连​接​会​失​败​。​当​ DBScale 从​ data-source 获​取​连​接​失​败​时​会​尝​试​最​多​ get-connection-retry-times,每​次​间​隔​ n*0.5s(n为​尝​试​次​数​)。​
  • handler-thread-pool-min
    Option-File Format handler-thread-pool-min=#
    Type int
    Multiple N
    Default Value 2
    Range >=1
    Scope GLOBAL
    DynamicSet N
    Description 客​户​端​工​作​线​程​池​的​初​始​线​程​数​。​
    该​参​数​与​handler-thread-pool-num的​乘​积​为​整​个​dbscale的​初​始​客​户​端​工​作​线​程​的​初​始​数​量​。​
  • handler-thread-pool-max
    Option-File Format handler-thread-pool-max=#
    Type int
    Multiple N
    Default Value 100
    Range >=1
    Scope GLOBAL
    DynamicSet N
    Description 客​户​端​工​作​线​程​池​的​最​大​线​程​数​。​
    该​参​数​与​handler-thread-pool-num的​乘​积​为​整​个​dbscale的​初​始​客​户​端​工​作​线​程​的​最​大​数​量​。​
  • handle-monitor-timeout-via-update-method
    Option-File Format handle-monitor-timeout-via-update-method=#
    Type int
    Multiple N
    Default Value 0
    Range 0,1
    Scope GLOBAL
    DynamicSet Y
    Description 是​否​处​理​以​ update 方​式​进​行​ ping 活​检​查​时​出​现​的​超​时​错​误​。​
    当​以​ update 方​式​进​行​ ping 活​检​查​时​,在​某​些​情​况​下​可​能​会​出​现​ update 请​求​超​时​的​现​象​,比​如​此​超​时​错​误​有​可​能​完​全​是​因​为​业​务​需​要​而​使​得​当​前​实​例​处​于​暂​时​的​只​读​模​式​而​导​致​的​。​DBScale 不​能​直​接​判​定​为​本​次​ ping 活​检​查​失​败​。​所​以​ DBScale 为​用​户​提​供​了​一​个​配​置​参​数​ handle-monitor-timeout-via-update-method,用​来​标​记​当​ DBScale 以​ update 方​式​进​行​ ping 活​检​查​出​现​超​时​错​误​时​,是​否​将​该​错​误​判​定​为​一​次​ ping 活​失​败​。​该​选​项​可​以​动​态​配​置​。​超​时​时​间​大​小​的​设​置​见​参​数​monitor-net-timeout。​
  • handler-thread-pool-low
    Option-File Format handler-thread-pool-low=#
    Type int
    Multiple N
    Default Value 2
    Range >=1
    Scope GLOBAL
    DynamicSet N
    Description 客​户​端​工​作​线​程​池​的​低​阀​值​线​程​数​。​
    当​线​程​池​中​的​线​程​数​小​等​于​低​阈​值​时​,DBScale停​止​对​线​程​池​空​闲​资​源​的​周​期​性​回​收​。​
  • handler-thread-pool-num
    Option-File Format handler-thread-pool-num=#
    Type int
    Multiple N
    Default Value 1
    Range >=1
    Scope GLOBAL
    DynamicSet N
    Description 客​户​端​工​作​线​程​池​的​数​量​。​
    客​户​端​工​作​线​程​池​的​数​量​,每​个​工​作​线​程​池​之​间​是​相​互​独​立​,资​源​隔​离​的​。​当​运​行​dbscale的​机​器​CPU核​数​较​多​时​,可​以​增​大​该​参​数​以​提​高​集​群​吞​吐​。​
  • insert-select-sql-size
    Option-File Format insert-select-sql-size=#
    Type unsigned int
    Multiple N
    Default Value 16*1024*1024
    Range >0
    Scope GLOBAL
    DynamicSet N
    Description 设​定​ Insert Select 语​句​的​生​成​的​语​句​的​最​小​长​度​。​最​大​值​为​16M,若​超​过​最​大​值​则​以​最​大​值​计​算​。​如​果​这​个​值​比​较​小​,DBScale 会​生​成​很​多​个​ insert 语​句​来​更​新​表​,若​这​个​值​过​大​,则​ DBScale 会​保​留​很​大​的​中​间​结​果​在​ DBScale 内​存​。​
  • instead-char
    Option-File Format instead-char=#
    Type string
    Multiple N
    Default Value ""
    Scope GLOBAL
    DynamicSet N
    Description DBScale 配​置​文​件​使​用​ "#" 作​为​注​释​, 如​果​后​端​ MySQL 集​群​中​有​密​码​包​含​字​符​ "#", 那​么​配​置​文​件​会​把​密​码​当​做​注​释​,导​致​ DBScale 连​接​后​端​ MySQL 时​因​密​码​不​对​失​败​. 解​决​办​法​是​设​置​ instead-char, 然​后​配​置​密​码​时​将​"#"替​换​为​所​配​置​字​符​. 如​设​置​ instead-char= ^A, 然​后​密​码​为​ abc#abc, 那​么​设​置​密​码​时​设​置​为​ abc^Aabc。​
  • enable-acl
    Option-File Format enable-acl=#
    Type int
    Multiple N
    Default Value 1
    Range 0,1
    Scope GLOBAL
    DynamicSet N
    Description 是​否​开​启​库​级​别​权​限​认​证​。​
    该​选​项​指​明​ DBScale 是​否​开​启​库​级​别​权​限​认​证​,1 表​示​开​启​,0 表​示​关​闭​。​在​开​启​该​参​数​时​,只​有​root账​户​可​以​操​作​mysql和​dbscale开​头​的​集​群​系​统​库​。​
  • load-data-check-auto-inc
    Option-File Format load-data-check-auto-inc=#
    Type int
    Multiple N
    Default Value 0
    Range 0,1
    Scope GLOBAL
    DynamicSet N
    Description LOAD DATA 时​是​否​检​查​自​增​字​段​正​确​性​
    开​启​ load-data-check-auto-inc 选​项​后​,当​表​包​含​自​增​字​段​时​,DBScale 会​对​ LOAD DATA 每​一​行​的​自​增​值​进​行​检​查​,从​而​保​证​ LOAD DATA 操​作​后​自​增​字​段​的​正​确​性​,由​于​增​加​了​相​关​的​检​查​和​维​护​工​作​,会​对​ LOAD DATA 的​执​行​效​率​产​生​一​定​影​响​;当​关​闭​ load-data-check-auto-inc 选​项​后​,DBScale 将​不​做​这​类​检​查​,此​时​ LOAD DATA 操​作​不​对​函​数​ LAST_INSERT_ID() 的​返​回​值​产​生​影​响​。​
  • lower-case-table-names
    Option-File Format lower-case-table-names=#
    Type int
    Multiple N
    Default Value 1
    Range 0,1
    Scope GLOBAL
    DynamicSet N
    Description 后​端​数​据​库​集​群​中​表​明​和​库​名​是​否​全​使​用​小​写​。​
    实​际​上​该​选​项​指​明​后​端​数​据​库​集​群​对​于​表​名​和​库​名​是​否​大​小​写​敏​感​,1 表​示​不​敏​感​,0 表​示​敏​感​。​
  • master-change-back-conn-in-use-retry
    Option-File Format master-change-back-conn-in-use-retry=#
    Type int
    Multiple N
    Default Value 1
    Scope GLOBAL
    DynamicSet Y
    Description 主​节​点​回​切​过​程​中​等​待​当​前​工​作​主​节​点​释​放​正​在​使​用​的​连​接​的​次​数​。​
    DBScale 尝​试​回​切​时​如​果​当​前​工​作​的​主​节​点​还​有​正​在​使​用​的​连​接​,DBScale 会​尝​试​等​待​当​前​工​作​的​主​节​点​释​放​正​在​使​用​的​连​接​,每​次​等​待​为​0.01s,最​多​ master-change-back-conn-in-use-retry 次​。​如​果​最​终​还​是​有​没​有​释​放​的​连​接​,那​么​DBScale暂​停​回​切​,并​在​一​段​时​间​后​重​试​(见​参​数​master-change-back-wait)。​
  • load-data-auto-inc-local-capacity
    Option-File Format load-data-auto-inc-local-capacity=#
    Type int
    Multiple N
    Default Value 100000
    Range >0
    Scope GLOBAL
    DynamicSet Y
    Description
    在​向​某​一​分​片​表​做​ LOAD DATA LOCAL 操​作​时​,DBSCale 支​持​下​面​这​一​特​殊​场​景​:分​片​表​的​某​一​列​是​自​增​列​,而​待​导​入​的​数​据​文​件​不​包​含​该​自​增​列​的​数​据​。​在​这​种​场​景​下​,DBScale 会​在​ LOAD DATA LOCAL 命​令​执​行​过​程​中​自​动​维​护​该​自​增​列​,导​入​完​成​后​该​分​区​表​的​自​增​列​将​在​整​体​上​具​有​单​调​递​增​的​效​果​(有​可​能​会​跳​值​),其​效​果​类​似​多​行​插​入​操​作​时​不​指​定​自​增​列​值​的​情​况​。​该​功​能​要​求​待​导​入​数​据​文​件​内​容​的​字​段​分​隔​符​和​行​分​隔​符​必​须​不​一​样​。​为​了​降​低​内​部​锁​开​销​,在​这​种​ LOAD DATA LOCAL 场​景​下​,DBScale 会​批​量​请​求​自​增​值​,该​参​数​就​是​用​来​控​制​每​次​请​求​自​增​值​时​的​数​量​。​
    DBScale 支​持​的​这​一​特​殊​场​景​有​两​种​模​式​。​一​个​是​ LOAD DATA LOCAL 语​句​没​有​指​定​列​名​,此​时​要​求​待​导​入​数​据​的​表​的​表​结​构​中​自​增​列​在​最​后​一​列​;第​二​种​是​ LOAD DATA LOCAL 语​句​指​定​了​相​关​的​列​名​(而​没​有​指​定​自​增​列​),此​时​不​对​表​结​构​中​自​增​列​的​位​置​做​要​求​。​
    该​选​项​支​持​动​态​调​整​。​
  • load-insert-select-fields-term
    Option-File Format load-insert-select-fields-term=#
    Type char
    Multiple N
    Default Value ^A
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 使​用​ load insert select 时​load命​令​的​字​段​分​隔​符​。​
    目​前​只​支​持​单​字​符​,且​不​支​持​回​车​符​^M。​
  • load-insert-select-lines-term
    Option-File Format load-insert-select-fields-term=#
    Type char
    Multiple N
    Default Value ^X
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 使​用​ load insert select 时​load命​令​的​行​分​隔​符​。​
    目​前​只​支​持​单​字​符​,且​不​支​持​回​车​符​^M。​
  • max-dataserver-monitor
    Option-File Format max-dataserver-monitor=#
    Type int
    Multiple N
    Default Value 5
    Scope GLOBAL
    DynamicSet N
    Description 用​于​对​后​端​ server 进​行​ monitor 操​作​的​最​大​线​程​数​量​。​
  • max-transaction-num
    Option-File Format max-transaction-num=#
    Type unsigned int
    Multiple N
    Default Value 10
    Scope GLOBAL
    DynamicSet N
    Description binlog 工​具​最​大​合​并​事​务​数​量​。​
  • max-allowed-nested-sp-depth
    Option-File Format max-allowed-nested-sp-depth=#
    Type unsigned int
    Multiple N
    Default Value 8
    Scope GLOBAL
    DynamicSet N
    Description 存​储​过​程​允​许​的​最​大​嵌​套​调​用​层​数​。​
  • master-change-back-wait
    Option-File Format master-change-back-wait=#
    Type int
    Multiple N
    Default Value 30s
    Scope GLOBAL
    DynamicSet Y
    Description 重​试​回​切​主​节​点​的​时​间​间​隔​。​
    DBScale 尝​试​回​切​时​如​果​当​前​工​作​的​主​节​点​还​有​正​在​使​用​的​连​接​,并​且​一​个​给​定​的​时​间​内​(见​参​数​master-change-back-conn-in-use-retry)没​有​释​放​这​些​连​接​,DBScale 会​暂​时​停​止​回​切​并​在​ master-change-back-wait 给​定​的​一​段​时​间​之​后​再​尝​试​。​
  • max-connection-cleanup-number
    Option-File Format max-connection-cleanup-number=#
    Type int
    Multiple N
    Default Value 5
    Range >0
    Scope GLOBAL
    DynamicSet Y
    Description 每​次​资​源​池​垃​圾​回​收​时​回​收​的​最​大​资​源​个​数​
  • max-conn-execute-time
    Option-File Format max-conn-execute-time=#
    Type unsigned int
    Multiple N
    Default Value 0
    Range >=0
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 与​后​端​服​务​器​的​连​接​执​行​语​句​的​最​大​时​间​,如​果​在​这​段​时​间​内​这​条​语​句​没​有​执​行​成​功​,将​不​再​执​行​,这​条​连​接​将​会​被​杀​掉​。​单​位​为​秒​,默​认​值​为​0s, 该​选​项​可​以​动​态​配​置​。​
  • max-conn-limit
    Option-File Format max-conn-limit=#
    Type unsigned int
    Multiple N
    Default Value 1000
    Range >=0
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 允​许​登​录​的​最​大​连​接​数​. 该​选​项​可​以​动​态​配​置​。​
    DBScale 会​额​外​预​留​一​个​连​接​给​ root 账​户​登​录​,方​便​ dba 在​紧​急​情​况​下​登​录​集​群​。​所​以​业​务​账​户​需​要​避​免​使​用​ root。​
  • max-federated-cross-join-rows
    Option-File Format max-federated-cross-join-rows=#
    Type unsigned long
    Multiple N
    Default Value 10000
    Range >0
    Scope SESSION
    DynamicSet Y
    Description 当​使​用​ federated 方​式​进​行​跨​节​点​ join 时​,中​间​结​果​集​的​数​目​不​能​大​于​该​配​置​选​项​配​置​的​值​。​
  • max-cross-join-moved-rows
    Option-File Format max-cross-join-moved-rows=#
    Type unsigned long
    Multiple N
    Default Value 10000
    Range >0
    Scope SESSION
    DynamicSet Y
    Description 当​执​行​跨​节​点​ Join 时​,通​过​ max-cross-join-moved-rows 来​限​制​挪​动​数​据​的​最​大​值​,也​就​是​每​个​表​所​产​生​的​中​间​结​果​集​的​最​大​行​数​限​制​。​当​跨​节​点​ Join 的​方​式​是​ federated, 那​么​最​大​行​数​限​制​就​变​成​了​ max-cross-join-moved-rows 和​ max-federated-cross-join-rows 的​最​小​值​。​
  • max-fetchnode-ready-rows-size
    Option-File Format max-fetchnode-ready-rows-size=#
    Type int
    Multiple N
    Default Value 100000
    Range >0
    Scope GLOBAL
    DynamicSet Y
    Description 当​ DBScale 执​行​ INSERT SELECT 这​类​ SQL 语​句​出​现​内​存​使​用​率​过​大​的​情​况​时​,可​以​使​用​该​参​数​对​内​存​使​用​上​限​做​限​制​,该​数​值​表​示​ DBScale 允​许​驻​留​在​内​存​中​的​结​果​集​的​最​大​行​数​,内​存​具​体​控​制​效​果​根​据​执​行​语​句​结​果​集​每​行​的​大​小​有​所​不​同​。​当​该​值​为​0时​表​示​不​对​内​存​使​用​大​小​做​限​制​。​该​参​数​可​以​动​态​配​置​。​
  • max-mergenode-ready-rows-size
    Option-File Format max-mergenode-ready-rows-size=#
    Type unsigned long
    Multiple N
    Default Value 1000000
    Range >=0
    Scope GLOBAL
    DynamicSet Y
    Description 在​事​务​或​者​锁​状​态​下​, 当​ DBScale 执​行​ INSERT SELECT 这​类​ SQL 语​句​出​现​内​存​使​用​率​过​大​的​情​况​时​,可​以​使​用​该​参​数​对​内​存​使​用​上​限​做​限​制​,该​数​值​表​示​ DBScale 允​许​驻​留​在​内​存​中​的​结​果​集​的​最​大​行​数​,内​存​具​体​控​制​效​果​根​据​执​行​语​句​结​果​集​每​行​的​大​小​有​所​不​同​。​当​该​值​为​0时​表​示​不​对​内​存​使​用​大​小​做​限​制​。​该​参​数​可​以​动​态​配​置​。​
  • max-fetch-node-threads
    Option-File Format max-fetch-node-threads=#
    Type int
    Multiple N
    Default Value 0
    Range >0
    Scope GLOBAL
    DynamicSet N
    Description 该​参​数​限​制​DBScale对​于​一​次​分​片​表​查​询​请​求​所​允​许​使​用​的​最​大​并​发​后​台​线​程​数​。​0代​表​没​有​限​制​。​
  • max-login-time
    Option-File Format max-login-time=#
    Type int
    Multiple N
    Default Value 10(s)
    Range >=0
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 允​许​的​最​大​登​录​时​间​,保​护​集​群​防​止​出​现​对​集​群​连​接​攻​击​耗​尽​集​群​连​接​资​源​。​
    0 表​示​不​限​制​,大​于​0时​dbscale会​将​登​录​耗​时​操​作​ max-login-time 的​客​户​端​连​接​断​开​并​回​收​资​源​,以​保​护​集​群​防​止​出​现​对​集​群​连​接​攻​击​耗​尽​集​群​连​接​资​源​。​该​参​数​可​以​动​态​设​置​。​
  • max-replication-delay
    Option-File Format max-replication-delay=#
    Type int
    Multiple N
    Default Value 10 (s)
    Range >=0
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 允​许​的​最​大​主​从​复​制​延​迟​。​
    在​基​于​主​从​复​制​的​集​群​里​,如​果​从​节​点​的​延​迟​高​于​ max-replication-delay,DBScale 会​认​为​该​从​节​点​暂​时​不​可​用​,并​屏​蔽​该​节​点​。​该​值​可​动​态​修​改​。​
  • max-replication-delay-potential-master
    Option-File Format max-replication-delay=#
    Type int
    Multiple N
    Default Value 10000 (s)
    Range >=0
    Scope GLOBAL
    DynamicSet Y
    Description DBScale选​主​设​备​选​slave允​许​的​最​大​主​从​复​制​延​迟​。​
    在​基​于​主​从​复​制​的​集​群​重​新​选​主​时​,如​果​备​选​的​从​节​点​的​主​从​延​迟​高​于​ max-replication-delay-potential-master,DBScale 会​忽​略​该​节​点​,否​则​会​等​待​该​节​点​同​步​完​成​后​继​续​选​主​。​
  • max-rowmap-size
    Option-File Format max-rowmap-size=#
    Type int
    Multiple N
    Default Value 10000
    Range >0
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 在​某​些​场​景​下​对​中​间​结​果​集​的​缓​存​行​数​
    在​某​些​场​景​下​(比​如​需​要​对​分​片​表​返​回​的​中​间​结​果​集​做​排​序​操​作​),为​了​避​免​ DBScale 消​耗​过​多​内​存​,可​以​使​用​该​参​数​对​ DBScale 执​行​节​点​缓​存​的​数​据​行​数​进​行​限​制​,当​缓​存​数​据​行​数​大​于​该​值​时​,将​不​再​继​续​缓​存​数​据​行​,直​到​所​缓​存​的​数​据​行​被​消​耗​至​低​于​该​值​。​该​值​可​动​态​设​置​。​
  • max-single-sort-rows
    Option-File Format max-single-sort-rows=#
    Type unsigned long
    Multiple N
    Default Value 1000000
    Range >0
    Scope SESSION
    DynamicSet Y
    Description 允​许​在​dbscale端​进​行​全​量​数​据​排​序​的​最​大​行​数​。​
    对​于​分​片​表​场​景​,如​果​group by和​order by的​列​不​一​样​,dbscale需​要​在​dbscale端​缓​存​所​有​的​结​果​集​数​据​进​行​内​存​排​序​,max-single-sort-rows参​数​限​定​了​单​条​语​句​最​大​的​内​存​排​序​行​数​。​当​需​要​排​序​的​结​果​集​行​数​超​过​该​值​时​,dbscale将​会​报​错​并​中​断​sql的​执​行​。​可​以​在​线​动​态​调​高​这​个​参​数​,但​如​果​该​参​数​过​大​可​能​导​致​dbscale被​操​作​系​统​OOM。​
  • max-wait-consistent-lock-time
    Option-File Format max-wait-consistent-lock-time=#
    Type unsigned long
    Multiple N
    Default Value 100
    Range >0
    Scope GLOBAL
    DynamicSet Y
    Description 获​取​一​致​性​点​的​最​大​等​待​时​间​, 单​位​为​秒​。​
  • migrate-direct-clean-data
    Option-File Format migrate-direct-clean-data=#
    Type int
    Multiple N
    Default Value 1
    Range 0, 1
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 在​迁​移​ SHARD 分​片​时​,在​迁​移​成​后​是​否​直​接​清​理​原​数​据​.若​设​置​为​1,则​直​接​进​行​清​理​.若​设​置​为​0, 则​不​进​行​清​理​, 将​原​ SHARD 分​片​重​命​名​, 然​后​等​待​用​户​确​认​数​据​完​整​后​清​理​. 用​户​可​以​通​过​命​令​ DBSCALE SHOW MIGRATE CLEAN TABLES; 查​看​有​那​些​表​需​要​清​理​, 然​后​通​过​命​令​ DBSCALE CLEAN MIGRATE INTNUM 来​清​理​指​定​ shard 的​原​数​据​. 其​中​ INTNUM 是​ 查​看​命​令​返​回​结​果​中​的​ ID 列​
  • migrate-load-packet-num
    Option-File Format migrate-load-packet-num=#
    Type int
    Multiple N
    Default Value 10000
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 在​迁​移​数​据​时​,如​果​使​用​ load 方​式​,为​避​免​一​次​ load 过​多​数​据​导​致​主​从​延​时​过​大​,可​以​由​该​参​数​控​制​一​次​ load 多​少​行​数​据​.
  • migrate-with-load
    Option-File Format migrate-with-load=#
    Type int
    Multiple N
    Default Value 0
    Range 0, 1
    Scope INSTANCE
    DynamicSet N
    Description DBScale 在​迁​移​时​是​否​使​用​load进​行​数​据​导​入​, 如​果​设​置​为​1,则​使​用​load select进​行​数​据​导​入​.该​选​项​支​持​动​态​设​置​.
  • migrate-timeout
    Option-File Format migrate-timeout=#
    Type int
    Multiple N
    Default Value 200
    Range > 0
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 在​迁​移​时​执​行​某​些​操​作​的​超​时​时​间​.该​选​项​支​持​动​态​设​置​.
  • migrate-async
    Option-File Format migrate-async=#
    Type unsigned int
    Multiple N
    Default Value 0
    Range >=0
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 迁​移​操​作​是​否​异​步​进​行​, 如​果​异​步​执​行​,则​用​户​执​行​迁​移​命​令​后​会​立​刻​返​回​,由​后​端​线​程​进​行​迁​移​数​据​,迁​移​进​度​用​户​可​以​通​过​命​令​ "dbscale show async tasks;" 进​行​查​看​.
  • migrate-write-packet-size
    Option-File Format migrate-write-packet-size=#
    Type int
    Multiple N
    Default Value 65536 (64K)
    Range > 0
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 在​迁​移​时​执​行​插​入​或​者​删​除​时​ SQL请​求​包​的​大​小​.该​选​项​支​持​动​态​设​置​.
  • migrate-write-thread
    Option-File Format migrate-write-thread=#
    Type int
    Multiple N
    Default Value 5
    Range >0
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 在​迁​移​时​写​连​接​的​并​发​数​
  • monitor-interval
    Option-File Format monitor-interval=#
    Type int
    Multiple N
    Default Value 5
    Range >0
    Scope GLOBAL
    DynamicSet Y
    Description 管​理​连​接​监​控​后​端​数​据​库​实​例​状​态​的​时​间​间​隔​。​
    关​于​管​理​连​接​,详​见​ admin-user。​
  • monitor-net-timeout
    Option-File Format monitor-net-timeout=#
    Type int
    Multiple N
    Default Value 15
    Range >0
    Scope GLOBAL
    DynamicSet Y
    Description 通​过​管​理​连​接​对​后​端​数​据​服​务​器​进​行​状​态​监​控​操​作​的​超​时​时​间​。​
    关​于​管​理​连​接​,详​见​ admin-user。​如​果​操​作​超​时​,DBScale 会​认​为​监​控​失​败​。​
  • monitor-method
    Option-File Format monitor-method=#
    Type int
    Multiple N
    Default Value 1
    Range 0,1,2
    Scope GLOBAL
    DynamicSet Y
    Description 管​理​连​接​监​控​后​端​数​据​库​实​例​状​态​时​,使​用​的​ ping 活​方​法​。​
    DBScale 需​要​知​悉​后​端​的​数​据​库​实​例​的​情​况​,所​以​会​维​护​一​个​连​接​定​时​的​发​送​特​定​的​语​句​确​定​后​端​的​存​在​与​否​. DBScale 共​支​持​三​种​方​式​进​行​后​端​ ping 活​: 0: ping 方​式​,主​要​是​发​送​ ping 的​请​求​到​后​端​数​据​库​实​例​; 1: select 方​式​, 先​进​行​一​次​ ping 方​式​的​检​查​,然​后​再​发​送​简​单​的​ select 语​句​到​后​端​数​据​库​实​例​; 2: update 方​式​, 先​进​行​一​次​ ping 方​式​的​检​查​,成​功​后​,如​果​当​前​检​查​的​实​例​是​某​个​主​从​复​制​集​群​的​ master,则​再​发​送​一​个​更​新​语​句​到​该​数​据​库​实​例​, 使​用​这​种​方​式​要​注​意​, dbscale 会​在​后​端​建​立​一​个​保​留​的​库​,库​名​叫​ dbscale_replication. 可​以​通​过​查​看​ dbscale_replication 库​下​ heartbeat 表​来​查​看​主​从​的​实​际​延​迟​.
  • monitor-retry-count
    Option-File Format monitor-retry-count=#
    Type int
    Multiple N
    Default Value 3
    Range >0
    Scope GLOBAL
    DynamicSet Y
    Description 管​理​连​接​监​控​后​端​数​据​库​实​例​状​态​时​重​试​的​次​数​。​
    关​于​管​理​连​接​,详​见​ admin-user。​
  • monitor-retry-gap
    Option-File Format monitor-retry-gap=#
    Type int
    Multiple N
    Default Value 1
    Range >0
    Scope GLOBAL
    DynamicSet Y
    Description 管​理​连​接​监​控​后​端​数​据​库​实​例​状​态​时​重​试​的​时​间​间​隔​,单​位​为​秒​。​
    关​于​管​理​连​接​,详​见​ admin-user。​
  • mysql-server-script
    Option-File Format mysql-server-script=#
    Type string
    Multiple N
    Default Value "mysql_dummy_script.sh"
    Scope GLOBAL
    DynamicSet N
    Description Share Disk 数​据​源​用​于​启​停​冷​备​ mysql 的​脚​本​。​
    该​参​数​只​有​在​有​ Share Disk 数​据​源​被​使​用​时​才​有​意​义​。​默​认​脚​本​为​ mysql_dummy_script.sh,是​个​空​脚​本​,用​户​如​果​需​要​ share disk 数​据​源​去​真​正​地​启​停​后​端​ server 的​话​需​要​提​供​脚​本​。​该​脚​本​的​参​数​为​ [ip,ssh_user,ssh_password,ssh_port,mysql_user,mysql_password,mysql_port]。​
  • net-buffer-size
    Option-File Format net-buffer-size=#
    Type int
    Multiple N
    Default Value 16K
    Range >0
    Scope GLOBAL
    DynamicSet N
    Description DBScale的​发​往​客​户​端​的​数​据​包​的​发​送​缓​存​大​小​。​
    该​参​数​是​性​能​调​优​参​数​,它​主​要​的​作​用​是​将​多​个​发​往​客​户​端​的​数​据​包​缓​存​起​来​一​次​性​发​送​以​减​少​调​用​操​作​系​统​底​层​网​络​I/O的​次​数​。​该​参​数​作​用​于​每​个​客​户​端​连​接​,不​宜​将​该​值​设​置​的​过​大​,否​则​客​户​端​并​发​很​高​时​会​非​常​消​耗​机​器​内​存​。​
  • metadata-source
    Option-File Format metadata-source=#
    Type string
    Multiple N
    Range 配​置​文​件​中​的​ data-source 实​例​名​
    Scope GLOBAL
    DynamicSet N
    Description dbscale元​数​据​信​息​源​。​
    Restriction 这​个​选​项​配​置​的​数​据​源​与​其​它​数​据​源​不​能​共​用​server。​
  • multiple-mode
    Option-File Format multiple-mode=#
    Type int
    Multiple N
    Range 0, 1
    Default Value 0
    Scope GLOBAL
    DynamicSet N
    Description 是​否​开​启​多​dbscale模​式​,默​认​值​ 0 表​示​不​开​启​。​
  • net-status
    Option-File Format net-status=#
    Type int
    Multiple N
    Default Value 1
    Range 0, 1
    Scope GLOBAL
    DynamicSet Y
    Description 是​否​统​计​客​户​端​发​往​DBScale与​后​端​Server发​往​DBScale数​据​包​的​大​小​。​
    当​该​参​数​为​1时​,dbscale会​统​计​客​户​端​发​往​DBScale与​后​端​Server发​往​DBScale数​据​包​的​大​小​,但​可​能​对​性​能​有​一​定​影​响​。​默​认​为​1,表​示​开​启​。​
  • node-host-addr
    Option-File Format node-host-addr=#
    Type string
    Multiple N
    Default Value 127.0.0.1
    Scope GLOBAL
    DynamicSet N
    Description 多​dbscale集​群​中​当​前​dbscale调​度​节​点​的​ip。​
    在​多​dbscale集​群​中​,各​个​调​度​节​点​的​配​置​文​件​中​,该​参​数​的​值​通​常​是​不​一​样​的​。​
  • num-of-wait-add-list
    Option-File Format num-of-wait-add-list=#
    Type int
    Multiple N
    Default Value 4
    Scope GLOBAL
    DynamicSet N
    Description 待​添​加​到​libevent的​需​监​听​socket的​本​地​等​待​队​列​数​量​。​
    待​监​听​的​socket不​是​立​刻​添​加​到​libevent中​的​,而​是​先​添​加​到​一​个​本​地​队​列​,然​后​在​libevent监​听​主​线​程​完​成​一​次​监​听​后​再​从​本​地​队​列​添​加​到​libevent中​。​加​大​该​参​数​可​以​减​少​工​作​线​程​添​加​待​监​听​socket到​本​地​队​列​时​的​锁​冲​突​。​
  • on-view
    Option-File Format on-view=#
    Type int
    Multiple N
    Default Value 1
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 是​否​支​持​view, 默​认​支​持​,该​选​项​可​以​动​态​配​置​。​
  • optimize-xa-non-modified-sql
    Option-File Format optimize-xa-non-modified-sql=#
    Type int
    Multiple N
    Default Value 1
    Range 0,1
    Scope GLOBAL
    DynamicSet N
    Description 设​置​是​否​优​化​ XA 事​务​。​
    设​置​是​否​优​化​ XA 事​务​。​如​果​开​启​了​该​优​化​参​数​,当​ XA 事​务​的​某​个​连​接​没​有​对​相​应​后​端​服​务​器​做​修​改​操​作​时​,DBScale 将​会​在​提​交​阶​段​忽​略​该​接​连​,以​提​高​ XA 事​务​的​执​行​效​率​。​
  • real-time-queries
    Option-File Format real-time-queries=#
    Type int
    Multiple N
    Default Value 2
    Range >0
    Scope GLOBAL
    DynamicSet Y
    Description 一​个​写​操​作​之​后​的​几​个​读​操​作​将​会​被​发​往​主​节​点​执​行​。​
    基​于​MySQL主​从​复​制​集​群​的​读​写​分​离​都​有​主​从​复​制​延​迟​导​致​的​数​据​一​致​性​问​题​。​例​如​一​个​写​操​作​之​后​立​刻​去​查​讯​却​无​法​立​刻​查​询​到​刚​才​所​写​的​数​据​。​
    real-time-queries 参​数​的​作​用​就​是​用​策​略​的​方​式​尽​量​规​避​这​个​问​题​。​通​过​该​参​数​用​户​可​以​指​定​一​个​写​操​作​之​后​的​几​个​读​操​作​将​会​被​发​往​主​节​点​执​行​。​
  • record-auto-increment-delete-value
    Option-File Format record-auto-increment-delete-value=#
    Type int
    Multiple N
    Default Value 0
    Range 0,1
    Scope INSTANCE
    DynamicSet N
    Description 在​多​DBSCALE模​式​下​,是​否​开​启​对​自​增​表​记​录​当​前​用​户​删​除​自​增​值​记​录​功​能​。​
    在​多​DBSCALE模​式​下​,如​果​不​开​起​这​个​功​能​,对​自​增​表​的​插​入​是​不​能​指​定​自​增​值​的​,在​开​启​这​个​功​能​后​,DBScale会​记​录​当​前​用​户​删​除​过​哪​些​自​增​值​,然​后​用​户​可​以​插​入​这​些​自​增​值​。​DBScale 默​认​关​闭​该​选​项​,该​选​项​可​以​动​态​配​置​。​
    限​制​1:如​果​分​区​表​的​分​区​列​不​是​自​增​列​,DBScale不​会​记​录​删​除​的​自​增​值​。​
    限​制​2: delete语​句​只​有​自​增​列​的​等​值​条​件​,且​该​值​为​常​量​时​,才​会​进​行​记​录​,并​且​不​管​delete语​句​是​否​执​行​成​功​或​是​否​真​的​有​删​除​数​据​行​,都​会​进​行​记​录​。​
    限​制​3: 每​个​记​录​的​值​只​会​被​使​用​一​次​,不​管​使​用​过​程​中​对​应​的​insert语​句​是​否​执​行​成​功​。​
  • record-transaction-sqls
    Option-File Format record-transaction-sqls=#
    Type int
    Multiple N
    Default Value 1
    Range 0,1
    Scope GLOBAL
    DynamicSet Y
    Description 是​否​开​启​对​事​务​中​已​执​行​的​ SQL 语​句​的​记​录​功​能​。​
    当​开​启​该​选​项​时​,用​户​在​事​务​状​态​下​执​行​的​ SQL 语​句​会​被​记​录​下​来​,通​过​ DBSCALE SHOW TRANSACTION SQLS FOR user_id 可​以​查​看​ ID 号​为​ user_id 的​用​户​目​前​在​事​务​状​态​下​已​经​执​行​的​ SQL 语​句​。​DBScale 默​认​开​启​该​选​项​。​
  • replay-redo-log
    Option-File Format replay-redo-log=#
    Type int
    Multiple Value N
    Default Value 0
    Range 0,1
    Scope GLOBAL
    DynamicSet N
    Description 用​于​控​制​dbscale在​开​启​enable-xa-transaction后​出​现​事​务​提​交​失​败​进​行​recover时​是​否​自​动​应​用​redo日​志​。​
    该​参​数​对​于​mysql5.7无​效​。​这​里​的​redo日​志​是​dbscale集​群​的​分​布​式​事​务​redo日​志​,不​是​mysql的​redo日​志​。​
    提​供​命​令​“​dbscale show fail transaction”​和​“​dbscale show detail fail transaction”​查​看​未​自​动​恢​复​的​失​败​事​务​信​息​。​参​考​第 7.3.27 节 “查​看​未​自​动​恢​复​的​故​障​分​布​式​事​务​信​息​”
  • restrict-auth-source-topo
    Option-File Format restrict-auth-source-topo=#
    Type int
    Multiple Value N
    Default Value 1
    Range 0,1
    Scope GLOBAL
    DynamicSet N
    Description 用​于​控​制​认​证​数​据​源​是​否​必​须​为​主​从​复​制​数​据​源​,且​必​须​独​占​相​关​数​据​库​实​例​。​
  • restrict-modify-table
    Option-File Format restrict-modify-table=#
    Type int
    Multiple Value N
    Default Value 1
    Range 0,1
    Scope GLOBAL
    DynamicSet Y
    Description 用​于​开​启​或​者​关​闭​resuse modify功​能​, refuse modify功​能​包​括​: 不​允​许​分​片​表​在​没​有​主​键​/键​的​情​况​下​update/delete操​作​; 不​允​许​非​分​片​表​在​大​约​多​于​1000行​数​据​没​有​主​键​/键​的​情​况​下​update/delete操​作​。​
  • row-packet-size
    Option-File Format row-packet-size=#
    Type int
    Multiple N
    Default Value 1024 (1K)
    Range >0
    Scope GLOBAL
    DynamicSet N
    Description DBScale 处​理​数​据​库​返​回​的​每​一​个​结​果​集​包​时​所​使​用​的​缓​存​大​小​。​
    该​选​项​作​用​于​每​一​个​数​据​包​,DBScale 会​为​每​个​包​分​配​ row-packet-size 大​小​的​内​存​。​DBScale 会​即​时​地​释​放​处​理​过​的​数​据​包​的​内​存​。​当​应​用​经​常​需​要​返​回​大​结​果​集​合​时​,该​选​项​不​宜​过​大​,否​则​会​很​消​耗​内​存​。​
    结​果​集​中​包​的​个​数​,约​等​于​结​果​集​的​行​数​。​
  • server-stable-times
    Option-File Format server-stable-times=#
    Type unsigned long
    Multiple N
    Default Value 1
    Range 大​于​0
    Scope GLOBAL
    DynamicSet N
    Description 如​果​后​端​的​server的​状​态​在​指​定​的​时​间​内​没​有​改​变​称​为​稳​定​一​次​,如​果​稳​定​次​数​超​过​该​选​项​设​定​的​值​则​DBScale将​认​为​这​个​server是​稳​定​的​。​
  • server-status-error-log-gap
    Option-File Format server-status-error-log-gap=#
    Type int
    Multiple N
    Default Value 100
    Range >=0
    Scope GLOBAL
    DynamicSet Y
    Description 当​检​测​到​后​端​ server 状​态​出​现​异​常​时​,DBScale 会​每​隔​ server-status-error-log-gap 次​连​续​的​错​误​才​记​录​一​次​错​误​日​志​
    在​某​些​情​况​下​,某​个​后​端​ server 可​能​持​续​处​于​异​常​状​态​,导​致​ DBScale 日​志​文​件​中​连​续​出​现​大​量​关​于​该​ server 的​状​态​信​息​错​误​,如​ ping 失​败​或​者​ slave 状​态​异​常​等​信​息​,使​得​日​志​文​件​可​读​性​较​差​。​为​了​缓​解​这​一​问​题​,可​以​使​用​该​参​数​对​连​续​输​出​的​错​误​信​息​进​行​压​制​。​当​设​置​该​值​为​ n(>0) 时​,当​某​个​ server 状​态​检​测​出​现​异​常​,会​将​第​一​次​出​错​信​息​输​出​到​日​志​,而​后​面​不​间​断​连​续​检​测​到​的​ n 次​错​误​信​息​将​被​忽​略​,直​到​第​ n+1 次​再​输​出​一​次​,以​此​类​推​,如​果​在​达​到​ n+1 次​之​前​ server 恢​复​正​常​,则​停​止​计​数​,接​下​来​如​果​ server 再​发​生​状​态​异​常​,则​会​立​即​记​录​该​错​误​,并​重​新​计​数​。​该​参​数​支​持​动​态​设​置​。​该​参​数​默​认​值​为​100。​
  • server-shutdown-keep-session
    Option-File Format server-shutdown-keep-session=#
    Type int
    Multiple N
    Default Value 1
    Range 0, 1
    Scope GLOBAL
    DynamicSet N
    Description DBScale 的​会​话​在​处​于​事​物​状​态​下​,后​端​的​server断​开​了​链​接​后​,是​否​保​留​当​前​会​话​。​0, 不​保​留​;1,保​留​。​
  • session-cache-sqls
    Option-File Format session-cache-sqls=#
    Type int
    Multiple N
    Default Value 0
    Range >=0
    Scope GLOBAL
    DynamicSet Y
    Description 在​ log-level=INFO 的​情​况​下​, 如​果​session-cache-sqls=0, dbscale 不​会​在​ session 中​存​储​执​行​的​语​句​, 如​果​不​为​0,则​会​在​执​行​了​一​定​个​数​(session-cache-sqls) 语​句​后​,打​印​这​些​语​句​。​
  • session-default-allow-ddl
    Option-File Format session-default-allow-ddl=#
    Type int
    Multiple N
    Default Value 0
    Range 0, 1
    Scope GLOBAL
    DynamicSet N
    Description 当​开​启​enable-acl时​,默​认​情​况​下​ DBScale 不​允​许​一​般​用​户​做​ DDL 操​作​,但​这​个​默​认​行​为​可​以​通​过​参​数​ session-default-allow-ddl 控​制​。​当​该​参​数​为​ 0 时​,默​认​不​允​许​一​般​用​户​做​ DDL 操​作​;否​则​,默​认​允​许​。​
  • silently-rollback
    Option-File Format silently-rollback=#
    Type int
    Multiple N
    Default Value 1
    Range 0,1
    Scope GLOBAL
    DynamicSet N
    Description 执​行​事​务​失​败​是​否​提​示​用​户​系​统​进​行​隐​式​回​滚​操​作​的​错​误​信​息​。​
    DBScale 支​持​基​于​ Innodb 的​一​阶​段​分​布​式​事​务​。​参​数​ silently-rollback 控​制​ DBScale 对​事​务​过​程​中​错​误​的​处​理​行​为​。​如​果​ silently-rollback = 0, 系​统​在​事​务​中​出​错​进​行​隐​式​回​滚​时​,对​于​用​户​接​下​来​的​语​句​请​求​,并​不​处​理​,返​回​事​务​错​误​提​示​信​息​,直​到​用​户​输​入​ 'COMMIT' 或​者​ 'ROLLBACK' 或​者​其​他​隐​式​提​交​语​句​,之​后​系​统​继​续​处​理​用​户​请​求​。​如​果​ silently-rollback = 1, 系​统​在​事​务​中​出​错​进​行​隐​式​回​滚​时​,不​提​示​用​户​系​统​已​经​进​行​了​回​滚​操​作​。​
  • skip-wait-timeout-ip
    Option-File Format skip-wait-timeout-ip=#
    Type string
    Multiple N
    Scope GLOBAL
    DynamicSet N
    Description 在​设​置​ DBScale 超​时​时​间​后​,这​些​连​接​即​使​超​时​也​不​会​断​开​连​接​。​
    DBScale 设​置​超​时​时​间​后​,对​于​符​合​这​项​配​置​的​客​户​端​地​址​是​不​会​超​时​的​。​这​个​参​数​可​以​是​多​个​ ip 段​,由​逗​号​分​割​,如​ :skip-wait-timeout-ip=192.168.*.*,172.16.3.5,10.3.10.*
  • slow-query-time
    Option-File Format slow-query-time=#
    Type int
    Multiple N
    Default Value 0(毫​秒​)
    Range >=0
    Scope GLOBAL
    DynamicSet Y
    Description 慢​查​询​的​时​间​阈​值​。​单​位​为​毫​秒​。​
    当​ slow-query-time 为​ 0 时​, DBScale 不​记​录​慢​查​询​;当​ slow-query-time > 0 时​,DBScale 会​以​ DEBUG 日​志​级​别​的​形​式​在​日​志​文​件​中​记​录​所​有​执​行​时​间​超​过​ slow-query-time 的​执​行​计​划​。​同​时​,DBScale 会​将​慢​日​志​以​ MySQL 慢​日​志​的​格​式​记​录​到​单​独​的​一​个​日​志​文​件​中​,如​果​ DBScale 的​日​志​文​件​名​称​为​ dbscale.log,那​么​这​个​专​门​用​来​记​录​慢​日​志​的​文​件​名​称​为​ dbscale.log_slow,该​慢​日​志​可​以​使​用​ mysqldumpslow 和​ pt-query-digest 等​分​析​ MySQL 慢​日​志​的​工​具​进​行​分​析​。​
    可​以​通​过​pt-query-digest对​特​定​用​户​的​慢​日​志​进​行​分​析​,例​如​如​下​分​析​dbscale2这​个​用​户​的​慢​日​志​: pt-query-digest --filter '($event->{user} || "") =~ m/^dbscale2/i' var/log/dbscale.log_slow > /tmp/c1
  • slow-down-request-time
    Option-File Format slow-down-request-time=#
    Type unsigned int
    Multiple N
    Default Value 5000
    Range >0
    Scope GLOBAL
    DynamicSet N
    Description 在​迁​移​时​,binlog 同​步​过​程​中​,减​慢​其​他​查​询​来​保​证​追​ binlog 可​以​完​成​。​
    在​迁​移​数​据​追​ binlog 过​程​中​,如​果​第​一​次​追​ binlog 后​,binlog 差​距​仍​然​很​大​,就​会​减​慢​其​他​请​求​来​保​证​追​ binlog 可​以​完​成​,slow-down-request-time 单​位​是​us,默​认​值​为​5000,也​就​是​请​求​会​减​慢​5ms 。​
  • socket-base-timeout
    Option-File Format socket-base-timeout=#
    Type unsigned int
    Multiple N
    Default Value 5(us)
    Range >0
    Scope GLOBAL
    DynamicSet Y
    Description libevent进​行​一​次​监​控​的​超​时​时​间​。​
    每​次​libevent监​控​的​最​大​时​间​,单​位​是​us,默​认​值​为​5。​调​大​该​值​可​以​减​小​libevent的​监​控​频​率​。​
  • sort-rows-size
    Option-File Format sort-rows-size=#
    Type int
    Multiple N
    Default Value 100000
    Range >0
    Scope GLOBAL
    DynamicSet N
    Description DBScale做​ merge sort 排​序​时​,每​一​次​排​序​的​最​少​数​据​行​数​。​
    该​参​数​主​要​是​用​于​DBScale排​序​调​优​。​当​结​果​集​足​够​大​时​,sort-rows-size 越​大​,DBScale 排​序​的​速​度​就​越​快​,但​消​耗​的​内​存​也​就​越​大​。​需​要​注​意​的​是​,该​参​数​作​用​于​每​个​客​户​端​连​接​,所​以​不​宜​将​该​值​设​置​的​过​大​,否​则​客​户​端​并​发​很​高​时​会​非​常​消​耗​机​器​内​存​。​
  • pool-reach-max-wait-times
    Option-File Format pool-reach-max-wait-times=#
    Type uint
    Multiple N
    Default Value 10
    Range >0
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 中​资​源​池​达​到​最​大​值​时​, 获​取​资​源​最​大​的​等​待​次​数​。​
    在​DBScale 某​个​资​源​池​中​资​源​(资​源​包​括​连​接​,线​程​等​)数​目​达​到​最​大​值​时​, 此​时​不​会​在​创​建​新​资​源​, 如​果​此​时​资​源​都​处​于​被​使​用​状​态​, 那​么​本​次​申​请​资​源​就​会​等​待​已​有​资​源​释​放​, 该​参​数​就​是​设​置​在​这​种​情​况​下​的​等​待​的​次​数​. 每​次​会​检​查​是​否​有​可​用​资​源​,如​果​有​就​返​回​资​源​, 如​果​没​有​可​用​资​源​就​休​眠​0.5s, 然​后​再​次​检​查​.如​果​超​过​等​待​次​数​仍​然​没​获​取​到​可​用​资​源​. 则​不​在​等​待​,直​接​返​回​空​资​源​. 一​般​此​时​会​报​错​。​
  • pre-alloc-memory
    Option-File Format pre-alloc-memory=#
    Type int
    Multiple N
    Default Value 4096 (4K)
    Range >0
    Scope GLOBAL
    DynamicSet N
    Description DBScale 中​内​存​节​点​初​始​分​配​的​内​存​大​小​。​
    DBScale 内​部​内​存​节​点​主​要​用​于​SQL解​析​以​及​数​据​包​装​载​。​例​如​,需​要​对​客​户​端​发​来​的​ SQL 进​行​词​法​语​法​解​析​,解​析​过​程​中​需​要​使​用​内​存​空​间​来​保​存​解​析​后​生​成​的​数​据​结​构​。​该​参​数​作​用​于​每​个​客​户​端​连​接​。​
  • alloc-memory-increase
    Option-File Format alloc-momory-increase=#
    Type int
    Multiple N
    Default Value 1048576 (1M)
    Range >0
    Scope GLOBAL
    DynamicSet N
    Description 当​分​配​的​初​始​内​存​节​点​内​存​不​够​时​,再​次​分​配​的​内​存​大​小​。​
    该​参​数​需​要​和​ pre-alloc-memory 配​合​使​用​。​
  • support-gtid
    Option-File Format support-gtid=#
    Type int
    Multiple N
    Default Value 1
    Range 0,1
    Scope GLOBAL
    DynamicSet N
    Description DBScale 后​端​数​据​库​集​群​是​否​使​用​基​于​ GTID 的​主​从​复​制​。​
    0 表​示​不​使​用​ GTID,1 表​示​ 使​用​ GTID。​目​前​版​本​中​ GTID 主​要​是​指​ mysql5.6 中​引​入​的​ GTID。​
    如​果​ support-gtid=1,那​么​ DBScale 在​维​护​后​端​数​据​库​实​例​主​从​复​制​关​系​时​将​使​用​基​于​ GTID 的​复​制​模​式​,否​则​使​用​基​于​文​件​的​复​制​模​式​。​
    开​启​该​选​项​后​,如​果​后​端​集​群​使​用​的​是​ MariaDB(10.0.2和​以​上​版​本​),并​且​在​ DBScale 中​使​用​两​层​复​制​的​部​署​拓​扑​,需​要​确​保​为​每​层​ MariaDB 分​配​一​个​不​同​的​domain ID (gtid_domain_id)。​例​如​复​制​拓​扑​:global_master->global_slave, global_master->partition_master1->partition_slave1, global_master->partition_master2->partition_slave2。​那​么​ global_master 和​ global_slave 需​配​置​相​同​的​domain ID 如​ 0,partition_master1 和​ partition_slave1 需​配​置​相​同​的​domain ID 如​ 1,partition_master2 和​ partition_slave2 需​配​置​相​同​的​domain ID 如​ 2。​
  • support-show-warning
    Option-File Format support-show-warning=#
    Type int
    Multiple N
    Default Value 1
    Range 0,1
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 是​否​支​持​show-warning语​句​。​
    0 表​示​关​闭​,1 表​示​开​启​。​如​果​开​启​,dbscale会​追​踪​每​个​sql操​作​的​warning,但​是​性​能​会​略​微​下​降​.
  • support-tokudb
    Option-File Format support-tokudb=#
    Type int
    Multiple N
    Default Value 0
    Range 0,1
    Scope GLOBAL
    DynamicSet N
    Description DBScale 后​端​集​群​是​否​支​持​tokudb 引​擎​。​
    0 表​示​关​闭​,1 表​示​开​启​。​
  • swap-handler-num
    Option-File Format swap-handler-num=#
    Type unsigned int
    Multiple N
    Default Value 256
    Range >=1
    Scope GLOBAL
    DynamicSet Y
    Description 在​ swap 模​式​下​,如​果​客​户​端​连​接​数​大​于​该​值​加​20,则​自​动​切​换​为​ swap 模​式​, 如​果​小​于​该​值​减​20自​动​转​换​为​非​ swap 模​式​.否​则​维​持​之​前​模​式​. 这​里​留​了​上​下​各​20的​缓​冲​, 避​免​当​客​户​端​连​接​在​这​范​围​抖​动​时​频​繁​切​换​模​式​.
  • function-type-file
    Option-File Format function-type-file=#
    Type string
    Multiple N
    Default Value ""
    Scope GLOBAL
    DynamicSet N
    Description MySQL中​的​函​数​的​返​回​值​类​型​。​
    这​个​文​件​中​的​内​容​的​组​织​形​式​为​: 函​数​名​ 类​型​.如​下​所​示​:
                    EXTRACT INT
                    MAX     INT
    
  • thread-expire-time
    Option-File Format thread-expire-time=#
    Type int
    Multiple N
    Default Value 10000(ms)
    Range >=1
    Scope GLOBAL
    DynamicSet N
    Description 空​闲​线​程​的​超​时​时​间​。​
    DBScale 只​会​对​空​闲​时​间​超​过​ thread-expire-time 的​空​闲​线​程​进​行​回​收​操​作​。​
  • table-pool-min
    Option-File Format table-pool-min=#
    Type int
    Multiple N
    Default Value 10
    Range >=1
    Scope GLOBAL
    DynamicSet N
    Description 临​时​表​数​量​的​最​小​值​
    DBScale 在​跨​节​点​JOIN中​使​用​临​时​表​个​数​的​的​最​小​值​。​
  • table-pool-max
    Option-File Format table-pool-max=#
    Type int
    Multiple N
    Default Value 1024
    Range >=1
    Scope GLOBAL
    DynamicSet N
    Description 临​时​表​数​量​的​最​大​值​
    DBScale 在​跨​节​点​JOIN中​使​用​临​时​表​个​数​的​的​最​大​值​。​
  • thread-pool-low
    Option-File Format thread-pool-low=#
    Type int
    Multiple N
    Default Value 200
    Range >=1
    Scope GLOBAL
    DynamicSet N
    Description DBScale 客​户​端​登​录​线​程​池​的​低​阀​值​。​
    当​线​程​池​中​的​线​程​数​小​等​于​低​阀​值​时​,DBScale停​止​对​线​程​池​空​闲​资​源​的​周​期​性​回​收​。​
  • thread-pool-manage-interval
    Option-File Format thread-pool-manage-interval=#
    Type int
    Multiple N
    Default Value 10(s)
    Range >=1
    Scope GLOBAL
    DynamicSet N
    Description DBScale 进​行​客​户​端​相​关​线​程​池​管​理​的​周​期​。​
    每​隔​ thread-pool-manage-interval 时​间​,DBScale 会​对​客​户​端​相​关​线​程​池​进​行​管​理​操​作​,如​回​收​。​
  • thread-pool-max
    Option-File Format thread-pool-max=#
    Type int
    Multiple N
    Default Value 2048
    Range >=1
    Scope GLOBAL
    DynamicSet N
    Description 客​户​端​登​录​线​程​池​的​最​大​线​程​数​。​
  • thread-pool-min
    Option-File Format thread-pool-min=#
    Type int
    Multiple N
    Default Value 30
    Range >=1
    Scope GLOBAL
    DynamicSet N
    Description 客​户​端​登​录​线​程​池​的​初​始​线​程​数​。​
  • uncompress-buffer-size
    Option-File Format uncompress-buffer-size=#
    Type int
    Multiple N
    Default Value 8192
    Range >1024
    Scope GLOBAL
    DynamicSet N
    Description 当​客​户​端​和​ DBScale 之​间​的​数​据​是​压​缩​数​据​时​,DBScale 在​解​压​来​自​客​户​端​的​数​据​时​会​使​用​一​个​临​时​的​缓​冲​区​,该​参​数​用​于​指​定​该​缓​冲​区​的​默​认​大​小​。​
  • dbscale-hosts
    Option-File Format dbscale-hosts=#
    Type string
    Multiple N
    Default Value 空​
    Scope GLOBAL
    DynamicSet N
    Description DBScale 节​点​主​机​ IP。​
    配​置​ DBScale 节​点​的​主​机​ IP,在​用​户​执​行​ GRANT/CREATE USER/DROP USER/SET PASSWORD 时​会​相​应​更​新​ DBScale 主​机​对​应​的​用​户​信​息​。​通​常​我​们​建​议​配​置​为​dbscale主​机​所​在​的​网​段​。​允​许​配​置​多​个​值​,多​个​值​间​使​用​“​,”​ 分​隔​,例​如​:dbscale-hosts = 127.0.0.1,172.16.90.%。​
    确​保​配​置​的​值​与​在​认​证​数​据​源​上​创​建​的​客​户​端​登​录​账​户​ HOST 值​保​持​一​致​。​
  • dbscale-safe-sql-mode
    Option-File Format dbscale-safe-sql-mode=#
    Type int
    Multiple N
    Default Value 1
    Range 0, 1, 2
    Scope GLOBAL
    DynamicSet Y
    Description DBScale语​句​安​全​模​式​的​级​别​。​
    当​该​参​数​为​0时​,DBScale将​不​对​任​何​危​险​的​操​作​进​行​限​制​。​
    为​1时​,DBScale将​拒​绝​对​系​统​库​(mysql和​dbscale开​头​的​几​个​集​群​系​统​库​)的​如​下​操​作​: 1. drop schema; 2. drop table; 3. truncate table。​
    为​2时​,DBScale将​在​1的​基​础​上​额​外​拒​绝​如​下​操​作​:1. delete或​update操​作​没​有​where条​件​; 2. drop/truncate table 如​果​用​户​不​是​root用​户​; 3. drop schema 如​果​用​户​不​是​root用​户​。​
  • unsafe-redo-sql-action
    Option-File Format unsafe-redo-sql-action=#
    Type int
    Multiple N
    Default Value 1
    Range 0, 1, 2
    Scope GLOBAL
    DynamicSet Y
    Description DBScale的​两​阶​段​事​务​需​要​记​录​redo日​志​用​于​分​布​式​事​务​的​故​障​恢​复​,当​客​户​端​的​事​务​SQL语​句​包​含​redo不​安​全​的​sql时​,该​参​数​控​制​DBScale的​行​为​。​
    当​该​参​数​为​0时​,DBScale将​忽​略​对​redo不​安​全​的​sql的​处​理​;当​该​参​数​为​1时​,DBScale将​为​redo不​安​全​的​sql打​印​WARN日​志​;当​该​参​数​为​2时​,DBScale将​拒​绝​redo不​安​全​的​sql。​关​于​redo不​安​全​的​SQL可​以​参​考​第 15.11 节 “Redo 不​安​全​语​句​”。​
  • use-load-data-for-insert-select
    Option-File Format use-load-data-for-insert-select=#
    Type int
    Multiple N
    Default Value 0
    Range 0,1,2
    Scope SESSION
    DynamicSet Y
    Description DBScale 以​何​种​方​式​实​现​ insert select。​
    目​前​ DBScale 内​部​提​供​三​种​实​现​ insert select 功​能​方​式​,方​式​ 0 为​常​规​ insert 方​式​,1 为​ FIFO load 方​式​,2 为​类​数​据​迁​移​ load 方​式​,测​试​配​置​为​ 1 或​ 2 有​更​好​的​性​能​,支​持​动​态​配​置​。​若​插​入​的​表​为​分​区​表​且​有​自​增​列​,则​该​语​句​使​用​常​规​ insert 方​式​。​
  • use-partial-parse
    Option-File Format use-partial-parse=#
    Type int
    Multiple N
    Default Value 1
    Range 0,1
    Scope GLOBAL
    DynamicSet Y
    Description 是​否​开​启​部​分​解​析​功​能​。​
    部​分​解​析​功​能​是​指​遇​到​某​些​ DBScale 不​能​完​全​解​析​的​语​句​, DBScale 会​将​这​条​语​句​发​送​到​后​端​执​行​。​
  • use-savepoint
    Option-File Format use-savepoint=#
    Type int
    Multiple N
    Default Value 0
    Range 0,1
    Scope GLOBAL
    DynamicSet N
    Description 执​行​事​务​时​是​否​为​每​步​操​作​建​立​ savepoint。​
    DBScale 支​持​基​于​ Innodb 的​一​阶​段​分​布​式​事​务​。​参​数​ savepoint 控​制​ DBScale 对​事​务​过​程​中​错​误​的​处​理​行​为​。​如​果​开​启​了​,那​么​当​分​布​式​事​务​中​的​一​条​ sql 语​句​(可​能​涉​及​到​多​个​物​理​实​例​)执​行​返​回​错​误​包​时​(如​重​复​主​键​错​误​),DBScale会​自​动​将​分​布​式​事​务​状​态​回​滚​到​这​条​语​句​执​行​之​前​的​状​态​;否​则​,DBScale将​回​滚​整​个​事​务​。​
  • user-priority-high-access-pct
    Option-File Format user-priority-high-access-pct=#
    Type int
    Multiple N
    Default Value 25
    Scope GLOBAL
    DynamicSet Y
    Description 这​个​值​描​述​的​是​最​高​优​先​级​队​列​与​中​级​优​先​级​队​列​的​访​问​比​例​。​在​ enable_session_swap = 1 的​模​式​下​ DBScale 内​部​存​在​三​个​执​行​优​先​级​队​列​, 这​三​个​队​列​分​别​是​高​优​先​级​队​列​, 中​等​优​先​级​队​列​, 低​优​先​级​队​列​. 这​个​比​例​就​是​描​述​最​高​优​先​级​与​中​级​优​先​级​的​比​例​情​况​. 当​前​, 如​果​这​个​值​是​25, 那​么​在​高​级​优​先​级​队​列​内​元​素​充​足​的​情​况​下​,需​要​访​问​这​个​队​列​25次​后​,才​会​访​问​中​级​优​先​级​队​列​。​
  • user-priority-mid-access-pct
    Option-File Format user-priority-mid-access-pct=#
    Type int
    Multiple N
    Default Value 25
    Scope GLOBAL
    DynamicSet Y
    Description 这​个​值​描​述​的​是​中​级​优​先​级​队​列​与​低​级​优​先​级​队​列​的​访​问​比​例​。​在​ enable_session_swap = 1 的​模​式​下​ DBScale 内​部​存​在​三​个​执​行​优​先​级​队​列​, 这​三​个​队​列​分​别​是​高​优​先​级​队​列​, 中​等​优​先​级​队​列​, 低​优​先​级​队​列​. 这​个​比​例​就​是​描​述​中​级​优​先​级​与​低​级​优​先​级​的​比​例​情​况​. 当​前​, 如​果​这​个​值​是​25,那​么​在​高​级​优​先​级​队​列​内​元​素​充​足​的​情​况​下​,需​要​访​问​这​个​队​列​25次​后​,才​会​访​问​中​级​优​先​级​队​列​。​如​果​user-priority-mid-access-pct=25, user-priority-high-access-pct=25, 用​相​同​的​三​个​sysbench客​户​端​(分​别​是​三​种​优​先​级​)压​测​,压​测​的​结​果​大​致​比​例​是​“​145831:36492:8856”​
  • wait-timeout
    Option-File Format wait-timeout=#
    Type unsigned int
    Multiple N
    Default Value 28800
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 客​户​端​连​接​超​时​时​间​。​
    DBScale 客​户​端​连​接​超​时​时​间​,默​认​为​28800,即​8天​,单​位​为​秒​。​如​果​设​置​为​0,那​么​就​不​会​超​时​。​
  • wait-check-using-table-time
    Option-File Format wait-check-using-table-time=#
    Type unsigned int
    Multiple N
    Default Value 1
    Scope GLOBAL
    DynamicSet N
    Description 每​次​检​查​是​否​有​客​户​端​连​接​在​使​用​这​个​表​的​等​待​时​间​。​
    在​迁​移​时​,当​追​ binlog 已​经​执​行​到​差​距​很​小​时​, DBScale 会​进​行​锁​整​个​表​的​操​作​,在​锁​表​前​会​检​测​是​否​还​有​客​户​端​在​使​用​这​张​表​,如​果​有​就​等​待​这​么​长​时​间​后​在​做​检​测​,单​位​为​秒​。​
  • zookeeper-password
    Option-File Format zookeeper-password=#
    Type string
    Multiple N
    Default Value dbscale
    Scope GLOBAL
    DynamicSet N
    Description 多​DBScale 中​用​于​zookeeper权​限​验​证​的​密​码​ 。​
  • zookeeper-user
    Option-File Format zookeeper-user=#
    Type string
    Multiple N
    Default Value dbscale
    Scope GLOBAL
    DynamicSet N
    Description 多​DBScale 中​用​于​zookeeper权​限​验​证​的​用​户​名​ 。​
  • zk-ka-message-len
    Option-File Format zk-ka-message-len=#
    Type unsigned int
    Multiple N
    Default Value 10240
    Range 大​于​0
    Scope GLOBAL
    DynamicSet N
    Description 多​DBScale 中​用​于​zookeeper接​受​消​息​的​消​息​Buffer长​度​ 。​
  • zk-sleep-duration
    Option-File Format zk-sleep-duration=#
    Type unsigned long
    Multiple N
    Default Value 0.2
    Range 大​于​0
    Scope GLOBAL
    DynamicSet N
    Description 多​DBScale 中​为​了​操​作​协​调​而​设​置​的​zookeeper睡​眠​时​间​,单​位​为​秒​ 。​
  • zk-ka-version-gap
    Option-File Format zk-ka-version-gap=#
    Type unsigned int
    Multiple N
    Default Value 10
    Range 大​于​1
    Scope GLOBAL
    DynamicSet N
    Description 多​DBScale 中​zookeeper存​储​的​集​群​初​始​化​消​息​与​更​新​消​息​之​间​的​最​大​版​本​差​ 。​
  • zk-log-level
    Option-File Format zk-log-level=#
    Type Enum
    Multiple N
    Default Value INFO
    Range INFO,WARNING,DEBUG,ERROR
    Scope GLOBAL
    DynamicSet N
    Description zookeeper的​日​志​选​项​级​别​ 。​
  • zk-log-file
    Option-File Format zk-log-file=#
    Type string
    Multiple N
    Default Value /var/log/zookeeper.log
    Scope GLOBAL
    DynamicSet N
    Description zookeeper的​日​志​文​件​名​以​及​日​志​文​件​位​置​。​
  • zookeeper-host
    Option-File Format zookeeper-host=#
    Type string
    Multiple N
    Default Value 127.0.0.1:2181
    Scope GLOBAL
    DynamicSet N
    Description zookeeper集​群​各​节​点​的​连​接​配​置​。​该​zookeeper集​群​用​于​多​dbscale集​群​调​度​节​点​间​广​播​与​同​步​。​
    当​搭​建​多​节​点​的​zookeeper集​群​时​,使​用​逗​号​分​隔​进​行​配​置​。​例​如​:172.16.72.29:2181,172.16.72.226:2181,172.16.72.28:2181。​
  • zk-connect-timeout
    Option-File Format zk-connect-timeout=#
    Type unsigned long
    Multiple N
    Default Value 200
    Scope GLOBAL
    DynamicSet N
    Description zookeeper 连​接​超​时​时​间​,单​位​为​毫​秒​。​
  • load-analysis-num
    Option-File Format load-analysis-num=#
    Type int
    Multiple N
    Default Value 3
    Range >=1
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 用​于​处​理​一​条​load data请​求​数​据​包​解​析​的​工​作​线​程​数​。​
    当​load data导​入​数​据​的​瓶​颈​在​dbscale解​析​数​据​包​处​时​,调​大​该​参​数​可​以​显​著​提​高​load data的​性​能​。​但​当​该​值​大​于​1时​,数​据​实​际​导​入​后​端​ mysql 的​顺​序​将​可​能​与​文​件​中​的​顺​序​不​一​致​,通​常​这​是​可​以​忽​略​的​。​
  • max-load-analysis-wait-size
    Option-File Format max-load-analysis-wait-size=#
    Type int
    Multiple N
    Default Value 30
    Range >=2
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 用​于​处​理​load data数​据​包​解​析​的​analysis节​点​的​处​理​队​列​最​大​长​度​。​
    DBScale对​analysis节​点​进​行​数​据​包​填​充​时​,总​是​填​充​到​max-load-analysis-wait-size指​定​的​大​小​,并​且​analysis节​点​在​待​处​理​的​数​据​包​数​量​小​于​该​值​的​一​半​时​会​唤​醒​父​线​程​进​行​数​据​包​填​充​。​建​议​该​值​使​用​默​认​值​或​适​当​调​高​,如​果​需​要​导​入​的​数​据​量​非​常​的​大​时​。​
    另​外​如​果​该​值​过​大​,会​导​致​DBScale缓​存​过​多​的​数​据​包​,将​会​导​致​dbscale在​load data过​程​中​对​机​器​内​存​的​消​耗​过​多​,极​端​情​况​下​可​能​会​OOM。​
  • max-load-packet-size
    Option-File Format max-load-packet-size=#
    Type unsigned long
    Multiple N
    Default Value 后​端​catalog数​据​源​ max_allowed_packet 值​
    Range >=1024
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 用​于​处​理​load data数​据​包​解​析​的​analysis节​点​拼​接​数​据​包​最​大​值​。​
    DBScale analysis节​点​进​行​数​据​包​拼​接​,当​数​据​包​大​小​达​到​该​值​后​,将​数​据​包​放​回​load data节​点​并​创​建​新​的​数​据​包​继​续​解​析​拼​接​。​
    默​认​值​为​从​后​端​catalog数​据​源​获​取​ max_allowed_packet 值​,如​果​配​置​值​小​于​1024则​使​用​默​认​值​,如​果​大​于​等​于​1024则​使​用​配​置​值​。​
  • max-load-select-analysis-wait-size
    Option-File Format max-load-select-analysis-wait-size=#
    Type int
    Multiple N
    Default Value 20000
    Range >=2
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 用​于​处​理​load data处​理​insert select请​求​时​,数​据​包​解​析​的​load select analysis节​点​的​待​处​理​数​据​行​队​列​最​大​长​度​。​
    DBScale对​load select analysis节​点​进​行​数​据​包​填​充​时​,总​是​填​充​到​max-load-select-analysis-wait-size指​定​的​大​小​,并​且​load select analysis节​点​在​待​处​理​的​数​据​包​数​量​小​于​该​值​的​一​半​时​会​唤​醒​父​线​程​进​行​数​据​包​填​充​。​建​议​该​值​使​用​默​认​值​或​适​当​调​高​,如​果​需​要​导​入​的​数​据​量​非​常​的​大​时​。​
    另​外​如​果​该​值​过​大​,会​导​致​DBScale缓​存​过​多​的​数​据​行​,将​会​导​致​dbscale在​load data过​程​中​对​机​器​内​存​的​消​耗​过​多​,极​端​情​况​下​可​能​会​OOM。​
  • max-load-ready-packets
    Option-File Format max-load-ready-packets=#
    Type int
    Multiple N
    Default Value 64
    Range >=10
    Scope GLOBAL
    DynamicSet Y
    Description DBScale 处​理​load data时​,每​个​后​端​数​据​包​发​送​线​程​缓​存​的​最​大​待​发​送​数​据​包​的​数​量​。​
    DBScale往​后​端​发​送​的​LOAD DATA数​据​包​每​个​是​16M,默​认​值​64即​1G。​每​个​后​端​partition对​应​一​个​数​据​包​发​送​线​程​。​当​后​端​mysql处​理​过​慢​时​可​能​导​致​数​据​包​在​数​据​包​发​送​线​程​上​堆​积​,但​堆​积​的​量​达​到​max-load-ready-packets时​,DBScale将​挂​起​该​load data任​务​直​到​堆​积​的​量​小​于​max-load-ready-packets。​
main secion 配​置​示​例​如​下​:
[main]
authenticate-source = auth
admin-user = dbscale
admin-password = dbscale
driver = mysql
log-level = DEBUG
log-file = dbscale.log

3.3.2. driver section

MySQL 主​要​包​含​ 2 个​层​次​:server 层​和​存​储​引​擎​层​。​类​似​的​,DBScale 也​分​为​ 2 个​层​次​:server 层​和​ driver 层​。​DBScale 为​每​一​类​支​持​的​数​据​库​实​现​一​个​ driver。​driver中​实​现​了​ DBScale 与​后​端​数​据​库​进​行​通​信​的​通​信​协​议​,并​包​含​了​对​应​数​据​库​的​ SQL 解​析​器​。​目​前​ DBScale 只​支​持​ MySQL 数​据​库​,所​以​暂​只​提​供​ MySQL 的​ driver。​
driver section 的​配​置​主​要​包​含​了​ DBScale 的​对​外​接​口​定​义​,以​及​后​端​数​据​库​类​型​。​
  • bind-address
    Option-File Format bind-address=#
    Type string
    Multiple N
    Default Value 127.0.0.1
    Range Ip address or hostname
    Description DBScale 绑​定​的​ IP 地​址​。​
    如​果​一​台​机​器​有​多​个​ IP 地​址​或​有​使​用​浮​动​ IP ,可​以​将​该​选​项​设​为​‘​0.0.0.0’​ ,这​样​通​过​所​有​的​ IP 都​可​以​访​问​到​ DBscale。​
  • check-using-table-times
    Option-File Format check-using-table-times=#
    Type unsigned int
    Multiple N
    Default Value 100
    Range >0
    Description 迁​移​数​据​时​检​测​是​否​有​表​在​使​用​的​次​数​。​
    在​迁​移​数​据​时​,追​ binlog 已​经​执​行​到​差​距​很​小​时​,要​锁​这​张​表​,锁​表​前​需​要​检​测​是​否​有​客​户​端​连​接​仍​然​在​使​用​这​个​表​,如​果​有​就​等​一​段​时​间​继​续​检​测​,最​多​检​测​check-using-table-times次​,如​果​仍​然​有​客​户​端​连​接​在​使​用​这​个​表​,就​放​弃​锁​表​,继​续​追​ binlog,追​到​差​距​小​时​仍​然​进​行​这​个​操​作​流​程​。​check-using-table-times 表​示​的​是​检​测​次​数​。​
  • close-cross-node-transaction
    Option-File Format close-cross-node-transaction=#
    Type int
    Multiple N
    Default Value 0
    Range 0, 1
    Description DBScale是​否​允​许​跨​节​点​分​布​式​事​务​的​执​行​。​0 表​示​允​许​, 1表​示​禁​止​。​
  • port [driver]
    Option-File Format port=#
    Type int
    Multiple N
    Default Value 3307
    Range >0
    Description DBScale 绑​定​的​端​口​。​
  • admin-port [driver]
    Option-File Format port=#
    Type int
    Multiple N
    Default Value 23399
    Range >0
    Description DBScale 管​理​端​口​。​
  • type [driver]
    Option-File Format type=#
    Type string
    Multiple N
    Default Value MySQLDriver
    Range MySQLDriver
    Description DBScale 后​端​数​据​库​集​群​的​类​型​。​
目​前​ DBScale 只​支​持​ MySQL 数​据​库​集​群​。​
driver section 示​例​如​下​:
[driver mysql]
type = MySQLDriver
bind-address = 0.0.0.0
port = 3306

3.3.3. black-white section

black-white section 定​义​了​ Dbscale 的​黑​白​名​单​。​
DBScale 支​持​在​登​录​时​检​查​客​户​端​ Ip 并​阻​止​其​登​录​的​功​能​.
目​前​ DBScale 支​持​基​于​黑​白​名​单​的​ Ip 过​滤​。​
  • black [black-white]
    Option-File Format black=#
    Type string
    Multiple Y
    Description DBScale 阻​止​登​录​的​ Ip. 如​果​ white 中​配​置​了​包​含​该​ Ip 规​则​,不​阻​止​.
  • white [black-white]
    Option-File Format white=#
    Type string
    Multiple Y
    Description DBScale 不​做​登​录​检​查​的​客​户​端​ Ip
    需​要​注​意​,在​实​际​使​用​时​,DBScale默​认​不​会​拒​绝​任​何​IP,用​户​应​当​将​焦​点​放​在​黑​名​单​上​,通​过​黑​名​单​来​限​制​访​问​DBScale的​IP,而​为​了​避​免​“​误​伤​”​,通​过​额​外​添​加​白​名​单​来​单​独​开​放​某​些​被​黑​名​单​匹​配​到​的​IP地​址​的​访​问​权​限​。​也​就​是​说​,白​名​单​具​有​高​优​先​级​;没​有​出​现​在​ black-white 列​表​中​的​ IP 或​匹​配​规​则​将​被​视​为​白​名​单​ IP。​
    黑​白​名​单​可​以​在​线​调​整​,具​体​命​令​请​参​考​第 7.4.15 节 “在​线​调​整​IP黑​白​名​单​”
    黑​白​名​单​可​以​通​过​命​令​查​看​,具​体​请​参​考​第 7.3.4 节 “查​看​ DBScale IP黑​白​名​单​”。​
  • 简​单​示​例​
    [black-white]
    black = 192.168.1.*
    white = 192.168.1.1
    
    上​面​的​示​例​中​,DBScale 会​阻​止​ 192.168.1.* 网​段​除​ 192.168.1.1 之​外​的​所​有​ IP,其​他​网​段​不​被​阻​止​。​
    [black-white]
    black = .*
    white = 192.168.1.1
    
    上​面​的​示​例​中​,DBScale 会​阻​止​所​有​ IP 登​录​ DBScale,仅​允​许​ 192.168.1.1 登​录​ DBScale。​

3.3.4. data-server section

data-server section 定​义​后​端​数​据​库​实​例​的​物​理​信​息​,其​中​包​含​的​选​项​主​要​是​用​于​创​建​到​该​数​据​库​实​例​的​连​接​用​的​。​
data-server 中​的​ user 和​ password 除​了​可​以​被​用​于​创​建​执​行​客​户​端​ SQL 的​数​据​库​连​接​,还​被​用​于​执​行​一​些​管​理​操​作​,例​如​ CHANGE MASTER,所​以​最​好​配​置​一​个​权​限​较​高​的​数​据​库​用​户​。​
  • external-load-script [data-server]
    Option-File Format external-load-script=#
    Type string
    Multiple N
    Default Value ""
    Description DBScale 前​端​进​行​外​部​数​据​导​入​的​可​执​行​程​序​路​径​。​
    该​参​数​只​有​在​参​数​ is-external-load [data-server] 开​启​时​才​有​用​。​
  • host [data-server]
    Option-File Format host=#
    Type string
    Multiple N
    Range Ip or hostname
    Description 后​端​数​据​库​实​例​的​ host 信​息​。​
  • is-external-load [data-server]
    Option-File Format is-external-load=#
    Type int
    Multiple Value Y
    Default Value 0
    Range 0,1
    Description 该​data-server是​否​使​用​外​部​导​入​程​序​来​执​行​load data命​令​。​
  • local-load-script [data-server]
    Option-File Format local-load-script=#
    Type string
    Multiple N
    Default Value ""
    Description DBScale 前​端​使​用​外​部​导​入​方​式​执​行​ INSERT SELECT 语​句​时​的​可​执​行​程​序​路​径​。​
    该​参​数​只​有​在​参​数​ is-external-load [data-server] 开​启​时​才​有​用​。​
  • master-backup [data-server]
    Option-File Format master-backup=#
    Type int
    Multiple N
    Default Value 1
    Range 0,1
    Description 该​数​据​库​实​例​是​否​可​以​被​选​为​复​制​集​群​中​的​主​节​点​。​
  • password [data-server]
    Option-File Format password=#
    Type string
    Multiple N
    Description 数​据​库​实​例​的​登​录​密​码​。​
    当​需​要​修​改​ password 时​,需​要​先​停​止​ dbscale 进​程​,然​后​修​改​配​置​文​件​,之​后​才​可​以​在​后​端​所​有​数​据​库​实​例​上​(复​制​集​群​只​需​要​在​主​节​点​上​做​)进​行​ CREATE USER/ALTER USER 等​相​关​修​改​,如​果​有​任​何​正​在​或​曾​经​以​相​关​用​户​名​和​密​码​作​为​连​接​参​数​作​为​ slave 的​数​据​库​实​例​(即​在​改​动​ password 后​这​些​ slave 的​连​接​信​息​会​过​期​),需​要​将​其​ stop slave 并​ reset slave all,最​后​再​重​新​启​动​ dbscale 进​程​。​
  • port [data-server]
    Option-File Format port=#
    Type int
    Multiple N
    Description 数​据​库​实​例​的​端​口​。​
  • remote-user [data-server]
    Option-File Format remote-user=#
    Type string
    Multiple Value N
    Default Value "root"
    Description 该​data-server用​于​远​程​ssh登​录​的​用​户​名​。​
  • remote-password [data-server]
    Option-File Format remote-password=#
    Type string
    Multiple Value N
    Default Value ""
    Description 该​data-server用​于​远​程​ssh登​录​的​密​码​。​
  • remote-port [data-server]
    Option-File Format remote-port=#
    Type string
    Multiple Value N
    Default Value 22
    Description 该​data-server用​于​远​程​ssh登​录​的​端​口​。​
  • user [data-server]
    Option-File Format user=#
    Type string
    Multiple N
    Description 数​据​库​实​例​的​登​录​用​户​名​。​
    当​需​要​修​改​ user 时​,需​要​先​停​止​ dbscale 进​程​,然​后​修​改​配​置​文​件​,之​后​才​可​以​在​后​端​所​有​数​据​库​实​例​上​(复​制​集​群​只​需​要​在​主​节​点​上​做​)进​行​ CREATE USER/ALTER USER 等​相​关​修​改​,如​果​有​任​何​正​在​或​曾​经​以​相​关​用​户​名​和​密​码​作​为​连​接​参​数​作​为​ slave 的​数​据​库​实​例​(即​在​改​动​ user 后​这​些​ slave 的​连​接​信​息​会​过​期​),需​要​将​其​ stop slave 并​ reset slave all,最​后​再​重​新​启​动​ dbscale 进​程​。​
  • ignore-ping [data-server]
    Option-File Format ignore-ping=#
    Type INT
    Multiple N
    Range 0, 1
    Description 这​个​数​据​库​实​例​是​否​由​ dbscale 检​查​其​状​态​。​配​置​了​这​个​选​项​的​ server, 只​能​出​现​在​ ServerDatasource 和​ ReadOnlyDatasource。​这​两​种​数​据​源​,只​能​被​配​置​在​alias schema中​。​
data-server section 实​例​配​置​如​下​:
[data-server global-master]
host = 192.168.192.110
port = 3307
user = dbscale
password = dbscale
master-backup = 1
[data-server global-slave]
host = 192.168.192.111
port = 3307
user = dbscale
password = dbscale
master-backup = 1

3.3.5. data-source section

data-source section 定​义​了​数​据​源​组​织​和​管​理​后​端​ data-server 所​需​的​选​项​。​
DBScale 支​持​了​多​种​类​型​的​数​据​源​,不​同​的​数​据​源​类​型​定​义​了​不​同​的​组​织​管​理​策​略​,所​以​它​们​所​需​的​选​项​也​可​能​有​所​不​同​。​
目​前​ DBScale 主​要​支​持​的​数​据​源​类​型​有​:server、​read_only、​share_disk、​load_balance、​rwsplit 和​ replication。​不​同​的​类​型​通​过​选​项​ type 进​行​区​分​。​
除​了​ type 以​外​,所​有​的​ data-source 类​型​都​会​提​供​选​项​ user 和​ password 。​类​似​于​ data-server 中​的​ user 和​ password,这​两​个​属​性​也​是​用​来​创​建​数​据​库​连​接​的​;不​同​的​是​这​两​个​属​性​是​业​务​相​关​的​,DBScale 会​优​先​使​用​ data-source 中​配​置​的​ user 和​ password 来​创​建​连​接​,如​果​ data-source 中​没​有​配​置​,才​会​使​用​ data-server 中​ user 和​ password 来​创​建​连​接​。​
在​开​启​ XA 功​能​时​, 所​有​的​ source 在​配​置​文​件​中​需​要​指​定​ group-id, 用​于​标​识​这​个​ datasource 属​于​那​个​组​,主​要​用​于​做​ XA 的​ failover, group-id 的​值​需​要​唯​一​。​在​关​闭​ XA 功​能​时​,可​以​不​指​定​ group-id.
  • password [data-source]
    Option-File Format password=#
    Type string
    Multiple N
    Description 数​据​库​实​例​的​登​录​密​码​。​
  • type [data-source]
    Option-File Format type=#
    Type string
    Multiple N
    Range server,read_only , share_disk,load_balance,rwsplit,replication
    Description DBScale 后​端​数​据​库​集​群​的​类​型​。​
  • user [data-source]
    Option-File Format user=#
    Type string
    Multiple N
    Description 数​据​库​实​例​的​登​录​用​户​名​。​
  • group-id [data-source]
    Option-File Format group-id=#
    Type int (value > 0)
    Multiple N
    Description 用​于​标​识​这​个​ source 属​于​那​个​组​, 每​个​ group-id 的​值​唯​一​。​

3.3.5.1. server data-source

server 类​型​的​ data-source 对​应​于​一​台​数​据​库​实​例​。​它​通​过​选​项​ server 指​明​数​据​库​实​例​ data-server,并​且​定​义​了​该​数​据​库​实​例​的​连​接​池​。​
  • server [data-source.server]
    Option-File Format server=#
    Type string
    Multiple N
    Format string-int-int-int-int
    Description Server data-source 所​关​联​的​ data server,以​及​相​关​的​连​接​池​配​置​。​
    data-server 选​项​的​格​式​为​“​string-int-int-int-int”​,其​中​ string 为​ data-server 的​实​例​名​称​,后​面​ 4 个​ int 分​别​为​连​接​池​的​初​始​值​、​最​大​值​、​低​阀​值​、​和​高​阀​值​,它​们​之​间​用​“​-”​进​行​分​割​,并​且​要​求​满​足​“​初​始​值​<=低​阀​值​<=高​阀​值​<最​大​值​”​。​
    DBScale 会​为​每​个​“​server”​ data-source 维​护​一​个​或​多​个​连​接​池​(连​接​池​的​数​量​由​参​数​ conn-pool-num 决​定​)。​当​工​作​线​程​需​要​执​行​ SQL 语​句​的​时​候​,会​从​连​接​池​中​取​走​一​个​空​闲​连​接​,并​在​执​行​成​功​之​后​将​该​连​接​放​回​连​接​池​;如​果​执​行​失​败​,那​么​该​连​接​将​会​被​回​收​清​理​。​每​个​连​接​池​都​会​定​期​地​进​行​连​接​清​理​,在​这​里​连​接​清​理​指​的​是​释​放​多​余​的​空​闲​连​接​和​清​理​故​障​连​接​。​
    data-server 选​项​中​包​含​的​“​初​始​值​、​最​大​值​、​低​阀​值​、​和​高​阀​值​”​定​义​了​连​接​池​的​行​为​:
    • 初​始​值​也​是​连​接​池​的​初​始​连​接​数​,为​ DBScale 启​动​的​时​候​会​自​动​在​该​连​接​池​中​创​建​的​连​接​数​。​当​故​障​节​点​重​新​加​入​ DBScale 集​群​, DBScale 确​保​相​关​的​连​接​池​的​连​接​数​不​低​于​初​始​值​。​
    • 最​大​值​为​连​接​池​中​连​接​数​目​的​上​限​,为​该​server data-source 最​大​允​许​的​连​接​数​(包​含​空​闲​连​接​和​正​在​被​使​用​的​连​接​)。​
    • 低​阀​值​和​高​阀​值​是​连​接​池​连​接​清​理​中​用​到​的​参​数​。​当​连​接​池​中​连​接​的​数​目​小​于​等​于​低​阀​值​时​,该​连​接​池​停​止​清​理​空​闲​连​接​;当​连​接​池​中​的​连​接​数​高​于​高​阀​值​的​时​候​,清​理​线​程​会​往​日​志​文​件​中​输​出​告​警​信​息​;当​连​接​池​中​的​连​接​数​高​于​低​阀​值​时​,DBScale 每​间​隔​ connection-pool-manage-interval 时​间​进​行​一​次​连​接​清​理​,并​且​每​次​连​接​清​理​回​收​最​多​ max-connection-cleanup-number 个​空​闲​连​接​。​

3.3.5.2. read-only data-source

read_only 类​型​的​ data-source 对​应​于​一​台​数​据​库​实​例​。​用​户​只​允​许​进​行​读​操​作​。​除​了​ type 与​ server 类​型​的​ data-source 不​同​,其​余​的​配​置​参​数​均​相​同​。​

3.3.5.3. share_disk data-source

share_disk 类​型​的​ data-source 封​装​了​一​对​共​享​数​据​存​储​的​ data-server。​它​们​分​为​2个​角​色​:active 和​ cold_standby。​正​常​情​况​下​,DBScale 只​会​使​用​ active 的​ data-server,当​active 的​ data-server 不​可​用​时​,DBScale 会​自​动​启​用​ cold_standby 的​ data-server。​
  • active [data-source.share_disk]
    Option-File Format active=#
    Type string
    Multiple N
    Format string-int-int-int-int
    Description share disk data-source 所​关​联​的​ active data server,以​及​相​关​的​连​接​池​配​置​。​
  • cold_standby [data-source.share_disk]
    Option-File Format cold_standby=#
    Type string
    Multiple N
    Format string-int-int-int-int
    Description share disk data-source 所​关​联​的​cold_standby data server,以​及​相​关​的​连​接​池​配​置​。​

3.3.5.4. load_balance data-source

load_balance 类​型​的​ data-source 封​装​了​一​组​负​载​均​衡​的​ data-server。​当​ DBScale 需​要​从​一​个​load_balance data-source 中​获​取​连​接​时​,该​ data-source 会​按​照​一​定​的​负​载​均​衡​算​法​,从​它​所​包​含​的​那​组​ data-server 中​选​一​个​ data-server 来​提​供​连​接​。​load_balance data-source 的​配​置​选​项​有​ server 和​ scheduler-type:
  • server [data-source.load_balance]
    Option-File Format server=#
    Type string
    Multiple Y
    Format string-int-int-int-int[-int]
    Description load_balance data-source 所​关​联​的​ data server,以​及​相​关​的​连​接​池​和​权​重​配​置​。​
    load_balance data-source 中​的​ server 的​配​置​方​式​基​本​上​与​server data-source 中​的​ server 相​同​,区​别​在​于​两​点​,第​一​点​是​ server data-source 中​只​能​有​一​个​ server,而​load_balance data-source 可​以​有​多​个​ server;第​二​点​是​如​果​ load_balance 的​ scheduler-type = weight,则​需​要​额​外​配​置​该​ server 的​权​重​值​,设​置​权​重​值​的​方​式​是​在​对​应​ server 的​连​接​池​配​置​参​数​后​追​加​一​个​非​负​整​数​,例​如​配​置​项​ server=server1-5-10-7-9-20 中​的​ 20 就​是​设​定​ server1 在​该​ load-balance 数​据​源​内​的​权​重​是​20。​就​像​ server data-source 那​样​,对​于​每​个​ server,load_balance data-source 会​为​每​个​ server 维​护​一​个​连​接​池​。​对​于​连​接​池​的​管​理​请​参​考​ server data-source 的​选​项​ server 中​说​明​。​
  • scheduler-type [data-source.load_balance]
    Option-File Format scheduler-type=#
    Type string
    Multiple N
    Default round-robin
    Range round-robin, weight
    Description 负​载​均​衡​策​略​。​
    目​前​ DBScale 提​供​了​轮​循​的​负​载​均​衡​算​法​ round-robin 和​基​于​权​重​比​例​的​负​载​均​衡​算​法​ weight。​
    • round-robin:round-robin 方​式​是​指​ load_balance 数​据​源​会​按​顺​序​依​次​从​配​置​的​各​个​ server 中​轮​流​取​连​接​来​执​行​读​ SQL 请​求​。​
    • weight:如​果​ shceduler-type 被​配​置​为​ weight,DBScale 会​根​据​数​据​源​内​不​同​ server 的​不​同​权​重​比​例​为​其​分​配​相​应​比​例​的​读​请​求​数​量​。​以​下​面​的​配​置​为​例​:
      [data-source rep]
      type = replication
      user = root
      scheduler-type = weight
      load-balance-strategy = MASTER-SLAVES
      master = master_server-1-2-1-1-10
      slave = slave_server_1-1-2-1-1-90
      slave = slave_server_2-1-2-1-1-0
      slave-source = slave_source
      
      那​么​该​数​据​源​在​工​作​时​,master_server、​slave_server_1 和​ slave_server_2 之​间​的​权​重​比​例​是​ 1:9:0,该​数​据​源​会​按​照​这​个​比​例​为​各​个​ server 分​配​读​请​求​数​量​(因​为​ slave_server_2 权​重​值​为​ 0,所​以​它​将​不​会​被​分​配​ SQL 请​求​)。​因​为​配​置​了​ load-balance-strategy = MASTER-SLAVES,所​以​ master 也​会​参​与​到​读​的​负​载​均​衡​,权​重​值​是​配​置​的​ 10,如​果​将​ load-balance-strategy 配​置​为​ SLAVES,如​果​ slave 节​点​仍​然​可​用​,那​么​ master 无​论​配​置​的​ weight 值​是​多​少​都​不​会​参​与​读​的​负​载​均​衡​。​需​要​注​意​的​是​,这​个​比​例​只​是​读​请​求​分​布​的​总​体​趋​势​,不​是​严​格​比​例​。​

3.3.5.5. multiple_master data-source

multiple_master 数​据​源​封​装​了​一​组​具​有​一​致​数​据​的​数​据​库​实​例​,需​要​借​助​诸​如​ Galera Cluster 这​类​提​供​强​数​据​一​致​性​的​多​主​集​群​来​提​供​数​据​一​致​性​保​证​。​DBScale 会​使​用​其​中​一​个​数​据​库​实​例​作​为​写​节​点​,同​时​在​余​下​的​其​他​数​据​库​实​例​间​做​读​操​作​的​负​载​均​衡​。​当​写​节​点​故​障​后​,选​择​一​个​读​节​点​作​为​新​的​写​节​点​,并​将​故​障​的​写​节​点​设​置​为​读​节​点​,故​障​的​写​节​点​在​恢​复​后​会​加​入​到​读​操​作​的​负​载​均​衡​轮​询​。​除​了​用​户​名​、​密​码​配​置​项​,该​数​据​源​还​有​ active、​server、​scheduler-type 三​个​配​置​参​数​。​
  • active [data-source.multiple_master]
    Option-File Format active=#
    Type string
    Multiple N
    Format string-int-int-int-int
    Description multiple_master 数​据​源​所​关​联​的​负​责​写​操​作​的​ data server,以​及​相​关​的​连​接​池​配​置​。​
  • server [data-source.multiple_master]
    Option-File Format server=#
    Type string
    Multiple Y
    Format string-int-int-int-int
    Description multiple_master 数​据​源​所​关​联​的​负​责​读​操​作​的​ data server,以​及​相​关​的​连​接​池​配​置​。​
    该​配​置​项​指​定​了​负​责​读​操​作​的​数​据​库​实​例​列​表​,这​些​实​例​的​配​置​顺​序​也​是​当​ active 出​现​故​障​时​,读​节​点​被​选​择​为​新​的​ active 节​点​的​优​先​级​顺​序​。​故​障​的​ active 节​点​在​恢​复​后​会​被​置​为​最​后​一​个​读​节​点​。​
  • scheduler-type [data-source.multiple_master]
    同​ scheduler-type [data-source.load_balance],但​取​值​只​能​是​ round-robin。​

3.3.5.6. rwsplit data-source

rwsplit data-source 是​一​个​读​写​分​离​的​数​据​源​。​所​谓​的​读​写​分​离​就​是​查​询​操​作​ SQL,如​ select、​show、​desc,会​发​送​读​节​点​,而​写​操​作​ SQL,如​ update、​insert、​delete,会​发​送​的​写​节​点​。​
它​会​包​含​ 1 个​用​于​写​的​ data-server 和​多​个​用​于​读​的​ data-server。​多​个​读​的​ data-server 直​接​进​行​负​载​均​衡​,所​以​ rwsplit data-source 也​有​ scheduler-type 选​项​,使​用​方​式​与​ load_balance data-source 一​致​。​
rwsplit data-source 中​的​写​ data-server 由​选​项​ master 指​定​,读​ data-server 由​选​项​ slave 指​定​, 所​以​ slave 选​项​可​以​有​多​个​。​ master 和​ slave 的​格​式​与​server data-source 中​的​ server 一​致​。​
另​外​,需​要​注​意​的​是​,rwsplit data-source 只​负​责​进​行​读​写​分​离​,它​不​维​护​读​写​ data-server 之​间​的​主​从​关​系​。​
  • master [data-source.rwsplit]
    Option-File Format master=#
    Type string
    Multiple N
    Format string-int-int-int-int[-int]
    Description rwsplit data-source 所​关​联​的​写​ data server,以​及​相​关​的​连​接​池​和​权​重​值​配​置​。​
  • scheduler-type [data-source.rwsplit]
  • slave [data-source.rwsplit]
    Option-File Format slave=#
    Type string
    Multiple Y
    Format string-int-int-int-int[-int]
    Description rwsplit data-source 所​关​联​的​读​ data server,以​及​相​关​的​连​接​池​和​权​重​值​配​置​。​

3.3.5.7. replication data-source

Replication data-source 类​似​于​ rwsplit data-source,可​以​进​行​读​写​分​离​,但​它​要​比​ rwsplit data-source 复​杂​。​
首​先​,不​同​于​ rwsplit data-source,replication data-source 可​以​配​置​一​个​写​ data-server 或​一​个​写​ data-source;可​以​配​置​多​个​读​ data-server 和​多​个​读​ data-source。​
其​次​,replication data-source 可​以​关​闭​读​写​分​离​的​功​能​,让​所​有​的​请​求​都​发​送​到​写​节​点​上​。​
最​后​,replication data-source 会​自​动​维​护​读​写​节​点​之​间​主​从​复​制​关​系​,当​主​节​点​发​生​故​障​的​时​候​,DBScale 会​自​动​从​从​节​点​中​选​择​一​个​新​主​节​点​,并​调​整​其​他​从​节​点​从​新​的​主​节​点​进​行​复​制​;当​原​来​的​主​节​点​恢​复​的​时​候​,DBScale 会​自​动​将​它​调​整​为​新​主​节​点​的​一​个​从​节​点​。​这​里​的​从​节​点​为​读​ data-server 和​读​ data-source。​从​读​ data-source 中​选​主​时​,就​是​从​该​ source 中​选​一​个​ data-server。​目​前​可​以​被​选​主​的​ data-source 主​要​是​ load_balance 和​ server data-source;resplit 和​ replication data-source 作​为​读​ data-source 时​,是​不​会​被​选​为​新​主​节​点​。​
注​意​,master-backup 为​ 0 的​ data-server 是​不​会​被​选​为​主​的​。​
和​ rwsplit data-source 相​似​,replication data-source 在​多​个​读​ data-server 和​读​ data-source之​间​进​行​负​载​均​衡​;replication data-source 会​为​配​置​的​ master 和​ slave 选​项​下​的​ data-server 维​护​连​接​池​。​
  • load-balance-strategy
    Option-File Format load-balance-strategy=#
    Type string
    Multiple N
    Default SLAVES
    Range SLAVES,MASTER,MASTER-SLAVES
    Description replication data-source读​写​分​离​的​执​行​策​略​。​
    当​ load-balance-strategy 为​ SLAVES时​,DBScale是​正​常​的​读​写​分​离​模​式​,写​操​作​发​到​主​节​点​上​,读​操​作​发​到​从​节​点​上​。​当​该​参​数​为​ MASTER时​,DBScle会​将​所​有​的​读​写​请​求​都​发​送​到​主​节​点​上​执​行​。​当​该​参​数​为​ MASTER-SLAVES时​,DBScale会​将​写​操​作​发​往​主​节​点​,读​操​作​发​到​从​节​点​和​主​节​点​上​,即​主​节​点​参​与​读​的​负​载​均​衡​。​
  • master [data-source.replication]
    Option-File Format master=#
    Type string
    Multiple N
    Format string-int-int-int-int[-int]
    Description replication data-source 所​关​联​的​写​ data server,以​及​相​关​的​连​接​池​和​权​重​值​配​置​。​
  • master-source [data-source.replication]
    Option-File Format master-source=#
    Type string
    Multiple N
    Range 配​置​文​件​中​ data-source 的​实​例​名​
    Description replication data-source 所​关​联​的​写​ data source。​
  • scheduler-type [data-source.replication]
  • semi-sync-on
    Option-File Format semi-sync-on=#
    Type int
    Multiple N
    Default Value 0
    Range 0,1
    Description replication 是​否​支​持​半​同​步​。​
  • slave [data-source.replication]
    Option-File Format slave=#
    Type string
    Multiple Y
    Format string-int-int-int-int[-int]
    Description replication data-source 所​关​联​的​读​ data server,以​及​相​关​的​连​接​池​和​权​重​值​配​置​。​
  • slave-source [data-source.replication]
    Option-File Format slave-source=#
    Type string
    Multiple Y
    Range 配​置​文​件​中​ data-source 的​实​例​名​
    Description replication data-source 所​关​联​的​读​ data source。​slave-source 不​参​与​读​负​载​均​衡​。​

3.3.5.8. odbc data-source

odbc data-source 是​一​个​使​用​odbc建​立​连​接​的​数​据​源​。​可​以​用​于​连​接​支​持​odbc连​接​的​数​据​库​,如​postgresql. 目​前​odbc data-source 处​于​beta版​本​.目​前​支​持​增​删​改​查​等​基​本​功​能​.
  • server [data-source.odbc]
    Option-File Format server=#
    Type string
    Multiple N
    Format string-int-int-int-int
    Description odbc data-source 所​关​联​的​ data server,以​及​相​关​的​连​接​池​。​其​中​server名​字​为​用​于​配​置​odbc连​接​的​dsn, 示​例​如​下​.
  • connector [data-source.odbc]
    Option-File Format connector=#
    Type string
    Multiple N
    Description 用​于​odbc初​始​话​连​接​, 如​果​配​置​connector, 则​建​立​连​接​时​使​用​connector来​初​始​化​连​接​. 如​果​未​配​置​该​选​项​, 则​使​用​server名​所​指​向​的​dsn来​初​始​化​连​接​, 示​例​如​下​。​
odbc data-source 的​示​例​配​置​:
[data-source pg]
type = odbc
server = mydsn-2-2-2-2
connector = DRIVER=PostgreSQL ANSI;DATABASE=postgres;SERVER=localhost;PORT=5432;UID=postgres;PWD=;

另外需要配置驱动:
vim /etc/odbcinst.ini
[PostgreSQL ANSI]
Description   = PostgreSQL ODBC driver (ANSI version)
Driver    = psqlodbca.so
Setup   = libodbcpsqlS.so
Debug   = 0
CommLog   = 1
UsageCount    = 1

[PostgreSQL Unicode]
Description   = PostgreSQL ODBC driver (Unicode version)
Driver    = psqlodbcw.so
Setup   = libodbcpsqlS.so
Debug   = 0
CommLog   = 1
UsageCount    = 1

如果不配置connector, 可以在系统添加dsn,配置示例如下:
vim /etc/odbc.ini
[mydsn]
Description             = PostgreSQL
Driver          = PostgreSQL ANSI
Trace           = No
TraceFile               = /tmp/psqlodbc.log
Database                = postgres
Servername              = localhost
UserName                = postgres
Password                =
Port            = 5432
ReadOnly                = Yes
RowVersioning           = No
ShowSystemTables                = No
ShowOidColumn           = No
FakeOidIndex            = No
ConnSettings            =

3.3.5.9. observer data-source

observer data-source 即​观​察​者​数​据​源​。​
所​谓​的​观​察​者​数​据​源​是​指​在​主​从​复​制​数​据​源​内​,某​个​从​节​点​被​设​定​为​不​会​被​切​换​为​主​节​点​,但​是​当​集​群​主​节​点​调​整​时​,它​也​会​相​应​调​整​主​从​,同​时​它​也​不​负​担​任​何​数​据​请​求​,而​是​仅​仅​作​为​ slave 节​点​从​主​节​点​同​步​数​据​。​
观​察​者​数​据​源​适​合​作​为​备​份​节​点​,负​责​备​份​集​群​数​据​。​
配​置​观​察​者​数​据​源​时​,不​需​要​单​独​配​置​一​个​ data-source section,而​是​在​主​从​复​制​数​据​源​内​将​ scheduler-type 设​置​为​ weight,并​将​某​个​ slave 的​权​重​设​置​为​ 0,同​时​将​该​ slave 对​应​的​ data-server 的​ master-backup 选​项​设​置​为​ 0 即​可​。​这​样​设​置​后​的​ slave 节​点​就​是​该​主​从​复​制​数​据​源​内​的​一​个​观​察​者​数​据​源​,其​不​会​被​选​为​主​节​点​,不​会​被​分​配​任​何​数​据​请​求​,只​从​主​节​点​同​步​数​据​。​

3.3.5.10. data-source 常​用​配​置​方​案​示​例​

  • 单​个​ server 的​ data-source
    [data-source single_source]
    type = server
    server = global_slave-10-100-20-80
    user = worker
    password = worker_password
  • 共​享​数​据​存​储​的​ data-source
    [data-source sd_source]
    type = share_disk
    active = as-10-100-20-80
    cold-standby = css-10-100-20-80
    user = worker
    password = worker_password
  • 负​载​均​衡​的​ data-source
    [data-source auth_source]
    type = load_balance
    server = auth_server1-10-100-20-80
    server = auth_server2-10-100-20-80
    user = worker
    password = worker_password
  • 带​权​重​的​负​载​均​衡​的​ data-source
    [data-source auth_source]
    type = load_balance
    scheduler-type = weight
    server = auth_server1-10-100-20-80-1
    server = auth_server2-10-100-20-80-5
    user = worker
    password = worker_password
  • 读​写​分​离​的​ data-source
    [data-source rw_source]
    type = rwsplit
    master = global_master-10-100-20-80
    slave = global_slave1-10-100-20-80
    slave = global_slave2-10-100-20-80
    user = worker
    password = worker_password
  • 带​权​重​的​读​写​分​离​的​ data-source
    [data-source rw_source]
    type = rwsplit
    scheduler-type = weight
    master = global_master-10-100-20-80-0
    slave = global_slave1-10-100-20-80-2
    slave = global_slave2-10-100-20-80-4
    user = worker
    password = worker_password
  • 一​层​主​从​复​制​的​ data-source
    [data-source simple_rep]
    type = replication
    master = global_master-10-100-20-80
    slave = global_slave-10-100-20-80
    user = worker
    password = worker_password
  • 带​权​重​的​一​层​主​从​复​制​的​ data-source
    [data-source simple_rep]
    type = replication
    scheduler-type = weight
    load-balance-strategy = MASTER-SLAVES
    master = global_master-10-100-20-80-1
    slave = global_slave-10-100-20-80-9
    user = worker
    password = worker_password
  • 带​观​察​者​数​据​源​的​一​层​主​从​复​制​的​ data-source
    [data-source simple_rep_with_observer]
    type = replication
    scheduler-type = weight
    load-balance-strategy = MASTER-SLAVES
    master = global_master-10-100-20-80-1
    slave = global_slave-10-100-20-80-9
    slave = observer-1-2-1-1-0
    user = worker
    password = worker_password
    
    [data-server observer]
    host = 192.168.192.111
    port = 3308
    user = dbscale
    password = dbscale
    master-backup = 0
  • 两​层​主​从​复​制​的​ data-source
    [data-source partition_rep1]
    type = replication
    master = par_master1-10-100-20-80
    slave = par_slave1-10-100-20-80
    
    [data-source partition_rep2]
    type = replication
    master = par_master2-10-100-20-80
    slave = par_slave2-10-100-20-80
    
    [data-source complex_rep]
    type = replication
    master = global_master-10-100-20-80
    slave = global_slave-10-100-20-80
    slave-source = partition_rep1
    slave-source = partition_rep2
    user = worker
    password = woker_password
  • 带​权​重​的​两​层​主​从​复​制​的​ data-source
    [data-source partition_rep1]
    type = replication
    scheduler-type = weight
    load-balance-strategy = MASTER-SLAVES
    master = par_master1-10-100-20-80-1
    slave = par_slave1-10-100-20-80-1
    
    [data-source partition_rep2]
    type = replication
    scheduler-type = round-robin
    master = par_master2-10-100-20-80
    slave = par_slave2-10-100-20-80
    
    [data-source complex_rep]
    type = replication
    scheduler-type = weight
    load-balance-strategy = SLAVES
    master = global_master-10-100-20-80-0
    slave = global_slave-10-100-20-80-1
    slave-source = partition_rep1
    slave-source = partition_rep2
    user = worker
    password = woker_password
一​般​而​言​,在​实​际​的​线​上​环​境​中​单​独​使​用​ server data-source 的​情​况​比​较​少​见​,大​多​数​情​况​下​我​们​推​荐​使​用​ replication data-source。​replication data-source 提​供​了​数​据​热​备​、​故​障​切​换​高​可​用​、​负​载​均​衡​等​实​用​功​能​可​以​很​大​程​度​上​提​高​线​上​业​务​的​可​靠​性​与​性​能​。​
replication data-source 可​以​通​过​ slave-source 选​项​级​联​其​他​的​ data-source,包​括​ replication data-source。​通​过​ slave-source 选​项​级​联​别​的​ replication data-source 的​方​式​,可​以​搭​建​ 2 级​甚​至​多​级​复​制​的​复​杂​集​群​,并​且​ replication data-source 会​在​集​群​出​现​故​障​的​时​候​自​动​调​整​多​级​复​制​集​群​的​复​制​关​系​,保​持​集​群​的​可​用​性​。​
注​意​,slave-source 不​参​与​读​负​载​均​衡​。​
除​ replication data-source 外​,load-balance data-source 也​常​被​用​到​。​如​上​面​的​示​例​,DBScale 的​登​录​验​证​ source (通​过​选​项​ authenticate-source 指​定​)通​常​也​被​配​置​成​一​个​ load-balance data-source。​另​外​,load-balance data-source 也​常​被​用​来​配​置​一​组​只​读​的​数​据​库​实​例​提​供​高​效​的​历​史​信​息​查​询​等​。​

3.3.6. partition-scheme section

partition-scheme section 定​义​了​一​组​分​片​ data-server 以​及​相​应​的​分​区​方​式​。​例​如​,对​于​一​张​分​区​表​,它​的​数​据​实​际​分​布​在​ 3 个​不​同​的​数​据​源​中​,那​么​每​个​数​据​源​就​是​一​个​分​片​,分​区​的​方​式​为​ hash 。​分​片​的​数​据​源​通​过​选​项​ partition 来​指​定​。​
DBScale所​支​持​的​partition-scheme的​策​略​类​型​主​要​有​4类​:hash,list,range, mod;由​选​项​ type 来​给​出​。​四​种​类​型​的​ partition-scheme 的​选​项​有​所​不​同​,下​面​是​它​们​公​共​的​选​项​:
  • type [partition-scheme]
    Option-File Format type=#
    Type string
    Multiple N
    Range hash,range,list,mod
    Description partition-scheme 的​分​区​方​式​。​

3.3.6.1. hash 分​区​

hash 分​区​指​分​区​方​式​是​基​于​hash算​法​来​实​现​的​。​这​里​使​用​的​是​字​符​串​ hash 算​法​,DBScale 将​分​区​列​的​字​符​串​值​通​过​字​符​串​ hash 算​法​转​成​一​个​整​数​,然​后​对​该​整​数​按​照​分​片​数​取​模​,最​终​得​出​分​区​表​的​某​一​个​行​应​该​分​布​在​哪​一​个​分​片​。​
  • hash-method [partition-scheme.hash]
    Option-File Format hash-method=#
    Type string
    Single Y
    Range CHAR, DJB, DEK, SDB, BKDR, ELF, PJW, RS, AP
    Description partition-scheme 所​使​用​的​具​体​ hash 算​法​,默​认​为​ BasicChar 算​法​。​
  • partition [partition-scheme.hash]
    Option-File Format partition=#
    Type string
    Multiple Y
    Range 配​置​文​件​中​ data-source 的​实​例​名​
    Description partition-scheme 所​关​联​的​分​片​ data source。​
  • shard-nums [partition-scheme.hash]
    Option-File Format shard-nums=#
    Type int
    Multiple N
    Default 3
    Range >1
    Description partition-scheme hash 类​型​的​shard分​片​的​总​数​。​
    该​参​数​只​有​在​ is-shard 为​1的​时​候​才​生​效​。​且​对​应​的​shard分​片​表​一​旦​创​建​,就​不​允​许​修​改​该​值​,否​则​可​能​出​现​数​据​混​乱​!
  • is-shard [partition-scheme.hash]
    Option-File Format is-shard=#
    Type int
    Multiple N
    Default 1
    Range 0,1
    Description partition-scheme 是​否​是​shard partition,即​是​否​允​许​在​同​一​个​mysql实​例​内​部​部​署​多​个​分​片​。​
  • virtual-weight [partition-scheme.hash]
    Option-File Format virtual-weight=#
    Type string
    Multiple N
    Range 按​分​片​数​目​配​置​比​例​
    Description partition-scheme 所​关​联​的​分​片​的​数​据​比​例​,如​有​三​个​分​片​,按​顺​序​分​别​为​ p1, p2, p3.如​果​三​台​机​器​的​性​能​比​例​为​ p1:p2:p3 = 1:2:3, 可​以​配​置​ virtual-weight = 1:2:3, 这​样​三​台​机​器​会​按​照​这​个​比​例​来​分​配​数​据​。​
如​果​该​分​片​表​的​partition-scheme配​置​了​is-shard=1,那​么​该​参​数​将​被​忽​略​。​

3.3.6.2. range 分​区​

range 分​区​指​分​区​方​式​是​基​于​range算​法​来​实​现​的​。​每​个​partition都​有​一​个​range取​值​范​围​。​
  • function [partition-scheme.range]
    Option-File Format function=#
    Type string
    Single Y
    Range get_int, get_month, get_year, get_year_month, get_date
    Description partition-scheme 使​用​的​ range 取​值​方​法​,默​认​为​ get_int,即​取​整​型​值​,同​时​提​供​对​时​间​值​的​几​种​取​值​方​法​。​
  • partition [partition-scheme.range]
    Option-File Format partition=#1 LESS THAN #2
    Type string,int
    Multiple Y
    Range #1为​配​置​文​件​中​ data-source 的​实​例​名​,#2为​整​数​或​ MAXVALUE。​
    Description partition-scheme 所​关​联​的​分​片​ data source。​并​且​配​置​了​这​个​分​片​的​range上​限​。​
    range 分​区​的​配​置​是​递​进​式​的​,后​一​个​分​区​的​ range 上​限​必​须​大​于​前​一​个​。​并​且​目​前​ range 只​支​持​整​数​或​关​键​字​ MAXVALUE 作​为​ range 的​上​限​。​

3.3.6.3. list 分​区​

list 分​区​指​分​区​方​式​是​基​于​ list 算​法​来​实​现​的​。​每​个​partition都​有​一​个​list来​确​定​取​值​范​围​。​
  • partition [partition-scheme.list]
    Option-File Format partition=#1 VALUES IN (#2[,#2]*)
    Type string,int
    Multiple Y
    Range #1为​配​置​文​件​中​ data-source 的​实​例​名​,#2为​整​数​。​
    Description partition-scheme 所​关​联​的​分​片​ data source。​并​且​配​置​了​这​个​分​片​所​允​许​的​取​值​范​围​。​
    List分​区​每​个​分​区​的​取​值​范​围​通​过​“​,”​分​割​,取​值​范​围​不​允​许​有​交​集​。​

3.3.6.4. mod 分​区​

Mod 分​区​指​分​区​方​式​是​基​于​ module 算​法​来​实​现​的​。​每​个​partition分​区​根​据​数​值​四​舍​五​入​取​整​的​值​,对​分​区​数​进​行​取​模​运​算​得​到​的​值​进​行​分​区​。​
  • simple-mod [partition-scheme.mod]
    Option-File Format simple-mod=#
    Type int
    Single Y
    Range 0, 1
    Description mod 分​区​方​法​是​否​使​用​simple-mod,默​认​为​1, 即​使​用​ simple-mod, 此​时​,仅​支​持​正​整​形​数​据​的​ mod 分​区​。​当​输​入​为​负​数​时​,会​提​示​用​户​错​误​信​息​(Only support positive integer for simple-mod),当​输​入​为​小​数​时​,可​能​导​致​数​据​的​发​往​异​常​的​分​区​。​
  • partition [partition-scheme.mod]
    Mod 分​区​的​配​置​和​ hash 分​区​相​同​。​
  • shard-nums [partition-scheme.mod]
    Option-File Format shard-nums=#
    Type int
    Multiple N
    Default 3
    Range >1
    Description partition-scheme mod 类​型​的​ shard 分​片​的​总​数​。​
    该​参​数​只​有​在​ is-shard 为​1的​时​候​才​生​效​。​且​对​应​的​shard分​片​表​一​旦​创​建​,就​不​允​许​修​改​该​值​,否​则​可​能​出​现​数​据​混​乱​!
  • is-shard [partition-scheme.mod]
    Option-File Format is-shard=#
    Type int
    Multiple N
    Default 1
    Range 0, 1
    Description partition-scheme 是​否​是​shard partition,即​是​否​允​许​在​同​一​个​mysql实​例​内​部​部​署​多​个​分​片​。​
  • virtual-weight [partition-scheme.mod]
    Option-File Format virtual-weight=#
    Type string
    Multiple N
    Range 按​分​片​数​目​配​置​比​例​
    Description partition-scheme 所​关​联​的​分​片​的​数​据​比​例​,如​有​三​个​分​片​,按​顺​序​分​别​为​ p1, p2, p3.如​果​三​台​机​器​的​性​能​比​例​为​ p1:p2:p3 = 1:2:3, 可​以​配​置​ virtual-weight = 1:2:3, 这​样​三​台​机​器​会​按​照​这​个​比​例​来​分​配​数​据​。​
如​果​该​分​片​表​的​partition-scheme配​置​了​is-shard=1,那​么​该​参​数​将​被​忽​略​。​

3.3.6.5. partition-scheme配​置​示​例​

如​下​是​一​个​分​区​表​的​ partition-scheme 的​示​例​,该​分​区​表​有​ 2 片​数​据​:
[data-source partition_rep1]
type = replication
master = par_master1-10-100-20-80
slave = par_slave1-10-100-20-80
[data-source partition_rep2]
type = replication
master = par_master2-10-100-20-80
slave = par_slave2-10-100-20-80
[partition-scheme part-hash]
type=hash
virtual-weight = 2:1
partition = partition_rep1
partition = partition_rep2
[partition-scheme part-range]
type=range
partition = partition-rep1 LESS THAN 50
partition = partition-rep2 LESS THAN MAXVALUE
[partition-scheme part-list]
type=list
partition = partition-rep1 VALUES IN (1,2,3)
partition = partition-rep2 VALUES IN (5,8,9)
[partition-scheme part-mod]
type=mod
virtual-weight = 2:1
partition = partition_rep1
partition = partition_rep2

3.3.7. catalog section

catalog section 是​定​义​了​ DBScale 集​群​ catalog 数​据​空​间​相​关​的​选​项​。​DBScale 集​群​只​允​许​定​义​一​个​ catalog 数​据​空​间​。​
所​谓​的​ catalog 数​据​空​间​就​是​指​全​局​数​据​空​间​或​默​认​数​据​空​间​,它​对​应​的​是​整​个​数​据​库​集​群​,凡​是​找​不​到​更​具​体​数​据​空​间​的​请​求​都​会​被​转​到​ catalog 数​据​空​间​。​
  • data-source [catalog]
    Option-File Format data-source=#
    Type string
    Multiple N
    Range 配​置​文​件​中​ data-source 的​实​例​名​
    Description catalog 数​据​空​间​所​关​联​的​ data source。​
catalog section 配​置​示​例​如​下​:
[catalog def]
data-source = single

3.3.8. schema section

schema section 定​义​了​ DBScale schema 数​据​空​间​相​关​的​选​项​。​DBScale 允​许​配​置​多​个​不​同​实​例​名​ schema section 实​例​。​
schema 数​据​空​间​对​应​数​据​库​中​的​ schema,schema section 的​实​例​名​就​是​它​所​对​应​的​数​据​库​ schema 的​名​字​。​schema 数​据​空​间​是​对​应​数​据​库​ schema 的​默​认​数​据​空​间​,该​ schema 中​所​有​没​有​找​到​更​细​的​表​数​据​空​间​的​ SQL 请​求​都​会​被​转​到​该​ schema 数​据​空​间​中​。​
DBScale 会​保​留​几​个​ schema 的​名​字​作​为​内​部​使​用​,它​们​是​ dbscale, dbscale_tmp, dbscale_replication, mysql,这​几​个​ schema 名​字​不​能​够​出​现​在​配​置​文​件​的​ schema 配​置​项​下​,否​则​会​导​致​ DBScale 启​动​失​败​或​者​ DBScale 运​行​时​行​为​异​常​。​
  • data-source [schema]
    Option-File Format data-source=#
    Type string
    Multiple N
    Range 配​置​文​件​中​ data-source 的​实​例​名​
    Description schema 数​据​空​间​所​关​联​的​ data source。​
  • independence [schema]
    Option-File Format independence=#
    Type int
    Multiple N
    Default 1
    Range 0,1
    Description 该​数​据​空​间​是​否​完​整​包​含​了​它​的​父​数​据​空​间​的​数​据​。​
    当​ independence 为​ 0 时​表​示​该​数​据​空​间​完​整​地​包​含​它​父​数​据​空​间​中​的​数​据​,反​之​ 1 为​不​包​含​。​该​参​数​主​要​用​于​执​行​计​划​生​成​,用​于​判​断​ SQL 语​句​是​否​可​以​发​送​到​一​台​数​据​库​实​例​执​行​。​DBScale同​时​也​会​根​据​配​置​文​件​所​配​置​的​主​从​关​系​中​更​新​该​选​项​的​值​。​
  • pushdown-stored-procedure [schema]
    Option-File Format pushdown-stored-procedure=#
    Type int
    Multiple N
    Default 0
    Range 0,1, 2
    Description 如​果​设​置​为​1,那​么​在​执​行​该​数​据​空​间​内​的​存​储​过​程​时​,DBScale 将​不​会​对​该​存​储​过​程​调​用​做​任​何​特​殊​处​理​,而​是​将​该​存​储​过​程​调​用​直​接​下​推​到​其​所​配​置​的​数​据​空​间​上​。​如​果​设​置​为​0, 那​么​存​储​过​程​的​执​行​将​在​dbscale层​进​行​,如​果​设​置​成​2, 那​么​dbscale会​判​断​当​前​schema是​否​有​额​外​配​置​的​table dataspace,如​果​没​有​就​直​接​下​推​。​
schema section 配​置​如​下​:
[schema]
data-source = simple_rep

3.3.9. table section

table section 定​义​了​ DBScale table 数​据​空​间​相​关​的​选​项​。​ DBScale 允​许​配​置​多​个​不​同​实​例​名​ table section 实​例​。​
table 数​据​空​间​对​应​数​据​库​中​的​ table,table section 的​实​例​名​就​是​它​所​对​应​的​数​据​库​ table 的​名​字​,该​实​例​名​包​含​ 2 部​分​,schema 名​和​ table 名​,中​间​用​ “​.”​ 隔​开​,如​ “​test.t1”​。​
DBScale 的​ table 主​要​有​ 2 类​:普​通​ table 和​分​区​ table,由​选​项​ type 给​出​。​两​种​类​型​的​ table 的​选​项​有​所​不​同​,下​面​是​它​们​公​共​的​选​项​:
  • independence [table]
    同​ independence [schema]。​
  • pattern
    Option-File Format pattern=#
    Type string
    Multiple N
    Range 正​则​表​达​式​
    Description 表​名​的​正​则​表​达​式​。​
    DBScale 支​持​表​名​的​正​则​表​达​式​匹​配​,正​则​表​达​式​由​ pattern 选​项​指​定​。​如​果​ pattern 选​项​有​值​的​话​,DBScale 就​不​会​把​该​ table section 的​实​例​名​中​ table 名​的​部​分​当​做​表​名​,而​是​将​数​据​空​间​设​置​为​ schema 中​所​有​表​名​满​足​该​正​则​表​达​式​的​表​。​但​需​要​注​意​的​是​,即​便​使​用​了​ pattern,table section 的​实​例​名​也​必​须​给​出​完​整​的​ schema 名​。​
    限​制​: pattern 表​的​配​置​表​名​要​与​ pattern 有​区​分​,否​则​无​法​进​行​迁​移​, 示​例​如​下​。​
    [table test.t1]
    type=partition
    pattern = t.*
    partition-scheme = part
    partition-key = c1
    mysql> DBSCALE MIGRATE PARTITION t1 1 TO p3s 2 TO p3s;
    ERROR 9001 (): migrate failed, please check log.
    
    mysql> DBSCALE MIGRATE PARTITION t2 1 TO p3s 2 TO p3s;
    Query OK, 0 rows affected (2 min 55.03 sec)
    
    迁移t1失败原因是因为t1是pattern表, 且表名t1与pattern表的配置表名test.t1重复, 所以无法迁移.
    如果要对t1表进行迁移, 建议配置pattern表如下:
    [table test.pattern_t]
    type=partition
    pattern = t.*
    partition-scheme = part
    partition-key = c1
    
  • type [table]
    Option-File Format type=#
    Type string
    Multiple N
    Range normal,partition
    Description 表​类​型​

3.3.9.1. normal table

normal table 指​的​是​非​分​区​表​,即​该​表​的​所​有​数​据​都​位​于​一​台​数​据​库​实​例​的​一​张​表​中​。​
  • data-source [table.normal]
    Option-File Format data-source=#
    Type string
    Multiple N
    Range 配​置​文​件​中​ data-source 的​实​例​名​
    Description Normal table 数​据​空​间​所​关​联​的​ data source。​

3.3.9.2. partition table

partition table 指​的​是​分​区​表​,即​该​表​的​数​据​是​分​布​式​分​布​,由​数​个​分​片​组​成​。​
partition table 的​选​项​主​要​定​义​了​分​区​表​的​分​区​方​式​,所​涉​及​的​分​片​数​据​源​:
  • partition-key
    Option-File Format partition-key=#
    Type string
    Multiple N
    Description Partition table 的​分​区​字​段​名​。​
    分​区​字​段​的​选​择​需​要​考​虑​分​区​类​型​ partition-type;例​如​,如​果​分​区​类​型​为​ hash 的​话​,应​该​选​数​据​离​散​度​较​高​的​字​段​作​为​分​区​字​段​。​
    另​外​分​区​字​段​的​选​择​还​需​要​考​虑​业​务​,如​果​分​区​字​段​能​较​多​地​出​现​在​业​务​ SQL 语​句​的​ WHERE 条​件​中​并​作​为​ AND 等​值​条​件​,那​么​就​能​有​效​地​缩​小​该​业​务​ SQL 需​要​扫​描​的​数​据​量​,例​如​每​条​业​务​ SQL 只​需​要​访​问​ parition 表​的​一​个​分​片​。​
  • partition-scheme
    Option-File Format partition-scheme=#
    Type string
    Multiple N
    Range 配​置​文​件​中​ partition-scheme 的​实​例​名​
    Description Partition table 的​ partition-scheme,其​中​包​含​了​该​分​区​表​的​所​有​分​片​数​据​源​。​
    不​同​的​分​区​表​可​以​共​享​一​个​ partition-scheme。​
  • virtual-times
    Option-File Format virtual-times=#
    Type int
    Multiple N
    Range >= 1
    Default Value 4
    Description 分​片​表​虚​拟​分​区​对​实​际​分​区​的​倍​数​。​
    该​参​数​只​对​ Hash 和​ Mod 分​区​的​分​片​表​起​作​用​,并​且​ DBScale 将​自​动​忽​略​小​于​1的​值​。​
  • virtual-map
    Option-File Format virtual-map=#
    Type string
    Multiple Y
    Default 默​认​情​况​下​,虚​拟​分​片​依​次​分​布​在​各​个​分​片​上​,如​有​两​个​实​际​分​片​,4个​虚​拟​分​片​,则​实​际​分​片​零​上​有​虚​拟​分​片​零​和​二​,实​际​分​片​一​上​有​虚​拟​分​片​一​和​三​。​
    Range 配​置​所​有​虚​拟​分​片​,且​不​重​复​。​
    Description 分​片​表​实​际​虚​拟​分​片​拓​扑​关​系​。​
    该​参​数​只​对​ Hash 和​ Mod 分​区​的​分​片​表​起​作​用​, 要​求​ virtual-map 数​目​同​分​片​数​目​相​同​,要​求​为​所​有​虚​拟​分​片​指​定​数​据​源​,同​时​虚​拟​分​片​ id 不​能​重​复​,总​的​虚​拟​分​片​数​目​应​该​等​于​ virtual-times * parition_num。​在​迁​移​分​区​表​时​,如​果​迁​移​成​功​,会​在​日​志​中​以​INFO级​别​给​出​迁​移​后​的​ virtual-map。​也​可​以​使​用​命​令​:"DBSCALE SHOW PARTITION TABLE table_name VIRTUAL MAP" 来​查​询​当​前​分​区​表​的​ virtual-map 配​置​。​ 对​于​四​分​片​表​,virtual-times = 4, 示​例​如​下​:
                    virtual-map = par1:0:4:8:12
                    virtual-map = par2:2:5:9:13
                    virtual-map = par3:6:10:14
                    virtual-map = par4:3:7:11:15:1
    

3.3.9.3. table section 配​置​示​例​

  • 非​分​区​表​
    [table test.t1]
    type = normal
    data-source = single
  • 非​分​区​表​正​则​表​达​式​
    [table test.my_tables]
    type = normal
    data-source = single
    pattern = my_.*
  • 分​区​表​
    [table test.part_table]
    type = partition
    partition-scheme = part
    partition-key = c1
  • 分​区​表​正​则​表​达​式​
    [table test.part_tables]
    type = partition
    pattern = part_.*
    partition-scheme = part
    partition-key = c1

3.3.10. read-only-procedure section

read-only-procedure section 包​含​一​个​配​置​选​项​ procedure-name。​如​果​用​户​确​认​某​个​存​储​过​程​只​包​含​读​操​作​,可​将​其​以​ procedure-name = db_name.procedure_name 的​形​式​在​ read-only-procedure section 下​列​出​,未​列​出​的​存​储​过​程​将​被​ DBScale 视​为​包​含​写​操​作​。​包​含​写​操​作​的​存​储​过​程​在​被​调​用​时​,如​果​后​端​是​读​写​分​离​的​ data-source,该​存​储​过​程​的​调​用​将​被​发​往​ master,否​则​发​往​ slave。​
  • procedure-name
    Option-File Format procedure-name=#
    Type string
    Multiple Y
    Default Value 无​
    Description 含​有​写​操​作​的​存​储​过​程​名​字​。​
read-only-procedure section 示​例​如​下​:
[read-only-procedure]
procedure-name = db1.proc1
procedure-name = db2.proc1
procedure-name = db2.proc2

3.4. 完​整​配​置​文​件​示​例​

本​节​将​给​出​一​个​完​整​的​配​置​文​件​示​例​。​该​示​例​包​含​了​ DBScale 的​ 3 种​数​据​分​布​式​部​署​方​式​:库​级​别​分​布​式​部​署​、​表​级​别​分​布​式​部​署​和​表​ sharding 部​署​;同​时​该​实​例​还​给​出​了​全​局​表​的​配​置​方​式​。​

3.4.1. 配​置​需​求​描​述​与​分​析​

DBScale 需​要​管​理​ 2 个​数​据​库​,库​名​分​别​为​ db1 和​ db2。​
db1 库​中​包​含​了​ 2 类​表​。​第​一​类​为​日​累​积​汇​总​表​,table_work_yyyymmdd 和​ table_task_yyyymmdd;该​类​型​的​表​一​天​一​张​新​表​,表​名​中​包​含​创​建​的​日​期​,单​表​数​据​量​很​大​。​第​二​类​为​普​通​数​据​表​,table_info、​table_price 和​ table_trade;该​类​型​的​表​数​量​固​定​,表​规​模​不​大​,增​量​可​控​。​
db2 库​规​模​较​小​,数​据​增​量​也​不​大​,但​应​用​的​业​务​ SQL 需​要​将​ db1 中​的​日​累​积​汇​总​表​与​ db2 库​中​的​表​进​行​ join,由​于​现​在​ DBScale 只​支​持​本​地​ join,所​以​ db2 库​中​的​表​需​要​以​全​局​表​的​形​式​部​署​到​所​有​ db1 库​的​物​理​机​器​上​。​
由​于​ db1 库​的​数​据​量​和​日​增​量​都​很​大​,所​以​我​们​需​要​对​它​进​行​分​布​式​部​署​。​分​布​式​部​署​包​含​了​表​级​别​的​分​布​式​部​署​,把​表​分​布​到​不​同​的​物​理​机​器​上​;以​及​单​表​ sharding,把​单​表​数​据​量​很​大​的​日​累​积​汇​总​表​ sharding 到​不​同​的​物​理​机​器​上​。​
所​有​的​数​据​都​需​要​有​ 1 份​备​份​,集​群​不​能​有​单​点​。​
配​置​集​群​可​以​使​用​的​物​理​机​器​有​ 6 台​,它​们​的​ IP 为​:
      192.168.192.110
      192.168.192.111
      192.168.192.112
      192.168.192.113
      192.168.192.114
      192.168.192.115
192.168.192.110 机​器​上​安​装​了​两​个​ MySQL 实​例​和​ 1 个​ DBScale 实​例​,MySQL 实​例​的​端​口​为​3307, 3308,DBScale 端​口​为​ 3306。​
192.168.192.111 机​器​上​安​装​了​两​个​ MySQL 实​例​和​ 1 个​ DBScale 实​例​,MySQL 实​例​的​端​口​为​3307, 3308,DBScale 端​口​为​ 3306。​
以​上​ 2 台​机​器​的​ DBScale 通​过​ HA 软​件​ GreatTurbo HA 进​行​高​可​用​;每​两​个​ MySQL 实​例​配​成​主​从​复​制​,端​口​为​ 3307 的​ MySQL 为​ master,端​口​为​的​ MySQL 为​ slave, 交​叉​复​制​。​
剩​下​的​ 4 台​机​器​每​台​安​装​两​个​ MySQL 实​例​,端​口​分​别​为​ 3307 和​ 3308:
      113 机器 3308 端口的 MySQL 为 112 机器 3307 端口 MySQL 的 slave;
      114 机器 3308 端口的 MySQL 为 113 机器 3307 端口 MySQL 的 slave;
      依次类推,
      最后 112 机器 3308 端口的 MySQL 为 115 机器 3307 端口 MySQL 的slave;
另​外​ 112 到​ 115 机​器​的​ 3307 端​口​ MySQL 都​从​ 110 机​器​ 3307 端​口​的​ MySQL 进​行​主​从​复​制​。​
db1 和​ db2 的​数​据​分​布​如​下​:
数​据​库​ 数​据​表​ MySQL 实​例​
db2 所​有​表​ 110 机​器​的​ MySQL 实​例​,备​份​为​ 111 机​器​的​ MySQL 实​例​。​同​时​通​过​主​从​复​制​同​步​到​所​有​其​他​ MySQL 实​例​。​
db1 table_info 112 机​器​ 3307 端​口​的​ MySQL 实​例​,备​份​为​ 113 机​器​ 3308 端​口​的​ MySQL 实​例​。​
db1 table_price 113 机​器​ 3307 端​口​的​ MySQL 实​例​,备​份​为​ 114 机​器​ 3308 端​口​的​ MySQL 实​例​。​
db1 table_trade 114 机​器​ 3307 端​口​的​ MySQL 实​例​,备​份​为​ 115 机​器​ 3308 端​口​的​ MySQL 实​例​。​
db1 table_work_yyyymmdd 以​分​区​表​的​形​式​ sharding 在​ 112 到​ 115 机​器​ 3307 端​口​的​ MySQL 实​例​,备​份​为​ 112 到​ 115 机​器​ 3308 端​口​的​ MySQL 实​例​。​
db1 table_task_yyyymmdd 以​分​区​表​的​形​式​ sharding 在​ 112 到​ 115 机​器​ 3307 端​口​的​ MySQL 实​例​,备​份​为​ 112 到​ 115 机​器​ 3308 端​口​的​ MySQL 实​例​。​
db1 和​ db2 的​用​户​与​权​限​如​下​:
用​户​名​ 密​码​ 权​限​
dbscale dbscale 全​部​权​限​
db1_user db1_password db1 库​的​全​部​权​限​
db2_user db2_password db2 库​的​全​部​权​限​

3.4.2. 配​置​文​件​示​例​

dbscale.conf配​置​文​件​示​例​

3.4.2.1. 主​配​置​文​件​

[main]
# 配置认证数据源
authenticate-source = auth

# 配置用于创建管理连接的数据库用户名密码,该用户名密码需要事先在MySQL中配置
admin-user = dbscale
admin-password = dbscale
driver = mysql

# 配置日志级别,如果处于调试阶段,可以先配置为DEBUG,该模式会打印更多的信息
log-level = INFO
log-file = dbscale.log

# 使用GTID复制,注意后端的MySQL版本要>=5.6.12,并且开启GTID
support-gtid = 1

# include data-source的配置,即DBScale对后端物理实例的组织和管理,详见“数据源配置文件”。
include-file = ./conf/sources.conf

# include data-server的配置,即后端MySQL实例集群的物理描述,详见“数据server配置文件”。
include-file = ./conf/servers.conf




# driver section的实例名称为mysql,该值与main中driver选项的取值一致
[driver mysql]
type = MySQLDriver
# 绑定为0.0.0.0可以在该机器的所有IP上进行监听
bind-address = 0.0.0.0
# DBScle对外提供服务的端口
port = 3306




# catalog section必须配置且只能配置一个
[catalog def]
# catalog 数据空间的请求将从 def_source中取连接进行响应
# def_source以及其他数据空间关联的data_source都在“数据源配置文件”中定义
data-source = def_source



# schema section可以配置多个,它们的实例名全局唯一并且与后端数据库中的schema名字一致
[schema db1]
# schema db1的请求如果没有更具体的table section匹配的话,将会从
# db1_def_source中取连接进行响应
data-source = db1_115source



# table section可以配置多个,它们的实例名全局唯一并且必须在实例名中指明所隶属的schema名
[table db1.table_info]
type = normal
# table db1.table_info的请求将会从 db1_112source中取连接响应
data-source = db1_112source



[table db1.table_price]
type = normal
data-source = db1_113source



[table db1.table_trade]
type = normal
data-source = db1_114source



[table db1.table_work_xxx]
# partition表示这是一张分区表,它的分区列信息由partition-key给出,
# 分区规划由partition-scheme给出
type = partition
# 当table section中使用pattern参数时,该table
# section将匹配一组表名,表名的匹配由pattern指定的正则表达式确定
# 这里匹配所有db1库中以table_work_为前缀的表
pattern = table_work_.*
partition-scheme = part
# 分区列
partition-key = work_id



[table db1.table_task_xxx]
type = partition
pattern = table_task_.*
partition-scheme = part
partition-key = task_id

3.4.2.2. 数​据​源​配​置​文​件​

./conf/sources.conf配​置​文​件​示​例​
# 每个数据源都是一个data-source section,它们的以各自的实例名在配置文件中
# 被其他配置引用,如数据空间

# auth为该数据源的实例名
[data-source auth]
type = replication
# replication是最常用的数据源类型,它会自动维护后端主从复制集群的复制拓扑
# db_auth1和db_auth2为data-server的实例名,它们定义在“数据server文件”中。
master = db_auth1-10-100-20-80
# 10-100-20-80为该data-server在这个数据源中的连接池配置,它们分别为最小值、最大值、低阀值、高阀值
slave = db_auth2-10-100-20-80
# 数据源中配置的用户名和密码一般是业务用户名和密码,即业务程序使用的
user = dbscale
password = dbscale



[data-source db1_112source]
type = replication
master = db1_112_master-10-100-20-80
slave = db1_112_slave-10-100-20-80
user = db1_user
password = db1_password
# 这里配置为所有读写请求都发往Master的工作模式
load-balance-strategy = MASTER



[data-source db1_113source]
type = replication
master = db1_113_master-10-100-20-80
slave = db1_113_slave-10-100-20-80
user = db1_user
password = db1_password
load-balance-strategy = MASTER



[data-source db1_114source]
type = replication
master = db1_114_master-10-100-20-80
slave = db1_114_slave-10-100-20-80
user = db1_user
password = db1_password
load-balance-strategy = MASTER



[data-source db1_115source]
type = replication
master = db1_115_master-10-100-20-80
slave = db1_115_slave-10-100-20-80
user = db1_user
password = db1_password
load-balance-strategy = MASTER



# 配置分区规划,它主要用于分区表的配置
[partition-scheme part]
# 分区方式为HASH
type = hash
# 这里给出了这个分区规划所涉及到的每个分片的数据源
partition = db1_112source
partition = db1_113source
partition = db1_114source
partition = db1_115source



# 两级复制的replication示例
[data-source def_source]
type = replication
master = db2_master-10-100-20-80
slave = db2_slave-10-100-20-80
# 使用两级复制,将db2库中的数据同步到所有db1的数据源上
slave-source = db1_112source
slave-source = db1_113source
slave-source = db1_114source
slave-source = db1_115source
load-balance-strategy = MASTER

3.4.2.3. 数​据​server配​置​文​件​

./conf/servers.conf配​置​文​件​示​例​
# 本文件列出了集群中所有MySQL实例的物理描述
[data-server db2_master]
host = 192.168.192.110
port = 3307
user = dbscale
password = dbscale


[data-server db2_slave]
host = 192.168.192.111
port = 3308
user = dbscale
password = dbscale


[data-server db1_112_master]
host = 192.168.192.112
port = 3307
user = dbscale
password = dbscale


[data-server db1_112_slave]
host = 192.168.192.113
port = 3308
user = dbscale
password = dbscale


[data-server db1_113_master]
host = 192.168.192.113
port = 3307
user = dbscale
password = dbscale


[data-server db1_113_slave]
host = 192.168.192.114
port = 3308
user = dbscale
password = dbscale


[data-server db1_114_master]
host = 192.168.192.114
port = 3307
user = dbscale
password = dbscale


[data-server db1_114_slave]
host = 192.168.192.115
port = 3308
user = dbscale
password = dbscale


[data-server db1_115_master]
host = 192.168.192.115
port = 3307
user = dbscale
password = dbscale


[data-server db1_115_slave]
host = 192.168.192.112
port = 3308
user = dbscale
password = dbscale


[data-server db_auth1]
host = 192.168.192.111
port = 3307
user = dbscale
password = dbscale


[data-server db_auth2]
host = 192.168.192.110
port = 3308
user = dbscale
password = dbscale

第 4 章 性​能​调​优​

4.1. 会​话​/语​句​内​存​相​关​配​置​

DBScale中​为​每​个​会​话​/语​句​级​别​进​行​内​存​分​配​的​参​数​主​要​有​如​下​,通​常​适​当​调​大​这​些​参​数​可​以​提​高​语​句​执​行​性​能​,但​设​置​过​大​的​话​可​能​会​导​致​DBScale发​生​OOM:
  1. pre-alloc-memory,参​考​参​数​pre-alloc-memory。​
  2. alloc-memory-increase,参​考​参​数​alloc-memory-increase。​
  3. net-buffer-size,参​考​参​数​net-buffer-size。​
  4. max-rowmap-size,参​考​参​数​max-rowmap-size。​
  5. sort-rows-size,参​考​参​数​sort-rows-size。​
  6. max-fetchnode-ready-rows-size,参​考​参​数​max-fetchnode-ready-rows-size。​
  7. max-mergenode-ready-rows-size,参​考​参​数​max-mergenode-ready-rows-size。​
  8. max-single-sort-rows,参​考​参​数​max-single-sort-rows。​
  9. max-fetch-node-threads,参​考​参​数​max-fetch-node-threads。​
  10. row-packet-size,参​考​参​数​row-packet-size。​

4.2. 数​据​导​入​/插​入​相​关​配​置​

DBScale支​持​load data相​关​语​句​和​insert...select相​关​语​句​,并​提​供​了​如​下​性​能​调​优​相​关​参​数​,这​些​参​数​控​制​了​数​据​导​入​/插​入​过​程​使​用​的​线​程​数​或​最​大​数​据​缓​存​数​量​,通​常​适​度​调​大​这​些​参​数​,可​以​提​高​相​关​数​据​导​入​或​插​入​的​性​能​,但​过​大​的​话​可​能​会​导​致​DBScale使​用​过​多​操​作​系​统​资​源​而​不​可​用​,如​OOM,特​别​是​在​并​发​的​场​景​下​:
  1. load-analysis-num,参​考​参​数​load-analysis-num。​
  2. max-load-analysis-wait-size,参​考​参​数​max-load-analysis-wait-size。​
  3. max-load-ready-packets,参​考​参​数​max-load-ready-packets。​
  4. insert-select-sql-size,参​考​参​数​insert-select-sql-size。​
  5. use-load-data-for-insert-select,参​考​参​数​use-load-data-for-insert-select。​
  6. max-load-select-analysis-wait-size,参​考​参​数​max-load-select-analysis-wait-size。​

4.3. 自​增​表​性​能​调​优​的​相​关​配​置​

DBScale的​分​片​表​支​持​mysql的​自​增​表​,相​关​调​优​参​数​有​:
  1. auto-inc-lock-mode,参​考​参​数​auto-inc-lock-mode。​
  2. load-data-check-auto-inc,参​考​参​数​load-data-check-auto-inc。​
  3. load-data-auto-inc-local-capacity,参​考​参​数​load-data-auto-inc-local-capacity。​
对​于​分​片​表​而​言​,使​用​自​增​表​主​要​在​数​据​插​入​上​比​非​自​增​表​有​一​定​的​性​能​损​耗​,其​他​查​询​、​修​改​、​删​除​操​作​的​性​能​与​非​自​增​表​是​一​样​的​。​

4.4. 连​接​池​相​关​调​优​参​数​

DBScale到​后​端​mysql数​据​节​点​的​连​接​是​由​DBScale的​连​接​池​维​护​。​连​接​池​的​状​态​可​以​通​过​命​令​第 7.3.17 节 “查​看​连​接​池​状​态​”查​看​。​连​接​池​的​参​数​配​置​可​以​参​考​第 3.3.5.1 节 “server data-source”。​
对​于​连​接​池​的​初​始​值​,该​值​如​果​配​置​过​大​,可​能​会​显​著​延​长​DBScale的​启​动​时​间​,但​好​处​是​集​群​的​连​接​池​无​需​再​预​热​以​适​应​高​并​发​,建​议​在​压​测​场​景​下​配​置​一​个​较​大​的​初​始​值​。​
对​于​连​接​池​的​低​阀​值​,该​值​需​要​根​据​业​务​的​常​规​压​力​进​行​设​置​,低​于​低​阀​值​的​连​接​是​不​会​被​周​期​性​自​动​回​收​,如​果​该​值​配​置​的​过​低​,低​于​业​务​常​规​运​行​过​程​中​的​正​常​连​接​需​求​,可​能​会​导​致​频​繁​的​连​接​创​建​与​销​毁​,而​影​响​业​务​SQL响​应​时​间​。​空​闲​连​接​的​超​时​时​间​为​10s,只​有​超​时​的​连​接​才​会​被​后​台​线​程​回​收​,所​以​如​果​业​务​访​问​较​为​频​繁​,低​阀​值​配​置​的​较​低​的​性​能​影​响​也​不​会​太​大​。​
对​于​连​接​池​的​高​阀​值​,该​值​需​要​根​据​业​务​的​常​规​压​力​进​行​设​置​,高​于​高​阀​值​的​连​接​在​空​闲​的​时​候​会​立​刻​回​收​,如​果​该​值​配​置​的​过​低​,低​于​业​务​常​规​运​行​过​程​中​的​高​峰​连​接​需​求​,可​能​会​导​致​高​峰​时​期​频​繁​的​连​接​创​建​与​销​毁​,而​影​响​业​务​SQL响​应​时​间​。​由​于​高​于​高​阀​值​的​连​接​空​闲​时​是​立​刻​回​收​的​,所​以​高​阀​值​配​置​过​低​在​业​务​高​峰​时​会​对​SQL响​应​性​能​有​较​大​影​响​。​
对​于​最​大​值​,建​议​配​置​的​足​够​大​,以​应​对​某​些​极​端​场​景​,具​体​请​参​考​enable-session-swap-during-execution中​关​于​连​接​池​部​分​的​描​述​。​
另​外​,关​于​连​接​池​还​有​一​个​重​要​的​main参​数​conn-pool-num,该​参​数​是​一​个​重​要​的​性​能​参​数​,它​影​响​集​群​的​连​接​数​量​以​及​连​接​池​的​锁​粒​度​,具​体​请​参​考​conn-pool-num。​关​于​该​参​数​,最​重​要​的​一​点​是​,集​群​实​际​的​连​接​数​是​连​接​池​配​置​的​数​量​乘​以​conn-pool-num之​后​的​值​。​所​以​在​进​行​连​接​池​配​置​的​时​候​一​定​要​综​合​考​虑​conn-pool-num的​值​,否​则​很​容​易​触​发​后​端​mysql最​大​连​接​数​限​制​。​
假​设​某​个​业​务​正​常​情​况​下​的​并​发​压​力​大​约​在​70到​100并​发​左​右​,但​每​天​早​上​8点​高​峰​的​半​小​时​可​能​达​到​400到​500多​左​右​并​发​,假​设​这​些​并​发​都​会​从​数​据​源​test_source中​取​连​接​,如​下​是​示​例​的​配​置​:
[main]
...
conn-pool-num=10
...
[data-source simple_rep]
type = replication
master = global_master-2-100-12-60
slave = global_slave-2-100-12-60
user = worker
password = worker_password
这​个​数​据​源​到​后​端​每​个​server的​初​始​连​接​数​为​2*10个​连​接​,低​阀​值​为​12*10个​连​接​足​够​负​载​正​常​情​况​下​的​最​高​100左​右​的​并​发​,高​阀​值​为​10*60,足​够​覆​盖​高​峰​500的​并​发​请​求​,而​最​大​值​的​10*100个​为​安​全​上​限​。​
连​接​池​相​关​的​的​其​他​配​置​参​数​还​有​:
  1. connection-pool-manage-interval,参​考​参​数​connection-pool-manage-interval。​
  2. enable-session-swap-during-execution,参​考​参​数​enable-session-swap-during-execution。​
  3. flush-all-conn-in-group,参​考​参​数​flush-all-conn-in-group。​
连​接​池​的​上​限​是​可​以​动​态​调​整​的​,参​考​第 7.6.2 节 “重​置​资​源​池​最​大​资​源​数​”。​

4.5. 线​程​池​相​关​调​优​参​数​

DBScale内​部​有​2种​线​程​工​作​模​型​,以​及​3类​线​程​池​。​不​同​的​线​程​工​作​模​型​下​所​使​用​的​线​程​池​以​及​线​程​池​的​职​责​不​尽​相​同​。​
2个​线​程​工​作​模​型​为​基​于​多​线​程​的​"非​swap"模​型​和​基​于​异​步​IO的​"swap"模​型​。​3类​线​程​池​分​别​为​前​端​线​程​池​、​后​端​线​程​池​、​以​及​swap线​程​池​。​DBScale的​线​程​池​可​以​通​过​命​令​第 7.3.19 节 “查​看​线​程​池​状​态​”查​看​运​行​状​态​。​
非​swap的​模​式​比​较​试​用​于​低​并​发​的​场​景​,但​在​高​并​发​场​景​如​1024\2048并​发​则​性​能​可​能​会​大​幅​下​降​。​每​个​登​录​的​客​户​端​会​独​占​一​个​DBScale工​作​线​程​直​到​该​客​户​端​退​出​。​在​该​模​式​下​DBScale只​会​使​用​前​端​线​程​池​和​后​端​线​程​池​。​其​中​前​端​线​程​池​用​于​响​应​客​户​端​请​求​被​登​录​客​户​端​独​占​,后​端​线​程​池​用​于​协​助​处​理​分​片​表​的​数​据​操​作​请​求​。​该​模​式​下​如​果​登​录​线​程​池​配​置​的​过​小​可​能​导​致​客​户​端​无​法​登​录​DBScale。​
swap模​式​比​较​适​用​于​大​并​发​的​场​景​,在​小​并​发​如​32/64并​发​则​性​能​不​如​非​swap模​式​,但​在​高​并​发​如​1024/2048并​发​则​性​能​非​常​的​稳​定​且​高​效​。​在​该​模​式​下​会​同​时​使​用​前​端​线​程​池​、​swap线​程​池​、​以​及​后​端​线​程​池​。​其​中​前​端​线​程​池​用​于​响​应​客​户​端​登​录​;swap线​程​池​用​于​以​事​件​驱​动​的​模​式​响​应​客​户​端​的​SQL请​求​;后​端​线​程​池​用​于​协​助​分​片​表​的​数​据​操​作​请​求​。​swap模​式​下​只​会​对​简​单​SQL语​句​进​行​基​于​事​件​驱​动​的​调​度​模​式​,而​对​于​复​杂​语​句​,会​退​化​成​多​线​程​模​型​,即​一​个​客​户​端​独​占​一​个​工​作​线​程​。​
在​ swap 模​式​下​,不​会​进​行​ swap 的​语​句​类​型​如​下​:
存储过程,如 CALL PROCEDURE()。
跨结点 join 语句。
union 子查询。
CREATE 表, CREATE VIEW, ALTER 表。
所有 DBScale 管理语句。
以及一些其他 DBScale 会判定为复杂执行的语句,如一条语句中会涉及多个分片表的查询。
如​下​是​在​某​种​环​境​下​ xa 事​务​在​ swap 模​式​与​非​ swap 模​式​性​能​对​比​. 其​中​在​ swap 模​式​下​,在​线​程​数​目​较​少​时​,tps 较​低​,随​着​线​程​数​目​增​加​,cpu 使​用​并​未​显​著​改​变​,性​能​会​大​幅​度​提​升​。​非​ swap 模​式​下​,在​线​程​数​目​较​少​时​,tps 较​高​,随​着​线​程​数​目​增​加​,cpu 使​用​增​加​到​跑​满​,性​能​有​瓶​颈​。​
线​程​数​ swap 模​式​ 非​swap模​式​
64 2678.05 6847.67(cpu 2106)
128 4341.61 8879.21(cpu 4142)
256 8784.85 6032.00 (cpu 6121)
512 11077.96 4817.38 (cpu 5387 )
对​于​前​端​线​程​池​,相​关​配​置​有​最​小​值​、​最​大​值​、​低​阀​值​,参​考​参​数​thread-pool-min。​在​非​swap模​式​下​,需​要​根​据​业​务​实​际​的​并​发​数​设​置​低​阀​值​和​最​大​值​,否​则​可​能​会​导​致​频​繁​的​线​程​创​建​于​销​毁​以​及​客​户​端​无​法​登​录​。​在​swap模​式​下​,则​无​需​设​置​过​大​的​低​阀​值​,避​免​创​建​一​堆​空​闲​线​程​。​
如​下​是​一​个​对​于​swap模​式​的​示​例​配​置​:
[main]
...
thread-pool-min = 10
thread-pool-low = 30
thread-pool-max = 1024
...
对​于​后​端​线​程​池​,相​关​配​置​有​最​小​值​、​最​大​值​、​低​阀​值​,参​考​参​数​backend-thread-pool-min。​后​端​线​程​池​主​要​用​于​用​于​分​片​表​多​个​分​片​的​并​行​操​作​执​行​,如​跨​分​片​扫​描​、​跨​分​片​聚​集​、​跨​分​片​多​行​插​入​,所​以​它​的​低​阀​值​需​要​设​置​为​业​务​跨​分​片​操​作​的​常​规​并​发​数​*分​片​数​,而​最​大​值​需​要​设​置​为​业​务​跨​分​片​操​作​的​最​大​并​发​数​*分​片​数​。​另​外​和​连​接​池​类​似​,后​端​线​程​池​有​个​参​数​控​制​后​端​线​程​池​的​数​量​backend-thread-pool-num,实​际​的​后​端​线​程​数​为​配​置​数​*backend-thread-pool-num。​
如​下​是​一​个​示​例​配​置​:
[main]
...
backend-thread-pool-num=3
backend-thread-pool-min = 10
backend-thread-pool-low = 100
backend-thread-pool-max = 1024
...
对​于​swap线​程​池​,它​只​在​开​启​swap模​式​enable-session-swap的​情​况​下​起​作​用​。​相​关​配​置​有​最​小​值​、​最​大​值​、​低​阀​值​、​以​及​线​程​组​数​。​通​常​而​言​,低​阀​值​*线​程​组​数​的​值​为​DBScale用​于​事​件​驱​动​的​工​作​线​程​数​,一​般​配​置​为​机​器​可​用​CPU数​的​1倍​到​2倍​。​通​常​低​阀​值​都​是​配​置​为​2,通​过​调​整​线​程​组​数​来​配​置​用​于​事​件​驱​动​的​工​作​线​程​数​。​通​常​最​大​值​要​配​置​的​足​够​大​,对​于​复​杂​查​询​语​句​,即​便​在​swap模​式​下​,DBScale依​然​会​用​独​占​工​作​线​程​的​方​式​执​行​,这​时​候​swap线​程​池​会​自​动​进​行​调​整​,在​不​超​过​最​大​线​程​数​限​制​的​前​提​下​,补​齐​用​于​事​件​驱​动​的​工​作​线​程​数​。​
如​下​是​一​个​示​例​配​置​,假​设​机​器​的​CPU数​为​12核​:
[main]
...
handler-thread-pool-num=10
handler-thread-pool-min = 2
handler-thread-pool-low = 2
handler-thread-pool-max = 200
...
由​于​handler-thread-pool-num的​配​置​是​不​能​动​态​修​改​的​,所​以​建​议​DBA根​据​实​际​业​务​对​不​同​的​值​进​行​压​测​来​选​取​最​适​合​的​值​。​
线​程​池​相​关​的​的​其​他​配​置​参​数​还​有​:
  1. enable-session-swap,参​考​参​数​enable-session-swap。​
  2. enable-session-swap-during-execution,参​考​参​数​enable-session-swap-during-execution。​
  3. thread-pool-manage-interval,参​考​参​数​thread-pool-manage-interval。​
线​程​池​的​上​限​是​可​以​动​态​调​整​的​,参​考​第 7.6.2 节 “重​置​资​源​池​最​大​资​源​数​”。​

4.6. 表​池​相​关​调​优​参​数​

DBScale通​过​临​时​表​辅​助​进​行​跨​节​点​JOIN,通​过​使​用​表​池​进​行​临​时​表​的​复​用​以​提​高​JOIN性​能​。​
表​池​的​参​数​主​要​有​最​小​值​和​最​大​值​,可​以​参​考​参​数​table-pool-min。​通​常​建​议​使​用​默​认​值​,不​用​额​外​进​行​配​置​调​整​。​

4.7. 其​他​对​性​能​影​响​的​相​关​main配​置​

DBScale还​提​供​如​下​对​性​能​有​影​响​的​main配​置​,其​中​较​为​常​设​置​的​有​:
  1. log-level,DBScale支​持​不​同​的​日​志​级​别​,通​常​进​行​业​务​功​能​性​调​试​的​时​候​建​议​开​启​DEBUG日​志​级​别​以​便​于​问​题​定​位​,而​在​线​上​系​统​通​常​使​用​INFO日​志​级​别​,参​考​参​数​log-level。​该​参​数​可​以​在​线​动​态​调​整​,所​以​对​于​行​为​异​常​的​线​上​集​群​可​以​临​时​开​启​DEBUG日​志​一​小​段​时​间​然​后​再​关​闭​以​收​集​异​常​行​为​的​日​志​。​
  2. slow-query-time,DBScale支​持​在​DBScale层​面​记​录​达​到​指​定​阀​值​的​慢​查​询​语​句​,并​且​支​持​使​用​pt-query-digest进​行​分​析​,参​考​参​数​slow-query-time。​进​行​集​群​调​优​的​时​候​可​以​利​用​该​功​能​进​行​慢​查​询​分​析​。​
其​他​通​常​推​荐​使​用​默​认​值​,但​对​性​能​有​一​定​影​响​的​配​置​:
  1. backlog,参​考​参​数​backlog。​
  2. record-transaction-sqls,参​考​参​数​record-transaction-sqls。​
  3. support-show-warning,参​考​参​数​support-show-warning。​
  4. always-reset-session-var,参​考​参​数​always-reset-session-var。​

4.8. 读​写​分​离​与​读​负​载​均​衡​调​优​

DBScale支​持​通​过​读​写​分​离​和​读​负​载​均​衡​,具​体​的​参​数​调​优​可​以​参​考​第 17.1 节 “读​写​分​离​”。​

4.9. 分​表​调​优​

分​片​表​的​配​置​与​使​用​、​支​持​的​分​片​算​法​等​介​绍​可​以​参​考​第 11 章 DBScale 分​片​表​。​

4.9.1. 分​片​列​选​取​

分​片​列​的​选​择​有​如​下​几​个​原​则​:
  1. 数​据​分​布​均​匀​。​通​常​选​取​的​分​片​算​法​为​hash或​mod,在​这​种​情​况​下​,所​选​择​的​分​片​列​的​值​的​离​散​度​需​要​足​够​高​,避​免​大​部​分​记​录​都​被​路​由​到​少​数​的​几​个​分​片​上​。​
  2. 对​于​OLTP业​务​,查​询​条​件​尽​量​带​分​片​列​的​等​值​and条​件​。​通​常​OLTP的​请​求​都​是​大​并​发​的​单​行​或​少​量​行​的​操​作​,需​要​尽​可​能​地​降​低​SQL的​响​应​时​间​,尽​可​能​地​将​OLTP的​SQL请​求​路​由​到​一​个​分​片​可​以​在​全​局​减​少​不​必​要​的​分​片​扫​描​以​提​高​执​行​效​率​。​
  3. 对​于​OLAP业​务​,查​询​条​件​尽​量​不​要​带​分​片​列​的​等​值​and条​件​。​通​常​OLAP的​请​求​查​询​复​杂​度​都​较​高​,并​且​并​发​很​小​,这​种​情​况​下​应​该​尽​可​能​地​将​查​询​请​求​并​发​出​去​,使​用​更​多​的​分​片​更​多​的​节​点​更​多​的​计​算​资​源​参​与​分​布​式​并​行​计​算​以​缩​短​复​杂​查​询​的​响​应​时​间​。​
  4. 分​片​列​不​允​许​update操​作​,需​要​修​改​只​能​先​delete再​insert。​

4.9.2. 分​片​表​SQL调​优​

有​如​下​调​优​建​议​(不​是​使​用​限​制​):
  1. 尽​量​在​group by中​带​上​分​片​列​。​
  2. 尽​量​避​免​在​having中​使​用​表​达​式​计​算​。​
  3. 尽​量​避​免​在​group by和​order by使​用​的​是​不​同​的​列​。​
  4. 使​用​两​级​复​制​配​置​全​局​表​以​规​避​跨​节​点​JOIN。​具​体​参​考​第 2.8 节 “DBScale 集​群​按​需​安​装​使​用​全​流​程​示​例​”中​的​示​例​集​群​配​置​。​
    使​用​两​级​复​制​的​集​群​建​议​开​启​配​置​enable-get-rep-connection,具​体​的​可​以​参​考​enable-get-rep-connection。​

4.9.3. 分​片​表​高​级​调​优​

当​分​片​表​集​群​写​压​力​过​大​时​,DBScale支​持​在​线​扩​展​分​片​表​集​群​,具​体​的​可​以​参​考​第 17.8 节 “DBScale 迁​移​数​据​”。​
DBScale支​持​分​片​表​的​跨​节​点​JOIN,具​体​使​用​建​议​可​以​参​考​第 17.9 节 “跨​节​点​JOIN”。​

第 5 章 数​据​导​入​导​出​

本​章​将​介​绍​如​何​对​DBScale集​群​进​行​数​据​导​入​和​导​出​。​

5.1. 数​据​导​入​

DBScale 支​持​如​下​几​种​数​据​导​入​方​式​:
  1. 对​于​使​用​ mysqldump 或​者​ mysqlpump 导​出​的​文​件​,DBScale支​持​使​用​source命​令​或​命​令​行​文​件​重​定​向​的​方​式​进​行​数​据​导​入​,例​如​:
    mysql -udbscale -p -h127.0.0.1 -P3307 < dump.sql
    
    需​要​注​意​的​是​:如​果​使​用​mysqldump命​令​从​单​机​mysql库​导​出​数​据​然​后​导​入​dbscale,那​么​需​要​在​mysqldump命​令​添​加​参​数​“​--skip-add-locks --set-gtid-purged=OFF”​,否​则​可​能​无​法​导​入​dbscale。​
    需​要​注​意​的​是​:DBScale不​支​持​同​时​执​行​多​条​SQL命​令​。​使​用​mysql命​令​行​客​户​端​mysql会​自​动​将​多​条​SQL拆​分​逐​个​执​行​。​如​果​使​用​图​形​工​具​,建​议​使​用​SQLYog。​
    需​要​注​意​的​是​:如​果​dump.sql文​件​中​本​身​没​有​创​建​并​ use 到​一​个​schema的​话​,在​执​行​数​据​导​入​前​请​先​登​陆​集​群​创​建​ schema 并​在​导​入​的​mysql命​令​中​指​定​ schema。​DBScale默​认​的​schema是​ information_schema,所​以​如​果​没​有​ use schema 就​执​行​操​作​的​话​,可​能​会​报​错​权​限​不​够​,而​不​是​通​常​mysql 的​ No database selected 报​错​。​
  2. 对​于​使​用​mydumper导​出​的​文​件​,DBScale 支​持​使​用​ myloader 进​行​数​据​的​恢​复​,例​如​:
    myloader -u root -p mysql -h 127.0.0.1 -P 3307 -d /tmp/02
    
  3. 对​于​使​用​select...into outfile导​出​的​格​式​化​数​据​文​件​,DBScale支​持​使​用​mysqlimport或​load data命​令​进​行​数​据​导​入​。​
    Load data支​持​数​据​在​客​户​端​的​local模​式​,以​及​数​据​在​DBScale端​的​非​local模​式​。​DBScale支​持​使​用​如​下​参​数​调​节​Load data过​程​中​数​据​导​入​线​程​对​CPU和​内​存​的​使​用​:load-analysis-num, max-load-analysis-wait-size, max-load-ready-packets。​
    需​要​注​意​的​是​,DBScale只​支​持​在​Load data语​句​使​用​单​字​符​的​分​隔​符​,该​单​字​符​可​以​是​特​殊​字​符​。​
  4. DBScale支​持​使​用​insert...select的​方​式​从​集​群​外​数​据​库​导​入​数​据​。​
    首​先​将​该​集​群​外​数​据​库​作​为​一​个​数​据​源​添​加​进​集​群​。​如​果​该​数​据​库​是​MySQL,可​以​直​接​将​其​配​置​进​集​群​作​为​集​群​的​一​个​数​据​域​,假​设​集​群​外​数​据​源​的​表​位​于​outer库​下​:
    [data-server outer_server]
    host = 127.0.0.1
    port = 13003
    
    [data-source ds_outer]
    type = server
    server = outer_server-1-5-1-1
    user = root
    
    [schema outer]
    data-source = ds_outer
    
    而​后​就​可​以​在​dbscale端​通​过​insert select命​令​将​该​outer数​据​源​的​数​据​抽​取​出​来​并​插​入​到​集​群​内​指​定​表​中​,假​设​集​群​中​配​置​了​一​个​分​片​表​ test.t1,那​么​我​们​就​可​以​使​用​如​下​命​令​将​outer数​据​源​中​的​数​据​导​入​到​集​群​的​test.t1表​中​:
     insert into test.t1 select * from outer.t1
    
    如​果​提​供​数​据​源​的​表​和​所​在​的​库​名​与​集​群​需​要​导​入​数​据​的​表​和​库​名​一​样​,例​如​我​们​要​将​一​个​单​机​mysql中​的​库​表​同​名​导​入​到​dbscale集​群​中​,这​是​DBScale提​供​了​alias schema功​能​进​行​insert...select方​式​数​据​导​入​,假​设​我​们​要​导​入​的​库​名​为​test:
    [data-server outer_server]
    host = 127.0.0.1
    port = 13003
    
    [data-source ds_outer]
    type = server
    server = outer_server-1-5-1-1
    user = root
    
    [schema outer]
    data-source = ds_outer
    alias-real-name = test
    
    与​之​前​的​配​置​最​大​的​区​别​是​[schema outer]下​多​了​一​个​ alias-real-name = test 的​配​置​,告​知​dbscale 该​schema的​配​置​中​outer只​是​一​个​别​名​,而​真​正​的​数​据​库​名​为​ test。​当​客​户​端​执​行​ insert into test.t1 select * from outer.t1时​,dbscale会​利​用​outer库​定​位​数​据​源​,然​后​在​真​正​执​行​的​时​候​将​outer库​替​换​为​test库​。​在​这​种​配​置​下​, 代​表​着​外​部​数​据​的​server,应​该​配​置​ ignore-ping 来​使​得​ dbscale 不​去​维​护​这​个​ server 的​状​态​。​
    对​于​非​mysql的​外​部​数​据​库​,可​以​使​用​mariadb的​connect引​擎​的​odbc/jdbc方​式​伪​装​成​一​个​mysql,然​后​用​上​面​同​样​的​方​式​将​数​据​导​入​集​群​。​
    可​以​配​置​dbscale 参​数​use-load-data-for-insert-select 为​2来​使​用​ load data的​方​式​进​行​数​据​导​入​。​
    参​考​章​节​第 4.2 节 “数​据​导​入​/插​入​相​关​配​置​” 进​行​load data方​式​insert...select导​入​的​性​能​调​优​。​
    参​考​章​节​第 7.4.5 节 “在​线​动​态​添​加​数​据​空​间​” 对​在​线​的​dbscale集​群​在​线​添​加​一​个​alias_schema进​行​数​据​导​入​。​

5.2. 数​据​导​出​

DBScale 支​持​如​下​数​据​导​出​方​式​:。​
  1. 使​用​ mysqldump 工​具​进​行​数​据​导​出​,用​法​和​ MySQL 是​一​样​的​。​但​是​需​要​注​意​, 如​果​导​出​的​数​据​需​要​包​含​视​图​, 则​需​要​添​加​--single-transaction, 请​使​用​示​例​中​出​现​的​参​数​.
    简​单​示​例​如​下​:
    1. 备份单表, 数据及表结构 
    shell> mysqldump [options] db_name [tbl_name ...]
    mysqldump -udbscale -pdbscale -h127.0.0.1 -P3307 --skip-add-locks --set-gtid-purged=OFF tpcc_mysql customer > database_table.sql
    2. 备份单个库, 因为单个库中, 可能包含视图, 则需要添加--single-transaction
    shell> mysqldump [options] db_name --single-transaction ...
    mysqldump -udbscale -pdbscale -h127.0.0.1 -P3307 --skip-add-locks --set-gtid-purged=OFF tpcc_mysql --single-transaction > whole_database.sql
    如果需要备份存储过程(procedure)和函数(function), 则添加--routine
    mysqldump -udbscale -pdbscale -h127.0.0.1 -P3307 --skip-add-locks --set-gtid-purged=OFF tpcc_mysql --single-transaction --routine > whole_database.sql
    3. 备份整个MySQL实例的所有数据, 因为包含视图, 所以需要添加--single-transaction
    shell> mysqldump [options] --all-databases
    mysqldump -uroot -pmysql -h127.0.0.1 -P3307 --skip-add-locks --set-gtid-purged=OFF --all-databases --single-transaction > all_databases.sql
    
  2. 使​用​ mydumper 工​具​进​行​数​据​的​导​出​, 用​法​与​ MySQL 基​本​相​同​, 但​是​需​要​注​意​的​是​不​会​备​份​二​进​制​文​件​, 请​使​用​示​例​中​出​现​的​参​数​。​
    简​单​示​例​如​下​:
    1. 备份单表, 数据及表结构
    shell> ./mydumper [options] -B db_name -T table_name -o backup-dir
    ./mydumper -u dbscale -p dbscale -h 172.16.90.102 -P 3307 -B tpcc_mysql -T history -m -o /tmp/04/
    2. 备份单个库
    shell> ./mydumper [options] -B db_name -o backup-dir
    ./mydumper -u dbscale -p dbscale -h 172.16.90.102 -P 3307 -B tpcc_mysql -c -o /tmp/01
    3. 备份整个MySQL实例的所有数据
    shell> ./mydumper [options] -o backup-dir
    ./mydumper -u dbscale -p dbscale -h 172.16.90.102 -P 3307 -o /tmp/02/
    
  3. 使​用​ MySQL5.7 提​供​的​ mysqlpump 工​具​进​行​数​据​的​导​出​, 用​法​与​ MySQL5.7 基​本​相​同​, 但​是​需​要​注​意​DBScale的​后​端​也​需​要​是​MySQL5.7, 请​使​用​示​例​中​出​现​的​参​数​。​
    简​单​示​例​如​下​:
    1. 备份单个表, 数据及表结构
    shell> mysqlpump [options] db_name [tbl_name ...]
    mysqlpump -uroot -pmysql -h127.0.0.1 -P3307 tpcc_mysql customer > database_table.sql
    2. 备份单个库
    shell> mysqlpump [options] db_name ...
    mysqlpump -uroot -pmysql -h172.16.90.102 -P3307 tpcc_mysql  > whole_database.sql
    3. 备份整个MySQL实例的所有数据
    shell> mysqldump [options] --all-databases
    mysqlpump -uroot -pmysql -h172.16.90.102 -P3307 --all-databases > all_databases.sql
    
  4. 使​用​select...into outfile进​行​格​式​化​数​据​导​出​,需​要​注​意​,dbscale只​支​持​单​字​符​分​隔​符​,该​单​字​符​可​以​是​特​殊​字​符​。​

第 6 章 日​志​

通​常​ DBScale 的​日​志​文​件​名​为​“​dbscale.log”​,它​的​位​置​由​选​项​ log-file 控​制​,通​常​为​“​/var/log/dbscale.log”​。​

6.1. 日​志​文​件​ rotate

DBScale 的​日​志​文​件​使​用​ linux 系​统​通​用​的​ logrotate 程​序​进​行​日​志​文​件​的​管​理​和​ rotate。​如​下​是​一​个​使​用​示​例​,假​设​ DBScale 日​志​文​件​位​于​“​/var/log/dbscale.log”​:
  1. 创​建​一​个​新​文​件​ dbscale.logrotate, 并​在​其​中​写​如​下​内​容​:
    /var/log/dbscale.log {
    rotate 10
    size 10M
    notifempty
    missingok
    compress
    sharedscripts
    postrotate
    /usr/bin/killall -HUP dbscale
    endscript
    }
    配​置​文​件​定​义​了​最​大​保​存​的​日​志​文​件​数​为​ 10 个​,每​个​文​件​最​大​为​ 10M,rotate 出​来​的​日​志​文​件​使​用​压​缩​的​方​式​保​存​,当​ logrotate 认​为​需​要​进​行​日​志​文​件​ rotate 的​时​候​会​向​“​dbscale”​进​程​发​送​ HUP 信​号​。​
  2. 将​dbscale.logrotate文​件​保​存​放​在​系​统​目​录​中​。​
  3. 创​建​一​个​新​文​件​dbscale-log-check.cron,放​在​/etc/cron.d/目​录​中​。​文​件​内​容​如​下​:
    # /etc/cron.d/dbscale-log-check.cron crontab entries for the dbscale log rotation
    
    SHELL=/bin/sh
    
    # Check log every 30 minutes
    #*/30 * * * * root /usr/sbin/logrotate -f /path/to/dbscale.logrotate >/dev/null 2>&1 &
    
    # Check log every 6 hours
    #0 */6 * * * root /usr/sbin/logrotate -f /path/to/dbscale.logrotate >/dev/null 2>&1 &
    
    # Check log every day
    0 0 */1 * * root /usr/sbin/logrotate -f /path/to/dbscale.logrotate >/dev/null 2>&1 &
    
  4. 如​果​DBScale 的​ log 文​件​没​有​放​在​ /var/log 目​录​下​,SELINUX 权​限​控​制​可​能​会​导​致​ log rotation 失​败​。​那​么​:
    • 关​闭​ SELINUX 权​限​控​制​。​方​法​一​:运​行​命​令​ setenforce 0(重​启​失​效​)。​方​法​二​:编​辑​文​件​ /etc/sysconfig /selinux,修​改​文​件​其​中​一​行​为​“​SELINUX=disabled”​(重​启​生​效​)。​
    • 或​者​保​持​ SELINUX 开​启​,则​需​要​运​行​下​列​命​令​(假​设​ DBScale log 文​件​放​在​ /home/dbscale/log 目​录​下​):
      semanage fcontext -a -t var_log_t "/home/dbscale/log(/.*)?"
      restorecon -R -v /home/dbscale/log
  5. 重​启​crond服​务​,让​新​添​加​的​dbscale log check生​效​:service crond restart。​

6.2. DBScale 日​志​文​件​说​明​

DBScale 的​日​志​文​件​主​要​有​ 4 个​级​别​:ERROR,WARN,INFO,DEBUG。​
可​以​通​过​选​项​ log-level 来​控​制​ DBScale 的​日​志​数​据​级​别​:如​果​ log-level 为​ ERROR ,那​么​只​会​有​ ERROR 日​志​被​打​印​到​日​志​文​件​中​;如​果​ log-level 为​ WARN ,那​么​ WARN 和​ error 的​日​志​会​被​打​印​到​日​志​文​件​中​;如​果​ log-level 为​ INFO ,那​么​ ERROR、​WARN 和​ INFO 的​日​志​会​被​打​印​到​日​志​文​件​中​;如​果​ log-level 为​ DEBUG ,那​么​ ERROR、​WARN、​INFO、​和​ DEBUG 的​日​志​信​息​都​会​被​打​印​到​日​志​文​件​中​。​

6.3. DBScale 慢​日​志​

DBScale 慢​日​志​相​关​配​置​和​信​息​请​参​考​ slow-query-time。​

6.4. DBScale 审​计​日​志​

DBScale 审​计​日​志​相​关​配​置​和​信​息​请​参​考​ do-audit-log。​

第 7 章 DBScale 管​理​命​令​

7.1. DBScale 管​理​工​具​帮​助​
7.2. DBScale 运​行​状​态​与​参​数​
7.2.1. 查​看​ DBScale 集​群​状​态​
7.2.2. 查​看​ DBScale 参​数​值​
7.2.3. 在​线​设​置​DBScale配​置​选​项​
7.2.4. DBScale 维​护​的​ mysql session 变​量​值​
7.3. DBSCALE SHOW 语​句​
7.3.1. 查​看​ DBScale 版​本​信​息​
7.3.2. 查​看​ DBScale 进​程​所​在​机​器​的​主​机​名​
7.3.3. 查​看​ DBScale 安​装​路​径​和​日​志​文​件​路​径​
7.3.4. 查​看​ DBScale IP黑​白​名​单​
7.3.5. 查​看​在​事​务​状​态​中​已​执​行​的​ SQL 语​句​
7.3.6. 查​看​所​有​数​据​节​点​
7.3.7. 查​看​数​据​源​信​息​
7.3.8. 查​看​PARTITION_SCHEME
7.3.9. 查​看​表​所​在​位​置​
7.3.10. 查​看​ metadata source 的​失​败​的​SQL语​句​
7.3.11. 查​看​每​个​session的​使​用​内​存​数​
7.3.12. 查​看​用​户​状​态​
7.3.13. 查​看​用​户​详​细​状​态​
7.3.14. 查​看​用​户​锁​表​状​态​
7.3.15. 查​看​ innodb/tokudb 锁​等​待​
7.3.16. 查​看​上​一​条​语​句​的​执​行​时​间​细​节​
7.3.17. 查​看​连​接​池​状​态​
7.3.18. 查​看​连​接​池​版​本​
7.3.19. 查​看​线​程​池​状​态​
7.3.20. 查​看​ SQL 语​句​的​预​估​影​响​行​数​
7.3.21. 查​看​后​端​工​具​线​程​
7.3.22. 查​看​指​定​表​分​片​信​息​
7.3.23. 查​看​一​个​指​定​分​区​表​的​信​息​
7.3.24. 查​看​SHARD分​片​表​SHARD分​片​分​布​
7.3.25. 查​看​分​片​表​虚​拟​分​片​分​布​
7.3.26. 查​看​所​有​的​shard分​片​表​
7.3.27. 查​看​未​自​动​恢​复​的​故​障​分​布​式​事​务​信​息​
7.3.28. 查​看​跨​节​点​ JOIN 相​关​状​态​。​
7.3.29. 查​看​等​待​清​理​的​ SHARD 表​
7.3.30. 查​看​用​户​是​否​具​有​执​行​ DDL 语​句​的​权​限​
7.3.31. 查​看​库​级​别​权​限​设​置​
7.3.32. 查​看​表​级​别​权​限​设​置​
7.3.33. 查​看​当​前​ dbscale swap工​作​线​程​组​运​行​状​况​
7.3.34. 查​看​当​前​ DBScale 在​运​行​过​程​中​记​录​到​的​最​近​10条​比​较​重​要​的​警​告​。​
7.3.35. 查​看​某​张​自​增​分​片​表​的​当​前​自​增​值​。​
7.3.36. 查​看​消​息​订​阅​平​台​ server 任​务​状​态​
7.3.37. 查​看​消​息​订​阅​平​台​ client 任​务​状​态​
7.3.38. 查​看​消​息​订​阅​平​台​ server 任​务​关​联​的​所​有​ client 任​务​的​状​态​
7.3.39. 查​看​schema数​据​域​
7.4. DBSCALE DYNAMIC 语​句​
7.4.1. 在​线​动​态​添​加​一​个​数​据​节​点​
7.4.2. 在​线​动​态​删​除​一​个​数​据​节​点​
7.4.3. 在​线​动​态​添​加​数​据​源​
7.4.4. 在​线​删​除​数​据​源​
7.4.5. 在​线​动​态​添​加​数​据​空​间​
7.4.6. 在​线​为​主​从​集​群​添​加​ Slave 节​点​
7.4.7. 在​线​从​主​从​集​群​删​除​ Slave 节​点​
7.4.8. 在​线​手​动​进​行​主​从​切​换​
7.4.9. 在​线​设​置​ replication 数​据​源​ load_balance 策​略​
7.4.10. 在​线​调​整​ MultipleMaster 数​据​源​的​ active 节​点​
7.4.11. 在​线​动​态​删​除​一​个​分​片​策​略​
7.4.12. 在​线​调​整​数​据​源​内​某​个​ Server DataSource 的​权​重​
7.4.13. 在​线​调​某​张​自​增​分​片​表​的​自​增​值​
7.4.14. 在​线​调​SCHEMA的​pushdown_procedure行​为​
7.4.15. 在​线​调​整​IP黑​白​名​单​
7.5. 数​据​迁​移​相​关​命​令​
7.5.1. 在​线​迁​移​数​据​
7.5.2. 清​理​等​待​清​理​的​ SHARD 表​
7.6. DBScale 状​态​清​理​/刷​新​/重​置​命​令​
7.6.1. 刷​新​连​接​池​版​本​
7.6.2. 重​置​资​源​池​最​大​资​源​数​
7.6.3. 清​理​跨​节​点​ JOIN 临​时​表​
7.6.4. 清​理​ zookeeper 中​的​配​置​文​件​相​关​信​息​
7.6.5. 清​理​未​自​动​恢​复​的​故​障​分​布​式​事​务​信​息​
7.7. 异​步​操​作​管​理​命​令​
7.7.1. 查​看​异​步​操​作​命​令​
7.7.2. 异​步​操​作​控​制​
7.8. 消​息​订​阅​平​台​相​关​命​令​
7.9. 多​dbscale集​群​相​关​命​令​
7.10. 其​他​管​理​命​令​
7.10.1. 默​认​ session 变​量​动​态​管​理​
7.10.2. 设​置​某​一​用​户​的​优​先​级​
7.10.3. 阻​塞​表​请​求​
7.10.4. DBScale 执​行​命​令​信​号​
7.10.5. 保​存​ DBScale 的​配​置​信​息​
7.10.6. 通​过​机​器​名​与​连​接​id获​取​持​有​这​个​连​接​的​ DBScale session id值​
7.10.7. 在​dataserver端​执​行​特​定​命​令​
7.10.8. 在​线​获​取​数​据​一​致​性​点​
7.10.9. 扩​展​ EXPLAIN 语​句​

7.1. DBScale 管​理​工​具​帮​助​

DBScale 可​以​通​过​命​令​
mysql> DBSCALE HELP;
查​看​所​有​本​章​列​出​的​管​理​相​关​命​令​,如​果​在​命​令​后​面​加​上​字​符​串​则​可​以​进​行​模​糊​查​询​。​

7.2. DBScale 运​行​状​态​与​参​数​

7.2.1. 查​看​ DBScale 集​群​状​态​

DBScale 提​供​了​
mysql> DBSCALE SHOW STATUS;
命​令​查​看​ DBScale 集​群​运​行​状​态​。​输​出​汇​总​:
输​出​项​ 含​义​
RunningTime(s) DBScale运​行​时​间​
TimesServerDown 后​端​server宕​机​次​数​
TimesChangeMaster 后​端​集​群​发​生​主​从​切​换​的​次​数​
TimesReplicationBroken 后​端​集​群​发​生​主​从​复​制​故​障​的​次​数​,故​障​包​括​延​迟​过​大​和​复​制​断​开​
TimesAllReadSourceOfReplicationUnAvailable 后​端​集​群​某​个​主​从​复​制​组​中​所​有​从​节​点​主​从​复​制​都​出​现​故​障​的​次​数​
TimesClientBrokenNotUsingQuit 客​户​端​连​接​非​正​常​断​开​的​次​数​
TimesPartialParsingWithoutTableName sql语​句​解​析​失​败​,并​且​没​有​解​析​出​表​名​的​次​数​
TimesPartialParsingRelatedToPartitionTable sql语​句​解​析​失​败​,并​且​解​析​出​表​名​,但​表​名​中​包​含​了​分​片​表​的​次​数​
TimesFailStoreMetadata 没​能​够​成​功​更​新​元​数​据​信​息​的​次​数​
TimesCreateNewTmpTables 因​为​表​池​为​空​而​新​建​的​临​时​表​数​
NumbersTmpTablePool 临​时​表​池​的​总​数​量​
TimesCrossNodeJoin 跨​节​点​join执​行​个​数​
TimesUseTmpTable 临​时​表​使​用​数​量​
TimesUseDuplicateTable Duplicate 临​时​表​被​用​到​的​次​数​
TimesXAOptimizeReadOnlyStmt 被​优​化​过​的​包​含​只​读​连​接​的​ XA 分​布​式​事​务​数​量​
TimesXAOptimizeOnlyAffectOneServer 因​只​涉​及​到​一​个​后​端​ server 而​被​优​化​的​ XA 分​布​式​事​务​数​量​
TimesWarningsCount 客​户​端​SQL语​句​执​行​结​果​带​有​警​告​的​次​数​
TimesErrorPacketFromServer 后​端​ server 返​回​错​误​包​的​次​数​
TimesErrorGeneratedByDBscale 由​ DBScale 发​起​的​错​误​信​息​的​次​数​
TimesExecutionPlanTouchAllPartition 涉​及​到​了​分​片​表​的​所​有​分​片​的​次​数​的​执​行​计​划​数​量​(不​包​含​ DDL 语​句​)
TimesCallStmtExecuteOnDBscaleSide 在​ DBScale端​执​行​而​不​是​直​接​转​发​后​端​MySQL执​行​的​存​储​过​程​数​量​
TimesCrossNodeJoinOrTableSubQueryMoveDataMoreThanOnce 在​后​端​ server 之​间​出​现​了​大​于​一​次​的​数​据​挪​动​的​跨​节​点​或​者​子​查​询​的​数​量​
TimesStmtRecordAsSlowQueryByDBscale 被​ DBScale 判​定​为​慢​语​句​的​语​句​数​量​
TimesXAUNRelayFailTransaction 在​关​闭​replay-redo-log的​情​况​下​(默​认​),对​于​非​mysql5.7为​后​端​存​储​节​点​的​集​群​,在​出​现​分​布​式​事​务​故​障​部​分​提​交​时​,dbscale默​认​不​会​自​动​进​行​集​群​redo日​志​恢​复​。​在​这​种​情​况​下​,该​状​态​值​记​录​了​dbscale启​动​以​来​发​生​分​布​式​事​务​故​障​部​分​提​交​的​故​障​节​点​次​数​,每​个​故​障​分​布​式​事​务​失​败​的​节​点​累​加​一​次​。​
TimesDBScaleLatestImportantWarning 当​前​ DBScale 实​例​在​运​行​过​程​中​记​录​到​的​重​要​警​告​的​个​数​
TimesDBScalePoolReachMaxWater 当​前​ DBScale 实​例​在​运​行​过​程​中​记​录​到​的​资​源​池​数​目​达​到​最​大​值​次​数​(如​果​一​个​小​时​内​出​现​多​次​资​源​池​内​资​源​数​目​到​达​最​大​值​,只​记​录​一​次​)
TimesDBScaleFailFlushConfToZoo 多​dbscale集​群​master节​点​发​生​配​置​变​更​时​刷​新​配​置​到​zookeeper上​失​败​的​次​数​。​预​期​为​0,如​果​发​生​或​增​加​,需​要​DBA通​过​错​误​日​志​进​行​定​位​并​手​动​恢​复​。​
示​例​执​行​结​果​
Variable_name Value
RunningTime(s) 20
TimesServerDown 2
TimesChangeMaster 2
TimesReplicationBroken 2
TimesAllReadSourceOfReplicationUnAvailable 0
TimesUseDuplicateTable 0
TimesClientBrokenNotUsingQuit 2
TimesPartialParsingWithoutTableName 2
TimesPartialParsingRelatedToPartitionTable 1
TimesFailStoreMetadata 1
TimesCreateNewTmpTables 40
NumbersTmpTablePool 40
TimesXAOptimizeReadOnlyStmt 10
TimesXAOptimizeOnlyAffectOneServer 10
TimesDBScalePoolReachMaxWater 1

7.2.2. 查​看​ DBScale 参​数​值​

DBScale 可​以​通​过​命​令​
DBSCALE SHOW OPTIONS;
查​看​配​置​选​项​的​当​前​值​,选​项​名​是​可​选​的​,如​果​没​有​指​明​选​项​将​输​出​所​有​选​项​的​当​前​值​,支​持​ LIKE "%" 模​糊​查​询​。​
mysql> DBSCALE SHOW SESSION | INSTANCE | GLOBAL OPTIONS;
mysql> DBSCALE SHOW SESSION | INSTANCE | GLOBAL OPTIONS LIKE '%option_name%';

7.2.3. 在​线​设​置​DBScale配​置​选​项​

DBScale 的​动​态​调​整​命​令​可​能​会​使​得​运​行​时​的​集​群​拓​扑​等​信​息​与​启​动​ DBScale 时​的​配​置​文​件​信​息​不​一​致​,这​时​就​需​要​及​时​地​手​动​调​整​配​置​文​件​,或​者​通​过​第 7.10.5 节 “保​存​ DBScale 的​配​置​信​息​”命​令​将​最​新​的​运​行​时​配​置​信​息​保​存​到​配​置​文​件​。​
DBScale 可​以​在​线​设​置​部​分​配​置​选​项​(只​有​ root 用​户​以​及​ dbscale 用​户​拥​有​在​线​设​置​的​权​限​),目​前​支​持​的​配​置​选​项​包​括​3个​级​别​:SESSION,session级​别​的​配​置​选​项​;INSTANCE,单​DBScale实​例​配​置​选​项​;GLOBAL,DBScale集​群​全​局​配​置​选​项​。​设​置​ session 级​别​配​置​选​项​,只​对​当​前​ session 生​效​;设​置​ instance 级​别​配​置​选​项​,对​当​前​单​ DBScale 实​例​生​效​;设​置​ global 级​别​配​置​选​项​,DBScale 集​群​全​局​即​时​生​效​。​
可​以​在​线​设​置​的​GLOBAL配​置​选​项​包​括​:
  • always_reset_session_var
  • close-cross-node-transaction
  • connect_timeout
  • cross_node_join_method
  • dynamic_remove_slave_wait
  • enable_listener_off
  • enable_record_query_time
  • exiting_timeout
  • enable_get_rep_connection
  • enable_multiple_stmt_check
  • get_conn_retry
  • handle_monitor_timeout_via_update_method
  • load_analysis_num
  • load_data_auto_inc_local_capacity
  • log_level
  • load-insert-select-fields-term
  • load-insert-select-lines-term
  • master_change_back_conn_in_use_retry
  • master_change_back_wait
  • max_connection_cleanup_number
  • max_conn_execute_time
  • max_federated_cross_join_rows
  • max_fetchnode_ready_rows_size
  • max_replication_delay
  • max_replication_delay_potential_master
  • max_single_sort_rows
  • max_load_analysis_wait_size
  • max_load_select_analysis_wait_size
  • max_login_time
  • max_rowmap_size
  • migrate_write_thread
  • monitor_interval
  • monitor_method
  • monitor_net_timeout
  • monitor_retry_count
  • monitor_retry_gap
  • net_status
  • on_view
  • real_time_queries
  • enable_record_transaction_sqls
  • send_server_retry_times
  • server_status_error_log_gap
  • slow_query_time
  • support_select_metadata
  • socket_base_timeout
  • wait_timeout
  • use_load_data_for_insert_select
  • use_partial_parse
可​以​在​线​设​置​的​INSTANCE配​置​选​项​包​括​:
  • cross_node_join_method
  • log_level
  • load-insert-select-fields-term
  • load-insert-select-lines-term
  • max_federated_cross_join_rows
  • max_single_sort_rows
  • enable_multiple_stmt_check
  • use_load_data_for_insert_select
  • migrate_with_load
  • record_auto_increment_delete_value
可​以​在​线​设​置​的​SESSION配​置​选​项​包​括​:
  • cross_node_join_method
  • load-insert-select-fields-term
  • load-insert-select-lines-term
  • max_federated_cross_join_rows
  • max_single_sort_rows
  • enable_multiple_stmt_check
  • use_load_data_for_insert_select
mysql> DBSCALE SET [SESSION | INSTANCE | GLOBAL] option_name = val;
当​同​时​设​置​多​个​配​置​选​项​时​,若​某​个​选​项​设​置​错​误​,如​选​项​名​不​存​在​或​者​值​类​型​不​对​,其​他​正​常​选​项​仍​可​成​功​设​置​。​

7.2.4. DBScale 维​护​的​ mysql session 变​量​值​

DBScale 通​过​选​项​ default-session-variables 来​配​置​ DBScale 维​护​的​ mysql session 变​量​值​.
default-session-variables 默​认​值​为​ "CHARACTER_SET_CLIENT:CHARACTER_SET_RESULTS: CHARACTER_SET_CONNECTION:NET_READ_TIMEOUT:TIME_ZONE: SQL_SAFE_UPDATES:SQL_MODE:TX_ISOLATION:SQL_SELECT_LIMIT: AUTO_INCREMENT_INCREMENT:AUTO_INCREMENT_OFFSET:NET_WRITE_TIMEOUT:TX_READ_ONLY:MAX_SORT_LENGTH", 也​就​是​说​ DBScale 会​去​维​护​后​端​数​据​库​的​这​些​ session 变​量​, 用​户​可​以​继​续​添​加​需​要​维​护​的​变​量​.
DBScale提​供​了​
DBSCALE SHOW/ADD/REMOVE DEFAULT SESSION VARIABLES para_list
命​令​实​现​对​默​认​ session 变​量​的​动​态​管​理​功​能​,第 7.10.1 节 “默​认​ session 变​量​动​态​管​理​”。​

7.3. DBSCALE SHOW 语​句​

7.3.1. 查​看​ DBScale 版​本​信​息​

DBScale 可​以​通​过​命​令​
mysql> DBSCALE SHOW VERSION;
显​示​ DBScale 的​版​本​号​。​

7.3.2. 查​看​ DBScale 进​程​所​在​机​器​的​主​机​名​

DBScale 可​以​通​过​命​令​
mysql> DBSCALE SHOW HOSTNAME;
显​示​ DBScale 进​程​所​在​机​器​的​主​机​名​。​

7.3.3. 查​看​ DBScale 安​装​路​径​和​日​志​文​件​路​径​

DBScale 可​以​通​过​命​令​
mysql> DBSCALE SHOW PATH INFO;
显​示​ DBScale 的​安​装​路​径​和​ log 路​径​。​

7.3.4. 查​看​ DBScale IP黑​白​名​单​

DBScale 可​以​通​过​命​令​
mysql> DBSCALE SHOW BLACK WHITE LIST;
显​示​ DBScale 的​ IP 黑​白​名​单​。​
该​命​令​只​有​root和​dbscale用​户​可​以​执​行​。​
字​段​名​ 描​述​
ip IP地​址​
black_or_white 标​识​该​IP是​属​于​黑​名​单​还​是​白​名​单​

7.3.5. 查​看​在​事​务​状​态​中​已​执​行​的​ SQL 语​句​

DBSCALE SHOW TRANSACTION SQLS FOR user_id;
当​开​启​ record-transaction-sqls 选​项​时​,用​户​在​事​务​状​态​下​执​行​的​ SQL 语​句​会​被​记​录​下​来​,通​过​该​命​令​可​以​查​看​ ID 号​为​ user_id 的​用​户​目​前​在​事​务​状​态​下​已​经​执​行​的​ SQL 语​句​。​
字​段​名​ 描​述​
Sequence-id 序​列​号​
Sqls 已​经​执​行​的​ SQL 语​句​

7.3.6. 查​看​所​有​数​据​节​点​

DBScale 提​供​了​ DBSCALE SHOW DATASERVERS 命​令​查​看​所​有​的​数​据​节​点​。​输​出​包​括​数​据​节​点​的​名​字​,ip,端​口​,帐​号​,状​态​以​及​其​他​数​据​节​点​具​有​的​所​有​可​配​置​属​性​。​如​果​有​密​码​将​会​替​换​成​字​符​串​ “​xxxxx”​。​
mysql>DBSCALE SHOW DATASERVERS;
servername host port username password status master_backup extrenal_load local_script external_script remote_user remote_password remote_port
auth_server 127.0.0.1 13000 root Server normal 1 0 root 22
master 127.0.0.1 13000 root Server normal 1 0 root 22
slave1 127.0.0.1 13001 root Changing master 1 0 root 22

7.3.7. 查​看​数​据​源​信​息​

data server的​状​态​包​括​:如​果​是​主​从​中​的​从​节​点​,Slave normal(状​态​正​常​),Changing master(切​换​主​从​中​),Server normal, slave down(主​从​断​开​),Server normal, slave error(主​从​错​误​),Slave normal, catching master(主​从​延​迟​),如​果​不​是​从​节​点​,Server down(节​点​错​误​),Server normal(节​点​正​常​),Dynamic removing(正​在​被​从​集​群​中​移​除​)以​及​未​知​状​态​Unknown。​data source的​状​态​包​括​:Working(工​作​状​态​),Changing(正​在​进​行​主​从​切​换​),Stop(故​障​不​可​用​),Slave stop(作​为​slave source主​从​错​误​),Unknown(未​知​)。​
  1. DBSCALE SHOW DATASOURCE ds_name;
    根​据​ data-source 名​显​示​该​ data-source 信​息​。​类​型​包​括​:server、​share_disk、​load-balance、​rwsplit、​replication。​各​类​型​对​应​不​同​的​输​出​格​式​:
    • Server DataSource
      字​段​名​ 描​述​
      Name data-source 名​
      Type data-source 类​型​
      Server 对​应​数​据​库​实​例​ data-server
      ServerStatus 对​应​数​据​库​实​例​ data-server 状​态​
      SourceStatus data-source 当​前​状​态​
      Is-internal 是​否​是​内​部​生​成​的​数​据​源​
    • Share-disk DataSource
      字​段​名​ 描​述​
      Name data-source 名​
      Type data-source 类​型​
      SourceStatus data-source 当​前​状​态​
      ActiveSource Active数​据​源​
      ActiveSourceStatus Active数​据​源​当​前​状​态​
      ColdStandbySource ColdStandby数​据​源​
      ColdStandbySourceStatus ColdStandby数​据​源​当​前​状​态​
    • Load-balance DataSource
      字​段​名​ 描​述​
      Name data-source 名​
      Type data-source 类​型​
      Status data-source 当​前​状​态​
      DataSource 封​装​的​负​载​均​衡​ data-source
      DataSourceStatus 封​装​的​负​载​均​衡​ data-source 当​前​状​态​
      DataServer 封​装​的​负​载​均​衡​ data-server
      DataServerStatus 封​装​的​负​载​均​衡​ data-server 当​前​状​态​
      Weight data-server 权​重​值​(如​果​有​)
    • Rwsplit DataSource
      字​段​名​ 描​述​
      Name data-source 名​
      Type data-source 类​型​
      SourceStatus data-source 当​前​状​态​
      WriteSource 写​节​点​数​据​源​(当​前​状​态​)
      WriteSourceStatus 写​节​点​数​据​源​当​前​状​态​
      WriteServer 写​节​点​数​据​源​对​应​的​后​端​ server
      WriteServerStatus 写​节​点​数​据​源​对​应​的​后​端​ server 状​态​
      ReadSource 读​节​点​数​据​源​(当​前​状​态​)
      ReadSourceStatus 读​节​点​数​据​源​当​前​状​态​
      ReadServers 如​果​数​据​源​类​型​为​server datasource,则​为​其​后​端​server,否​则​为​空​
      ReadServerStatus 读​节​点​ server 状​态​
      ReadWeight 读​节​点​ server 权​重​值​(如​果​有​)
    • Replication DataSource
      字​段​名​ 描​述​
      Name data-source 名​
      Type data-source 类​型​
      SourceStatus data-source 当​前​状​态​
      Load_balance_strategy data-source Load Balance 策​略​
      MasterSource 主​节​点​数​据​源​(当​前​状​态​)
      MasterSourceStatus 主​节​点​数​据​源​当​前​状​态​
      MasterServer 主​节​点​对​应​ data-server
      MasterServerStatus 主​节​点​ data-server 当​前​状​态​
      MasterWeight master server 权​重​值​(如​果​有​)
      SlaveSource 从​节​点​数​据​源​(当​前​状​态​)
      SlaveSourceStatus 从​节​点​数​据​源​当​前​状​态​
      SlaveServers 如​果​数​据​源​类​型​为​server datasource,则​为​其​后​端​server,否​则​为​空​
      SlaveServerStatus 从​节​点​各​ data-server 当​前​状​态​
      SlaveWeight slave server 权​重​值​(如​果​有​)
      DelayedTime data server 的​主​从​延​迟​大​小​(秒​)(如​果​当​前​ monitor_method = 2)
  2. DBSCALE SHOW DATASOURCE TYPE = type_name;
    根​据​ data-source 类​型​名​显​示​所​配​置​的​该​类​型​的​所​有​ data-source 信​息​。​输​出​格​式​与​根​据​ data-source 名​显​示​信​息​输​出​格​式​一​致​。​

7.3.8. 查​看​PARTITION_SCHEME

DBScale 可​以​通​过​命​令​
DBSCALE SHOW PARTITION_SCHEME
查​看​分​片​策​略​。​
  1. mysql> DBSCALE SHOW PARTITION_SCHEME;
    scheme_name type is_shard partitions relate_tables
    part HASH 0 ds_par1 ds_par2 test.part_table test.part_table_patt

7.3.9. 查​看​表​所​在​位​置​

DBScale 可​以​通​过​命​令​
DBSCALE SHOW TABLE LOCATION Table_Name
查​看​表​的​具​体​位​置​,包​括​ host_ip 和​ host_name,slave_name,host_port,data_source, 并​且​还​包​含​了​ slave 的​信​息​ host_name,slave_ip,slave_port, 如​果​有​多​个​ slave 会​分​多​行​显​示​。​如​果​是​分​片​表​则​会​显​示​所​有​包​括​该​表​的​ server 的​信​息​,所​属​ datasource 改​为​所​属​ partitionSchema.
Talbe_Name 为​ schema_name.table_name, 或​者​只​给​ table_name. 当​所​给​的​ Table_Name 没​有​在​配​置​文​件​中​配​置​时​,默​认​此​ table 存​在​于​ catalog
DBSCALE SHOW TABLE LOCATION table_name;
Server_name Server_ip Server_port Data_source slave_name slave_ip slave_port
xxxxx 127.0.0.1 13000 def_catalog xxxxx 127.0.0.1 13005
注​意​:此​命​令​并​不​会​检​查​ table 是​否​存​在​,如​果​该​ master 没​有​ slave 则​显​示​为​空​。​

7.3.10. 查​看​ metadata source 的​失​败​的​SQL语​句​

DBScale 可​以​通​过​命​令​
DBSCALE SHOW CRITICAL ERRORS
查​看​由​于​ medatada source 的​ connection 导​致​需​要​在​ metadata 中​执​行​的​SQL失​败​。​显​示​信​息​包​括​, Error_Type, Error_SQL.
mysql> DBSCALE SHOW CRITICAL ERRORS;
Error_Type Error_SQL
Metadata Error SELECT * FROM t1
注​意​:此​时​的​ Error_Type 只​可​能​是​ Metadata Error.

7.3.11. 查​看​每​个​session的​使​用​内​存​数​

DBScale 可​以​通​过​命​令​
DBSCALE SHOW USER MEMORY STATUS
查​看​每​个​用​户​的​内​存​使​用​情​况​,包​括​user_id和​memory_used。​user_id表​示​该​session的​id号​,memory_used表​示​当​前​占​用​的​内​存​数​,单​位​为​K。​
mysql> DBSCALE SHOW USER MEMORY STATUS;
user_id memory_used
root 58456
注​意​:此​命​令​用​在​后​端​数​据​库​为​mariadb时​才​会​生​效​.

7.3.12. 查​看​用​户​状​态​

DBScale 可​以​通​过​命​令​
DBSCALE SHOW USER STATUS [for user_name]
查​看​用​户​状​态​,主​要​包​括​当​当​前​用​户​的​ session,当​前​所​有​用​户​地​址​信​息​,正​在​执​行​语​句​,执​行​时​间​,工​作​状​态​,登​录​时​间​等​信​息​以​及​一​些​额​外​信​息​x。​如​果​给​定​了​用​户​名​ (for user_name),那​么​将​只​查​看​指​定​用​户​的​所​有​session状​态​.
DBScale 可​以​通​过​命​令​
DBSCALE SHOW USER STATUS RUNNING
查​看​正​在​执​行​语​句​的​用​户​状​态​,。​
工​作​状​态​(Working State) 为​6种​可​能​值​: none 表​示​空​闲​、​in-lock-state 表​示​处​于​锁​表​、​in-transaction 表​示​处​于​事​务​中​、​in-prepare 表​示​持​有​ prepare、​in-lock-state & in-prepare 以​及​ in-transaction & in-prepare。​
Thread_id_Handler 为​一​个​16进​制​的​值​,是​ DBScale 日​志​文​件​中​用​到​的​ session 地​址​,这​个​显​示​项​方​便​从​日​志​文​件​中​查​找​问​题​。​
mysql> DBSCALE SHOW USER STATUS;
Thread_id_Handler User_id User_info Executing SQL Executing time(ms) Working State Login time
0x1419000 5 root@127.0.0.1:38251 dbscale show user status 0 none 2014-9-26 6:40:15
0x1419e10 6 root@127.0.0.1:38263 Idle 0 none 2014-9-26 6:45:28

7.3.13. 查​看​用​户​详​细​状​态​

DBScale 可​以​通​过​命​令​
DBSCALE SHOW USER STATUS user_id
查​看​用​户​详​细​状​态​,主​要​包​括​用​户​工​作​状​态​的​详​细​额​外​信​息​以​及​用​户​持​有​的​连​接​信​息​。​
额​外​信​息​(Extra Info):
工​作​状​态​为​ none 时​,额​外​信​息​为​空​;
工​作​状​态​为​ in-lock-state 时​,额​外​信​息​为​持​有​的​锁​表​信​息​;
工​作​状​态​为​ in-transaction 时​,额​外​信​息​为​保​持​连​接​的​ dataspace 名​字​;
工​作​状​态​为​ in-prepare 时​,额​外​信​息​为​持​有​的​ prepare 数​量​;
工​作​状​态​为​组​合​时​,额​外​信​息​为​组​合​的​信​息​。​
连​接​信​息​(Kept Conn List)格​式​为​ ip-port-connectionid
mysql> DBSCALE SHOW USER STATUS 5;
User_id Working State Extra Info Kept Conn List
5 in-transaction test 192.168.122.13-3306-9;192.168.122.14-3306-10;

7.3.14. 查​看​用​户​锁​表​状​态​

DBScale 可​以​通​过​命​令​
dbscale show lock usage
查​看​用​户​锁​表​状​态​,主​要​包​含​ User_id,User_info,被​锁​表​的​名​字​,锁​的​类​型​以​及​引​起​锁​表​的​操​作​语​句​。​目​前​只​支​持​ lock tables,unlock tables 引​起​的​锁​表​状​态​显​示​。​
mysql> DBSCALE SHOW LOCK USAGE;
User_id User_info Lock_tables Lock_operation
159 root@127.0.0.1:47533 t write lock tables
t1 read

7.3.15. 查​看​ innodb/tokudb 锁​等​待​

DBScale 可​以​通​过​命​令​
DBSCALE SHOW INNODB_LOCK_WAITING STATUS
或​者​
DBSCALE SHOW TOKUDB_LOCK_WAITING STATUS
查​看​ innodb/tokudb 事​务​锁​情​况​,主​要​包​括​当​前​等​待​的​ query ,阻​塞​的​ query 以​及​被​上​锁​的​表​ 。​
mysql> DBSCALE SHOW INNODB_LOCK_WAITING STATUS;
mysql> DBSCALE SHOW TOKUDB_LOCK_WAITING STATUS;
server_id waiting_query blocking_query lock_table
13310 SELECT c2 FROM t1 FOR UPDATE SELECT SLEEP(20) `test`.`t1`
13313 SELECT a2 FROM t1 FOR UPDATE SELECT SLEEP(20) `test`.`t1`

7.3.16. 查​看​上​一​条​语​句​的​执​行​时​间​细​节​

DBScale 可​以​通​过​命​令​
dbscale show execution profile
查​看​上​一​条​语​句​的​各​个​步​骤​执​行​消​耗​时​间​,主​要​包​含​ ProfileId,ExecuteNode,MonitorPoint,StartTime,EndTime,CostTime,SerialInfo,ExtraInfo。​消​耗​时​间​的​单​位​为​ms。​ExecuteNode是​具​体​哪​一​个​Node的​名​字​, SerialInfo指​的​是​某​段​代​码​是​并​行​还​是​串​行​,MonitorPoint是​标​识​代​码​段​的​,ExtraInfo是​一​些​辅​助​显​示​信​息​。​
此​功​能​默​认​是​关​闭​的​,可​以​通​过​
DBSCALE SET execute_profile=1
开​启​此​功​能​,通​过​
DBSCALE SET execute_profile=0
关​闭​此​功​能​。​
mysql> DBSCALE SHOW EXECUTION PROFILE;
ProfileId ExecuteNode MonitorPoint StartTime EndTime CostTime SerialInfo ExtraInfo
0 MySQLSendNode SendNode all 12:9:18 12:9:18 4 serial
1 MySQLSendNode SendNode init 12:9:18 12:9:18 0 serial
2 MySQLFetchNode par1 12:9:18 12:9:18 2 parallel (select * from part_table)
3 MySQLFetchNode par1 12:9:18 12:9:18 3 parallel (select * from part_table2)
4 MySQLFetchNode par2 12:9:18 12:9:18 1 parallel (select * from part_table)
5 MySQLFetchNode par2 12:9:18 12:9:18 3 parallel (select * from part_table2)
6 MySQLUnionAllNode SendNode init 12:9:18 12:9:18 0 serial iterator 2
7 MySQLSendNode SendNode send packet 12:9:18 12:9:18 0 serial

7.3.17. 查​看​连​接​池​状​态​

DBScale 可​以​通​过​命​令​
dbscale show connection pool [server_name]
查​看​连​接​池​状​态​,主​要​包​括​对​应​ data_server 和​ data_source 的​名​字​,连​接​池​被​使​用​的​连​接​的​数​量​,空​闲​的​连​接​的​数​量​,死​掉​的​连​接​的​数​量​以​及​连​接​的​总​量​。​dbscale show connection pool 查​看​所​有​ data_server 对​应​连​接​池​的​状​态​,dbscale show connection pool server_name 查​看​名​字​叫​ server_name 的​ data_server 对​应​的​连​接​池​信​息​。​
mysql> DBSCALE SHOW CONNECTION POOL;
Server_name Pool_name Used Free Dead Total Handler_times/s Handler_times/10m Handler_times/m
auth_server auth 1 9 0 10 1 2 10
part1 ds_part1 1 11 0 12 2 5 19
part2 ds_part2 2 14 0 16 1 4 9
single single 0 1 0 1 0 0 0
mysql> DBSCALE SHOW CONNECTION POOL PART1;
Server_name Pool_name Used Free Dead Total Handler_times/s Handler_times/10s Handler_times/m
part1 ds_part1 1 11 0 12 1 2 10

7.3.18. 查​看​连​接​池​版​本​

DBScale 可​以​通​过​命​令​
dbscale show version connection pool [pool_name]
查​看​连​接​池​版​本​,主​要​包​括​对​应​连​接​池​的​名​字​和​版​本​,连​接​池​内​连​接​的​地​址​和​版​本​。​dbscale show version connection pool 查​看​所​有​连​接​池​的​版​本​,dbscale show version connection pool pool_name 查​看​名​字​叫​ pool_name 的​连​接​池​版​本​。​
mysql> DBSCALE SHOW VERSION CONNECTION POOL;
pool name pool version connection connection version      
auth 1 0x7f5424018960 1      
ds_part1 1 0x7f5424019f00 0      
ds_part2 2 0x7f542401b4a0 0      
mysql> DBSCALE SHOW VERSION CONNECTION POOL DS_PART1;
pool name pool version connection connection version      
ds_part1 1 0x7f542401f580 0      

7.3.19. 查​看​线​程​池​状​态​

DBScale 可​以​通​过​命​令​
dbscale show thread pool info
查​看​线​程​池​状​态​,主​要​包​括​对​应​线​程​池​标​志​和​ thread_pool 的​名​字​,线​程​池​被​使​用​的​线​程​的​数​量​,空​闲​的​线​程​的​数​量​,死​掉​的​线​程​的​数​量​以​及​线​程​的​总​量​。​dbscale show thread pool info 查​看​线​程​池​的​状​态​。​
mysql> DBSCALE SHOW THREAD POOL INFO;
Thread_pool Pool_name Used Free Dead Total Handler_times/s Handler_times/10m Handler_times/m
THREAD Thread_Pool 7 23 0 30 6 7 7

7.3.20. 查​看​ SQL 语​句​的​预​估​影​响​行​数​

DBScale提​供​了​DBSCALE ESTIMATE 命​令​来​评​估​待​执​行​的​SQL语​句​的​影​响​行​数​。​
DBScale可​以​支​持​的​预​估​影​响​行​数​的​SQL语​句​包​括​有​ SELECT 语​句​,UPDATE 语​句​,DELETE 语​句​,INSERT...SELECT 语​句​。​这​些​语​句​中​不​能​包​含​跨​节​点​ join,有​跨​节​点​join的​语​句​暂​不​支​持​。​
mysql> DBSCALE ESTIMATE SELECT * FROM part_table;

7.3.21. 查​看​后​端​工​具​线​程​

DBScale 可​以​通​过​命​令​
mysql> DBSCALE SHOW BACKEND_THREADS
查​看​所​有​ DBScale 工​具​线​程​。​

7.3.22. 查​看​指​定​表​分​片​信​息​

DBSCALE SHOW PARTITIONS FROM tbl_name;
根​据​表​名​显​示​表​的​分​片​信​息​。​对​于​分​片​表​,显​示​序​列​号​,分​片​方​式​,分​片​表​达​式​,分​片​关​联​的​ data-source 信​息​;对​于​非​分​片​表​,显​示​提​示​为​非​分​片​表​,并​显​示​关​联​的​ data-source。​
字​段​名​ 描​述​
Sequence 序​列​号​
Type 分​片​方​式​(可​选​值​ hash/range/list)
Expresion 相​应​分​片​方​式​所​对​应​的​表​达​式​
Data Source 各​分​片​关​联​的​ data-source

7.3.23. 查​看​一​个​指​定​分​区​表​的​信​息​

可​以​通​过​命​令​
DBSCALE SHOW PARTITION TABLE STATUS FOR table_name;
命​令​查​看​分​区​表​的​相​关​信​息​。​
  1. DBSCALE SHOW PARTITION TABLE STATUS FOR table_name;
    schema table partition_key_column partition_key_pos auto_increment_key auto_increment_key_pos auto_increment_key_base_value virtual_map original_layout shard_map
    test partition_tb c1 1 c2 3 20 0:1:2:3:4:5:0:1:2:3:4:5:0:1:2:3:4:5:0:1:2:3:4:5 true ds_par1:0:2:4-ds_par2:1:3:5

7.3.24. 查​看​SHARD分​片​表​SHARD分​片​分​布​

DBScale 可​以​通​过​命​令​
DBSCALE SHOW PARTITION TABLE table_name SHARD MAP
查​看​SHARD分​片​表​SHARD分​片​分​布​,如​果​该​分​片​表​是​一​个​ SHARD 表​, 通​过​该​命​令​可​以​看​到​当​前​ SHARD 分​片​的​分​布​.
DBSCALE SHOW PARTITION TABLE table_name SHARD MAP;
option
[partition-scheme ds_par2:1:3:5:4:2-ds_par1:0]
ds_par2:1:3:5:4:2
ds_par1:0

7.3.25. 查​看​分​片​表​虚​拟​分​片​分​布​

DBScale 可​以​通​过​命​令​
DBSCALE SHOW PARTITION TABLE table_name VIRTUAL MAP
查​看​分​片​表​虚​拟​分​片​分​布​,包​括​该​分​片​表​当​前​的​分​片​策​略​和​虚​拟​分​片​分​布​。​
DBSCALE SHOW PARTITION TABLE table_name VIRTUAL MAP;
option
[partition-scheme part_ds_mig]
partition = ds_par1
partition = ds_par2
partition = ds_mig
[table test.table_name]
virtual-map = ds_par1:2:5:6
virtual-map = ds_par2:1:7
virtual-map = ds_mig:0:3:4

7.3.26. 查​看​所​有​的​shard分​片​表​

可​以​通​过​命​令​
DBScale SHOW SHARD PARTITION TABLES
命​令​查​看​所​有​的​shard 分​片​表​。​
  1. mysql> DBScale SHOW SHARD PARTITION TABLES;
    Table Scheme RealPartitions Shards
    test.partition_tb part 2 6
同​时​可​以​在​命​令​的​最​后​指​定​一​个​partition scheme的​名​字​来​查​看​该​partition scheme的​所​有​shard分​片​表​。​
mysql> DBSCALE SHOW SHARD PARTITION TABLES part;

7.3.27. 查​看​未​自​动​恢​复​的​故​障​分​布​式​事​务​信​息​

可​以​通​过​命​令​
DBSCALE SHOW FAIL TRANSACTION
查​看​目​前​集​群​中​部​分​提​交​的​分​布​式​事​务​汇​总​。​
  1. mysql> DBSCALE SHOW FAIL TRANSACTION;
    Xid RelatedSource FailSource  
    11 ds_par1:ds_par2 ds_par2  
Xid标​识​部​分​提​交​的​分​布​式​事​务​编​号​,全​局​唯​一​。​RelatedSource标​识​该​分​布​式​事​务​涉​及​到​的​集​群​数​据​源​。​FailSource标​识​出​提​交​失​败​的​数​据​源​。​
可​以​通​过​命​令​
DBSCALE SHOW DETAIL FAIL TRANSACTION "xid"
查​看​具​体​一​个​部​分​提​交​的​分​布​式​事​务​提​交​失​败​的​集​群​redo日​志​信​息​。​
  1. mysql> DBSCALE SHOW DETAIL FAIL TRANSACTION "11";
    FailSource XidMachine RedoSQL  
    ds_par2 14-4 use `test`;  
    ds_par2 14-4 insert into part_table values(101);  
FailSource出​现​提​交​失​败​的​数​据​源​。​XidMachine标​识​该​分​布​式​事​务​在​该​数​据​源​上​的​shard信​息​,分​片​表​在​一​个​数​据​源​上​可​能​有​多​个​shard,每​个​shard的​分​布​式​事​务​是​独​立​提​交​的​。​RedoSQL标​识​出​失​败​事​务​的​sql语​句​,从​上​到​下​为​执​行​顺​序​。​

7.3.28. 查​看​跨​节​点​ JOIN 相​关​状​态​。​

DBScale 可​以​通​过​命​令​
DBSCALE SHOW JOIN STATUS {name}"
查​看​跨​节​点​ JOIN 相​关​状​态​。​
  1. 通​过​
    DBSCALE SHOW JOIN STATUS hotspot
    查​看​每​个​ server 上​临​时​表​的​使​用​次​数​。​
    mysql> DBSCALE SHOW JOIN STATUS hotspot;
    Servers Read-Write Times
    auth_server 0
    master 45
    par1 44
    par2 48

7.3.29. 查​看​等​待​清​理​的​ SHARD 表​

DBScale 通​过​命​令​
DBSCALE SHOW MIGRATE CLEAN TABLES;
进​行​查​看​有​那​些​表​需​要​清​理​。​
mysql> DBSCALE SHOW MIGRATE CLEAN TABLES;
+------+---------------------+-------------+-------------------------------------+-------------+
| id   | table_name          | schema_name | clean_table_name                    | source_name |
+------+---------------------+-------------+-------------------------------------+-------------+
| 4    | part_table_pattern7 | test        | test.part_table_pattern7_DM_8564484 | ds_par1     |
+------+---------------------+-------------+-------------------------------------+-------------+
结​果​中​ id 为​清​理​编​号​, 用​于​清​理​命​令​指​定​清​理​那​条​记​录​。​
结​果​中​ table_name 列​为​原​表​名​。​
结​果​中​ schema_name 列​为​原​库​名​。​
结​果​中​ clean_table_name 为​原​ shard 表​重​命​名​后​的​表​名​, 以​ _DM_[int] 结​尾​,标​识​这​是​ DBScale 重​命​名​的​表​,用​户​在​使​用​时​不​能​以​ ​_DM_[int] 来​作​为​分​片​表​的​表​名​结​尾​。​
结​果​中​ source_name 为​使​用​数​据​源​的​名​字​, 用​于​标​识​去​那​个​数​据​源​进​行​清​理​。​

7.3.30. 查​看​用​户​是​否​具​有​执​行​ DDL 语​句​的​权​限​

可​以​通​过​命​令​
DBSCALE SHOW [ALL] ALLOW DDL USER
查​看​当​前​用​户​是​否​具​有​执​行​ DDL 语​句​的​权​限​。​只​有​ root 用​户​能​够​执​行​含​有​ ALL 参​数​的​该​命​令​,当​包​含​ ALL 参​数​时​,命​令​结​果​集​是​ DBScale 集​群​内​具​有​执​行​ DDL 语​句​权​限​的​用​户​名​列​表​。​
命​令​示​例​如​下​:
mysql> dbscale show allow ddl user;
+-------------------+
| is_user_allow_ddl |
+-------------------+
| YES               |
+-------------------+
1 row in set (0.00 sec)

mysql> dbscale show all allow ddl user;
+----------------------+
| users_allow_ddl_stmt |
+----------------------+
| dbscale              |
| root                 |
| user1                |
+----------------------+
3 rows in set (0.00 sec)

7.3.31. 查​看​库​级​别​权​限​设​置​

可​以​通​过​如​下​命​令​查​看​当​前​ session 内​用​户​的​库​级​别​权​限​设​置​:
DBSCALE SHOW ACL SCHEMA INFO
schema_name schema_acl_type
db1 no_touch
db2 read_only
db3 writable
db4 read_only
root 和​ dbscale 两​个​用​户​还​可​以​通​过​如​下​命​令​查​看​整​个​ DBScale 集​群​内​所​有​用​户​的​库​级​别​权​限​设​置​。​
DBSCALE SHOW ALL ACL SCHEMA INFO
user_name schema_name schema_acl_type
dbscale1 db1 no_touch
dbscale1 db2 read_only
dbscale2 db3 writable
dbscale3 db4 read_only

7.3.32. 查​看​表​级​别​权​限​设​置​

可​以​通​过​如​下​命​令​查​看​当​前​ session 内​用​户​的​表​级​别​权​限​设​置​:
DBSCALE SHOW ACL TABLE INFO
full_table_name table_acl_type
db1.tb1 no_touch
db2.tb1 read_only
db3.tb2 writable
db4.tb4 read_only
root 和​ dbscale 两​个​用​户​还​可​以​通​过​如​下​命​令​查​看​整​个​ DBScale 集​群​内​所​有​用​户​的​表​级​别​权​限​设​置​。​
DBSCALE SHOW ALL ACL TABLE INFO
user_name full_table_name table_acl_type
dbscale1 db1.tb1 no_touch
dbscale1 db2.tb1 read_only
dbscale2 db3.tb2 writable
dbscale3 db4.tb4 read_only

7.3.33. 查​看​当​前​ dbscale swap工​作​线​程​组​运​行​状​况​

可​以​通​过​命​令​
DBSCALE SHOW EVENT BASE STATUS;
查​看​dbscale集​群​ swap 工​作​线​程​组​的​运​行​状​况​,便​于​系​统​管​理​员​分​析​诊​断​问​题​。​只​有​在​开​启​swap模​式​enable-session-swap时​该​命​令​才​有​意​义​。​
Id BindClient BindServer CountServer CountClient CountTimeout CountListener WaitSize WorkSize ReadySize LatestEventHandle LatestEventAdd CountObtain CountAssign CountUnAssign CountIncMax
0 1 1 11 12 20 0 0 0 0 2 3 2 2 23 1
该​命​令​的​输​出​的​行​数​由​参​数​handler-thread-pool-num控​制​,每​个​swap线​程​组​一​行​。​
Id 是​swap工​作​线​程​组​编​号​,BindClient是​绑​定​到​这​个​组​的​客​户​端​socket数​量​,BindServer是​绑​定​到​这​个​组​的​服​务​端​socket的​数​量​,CountServer是​server socket可​读​事​件​处​理​次​数​,CountClient是​client socket可​读​事​件​处​理​次​数​,CountTimeout是​在​每​次​检​测​间​隔​中​超​时​而​没​有​检​测​到​任​何​可​读​socket的​次​数​,CountListener是​每​个​组​listener线​程​参​与​服​务​的​次​数​,WaitSize是​等​待​加​入​监​听​队​列​的​socket的​数​量​,WorkSize当​前​监​听​队​列​的​socket的​数​量​,ReadySize是​可​读​待​处​理​的​socket数​量​,LatestEventHandle是​最​近​一​次​处​理​过​程​中​发​现​的​可​读​socket数​量​,LatestEventAdd是​最​近​一​次​从​等​待​队​列​加​入​监​听​队​列​的​socket数​量​,CountObtain是​空​闲​控​制​线​程​自​动​从​ready列​表​中​获​取​可​读​socket的​次​数​,CountAssign是​listener线​程​从​ready列​表​中​分​配​socket到​空​闲​工​作​线​程​的​次​数​,CountIncMax是​dbscale检​测​到​该​swap线​程​组​阻​塞​而​动​态​新​增​可​用​线​程​的​次​数​。​
其​中​CountIncMax是​DBA管​理​员​最​需​要​关​注​的​,該​值​的​增​加​,特​别​是​频​繁​的​增​加​,表​明​dbscale集​群​的​swap模​式​在​当​前​业​务​场​景​下​工​作​不​正​常​,经​常​性​出​现​无​可​用​空​闲​工​作​线​程​,需​要​人​工​介​入​分​析​原​因​。​

7.3.34. 查​看​当​前​ DBScale 在​运​行​过​程​中​记​录​到​的​最​近​10条​比​较​重​要​的​警​告​。​

DBScale 可​以​通​过​命​令​
DBSCALE SHOW WARNINGS
来​查​看​当​前​ DBScale 实​例​在​运​行​过​程​中​记​录​到​的​最​近​10条​比​较​重​要​的​警​告​信​息​。​

7.3.35. 查​看​某​张​自​增​分​片​表​的​当​前​自​增​值​。​

DBScale 可​以​通​过​命​令​
DBSCALE SHOW AUTO_INCREMENT OFFSET FOR table_name;
来​查​看​当​前​ DBScale 实​例​在​运​行​过​程​中​某​张​自​增​分​片​表​的​当​前​自​增​值​。​
对​于​新​创​建​的​自​增​表​,无​法​查​看​自​增​值​,需​要​进​行​插​入​后​才​能​执​行​该​命​令​.

7.3.36. 查​看​消​息​订​阅​平​台​ server 任​务​状​态​

7.3.37. 查​看​消​息​订​阅​平​台​ client 任​务​状​态​

7.3.38. 查​看​消​息​订​阅​平​台​ server 任​务​关​联​的​所​有​ client 任​务​的​状​态​

7.3.39. 查​看​schema数​据​域​

DBScale 可​以​通​过​命​令​
DBSCALE SHOW SCHEMA DATASPACE [schema_name]"
查​看​集​群​的​schema数​据​域​配​置​。​
该​命​令​的​输​出​包​含​5个​字​段​,分​别​为​库​名​,该​库​的​存​储​过​程​是​否​下​推​执​行​,该​库​是​否​为​外​部​别​名​库​,该​库​对​应​的​外​部​别​名​库​名​,以​及​该​库​目​前​包​含​的​表​数​据​空​间​数​。​
关​于​“​is_alias”​和​“​alias_schema”​,可​以​参​考​第 5.1 节 “数​据​导​入​”中​的​第​4种​导​入​方​式​说​明​。​
关​于​“​pushdown_sp”​可​以​参​考​参​数​pushdown-stored-procedure [schema]。​
  1. scheme_name pushdown_sp is_alias alias_schema table_space_num
    test 1 0 3
    test2 0 1 db1 0

7.4. DBSCALE DYNAMIC 语​句​

DBScale 的​动​态​调​整​命​令​可​能​会​使​得​运​行​时​的​集​群​拓​扑​等​信​息​与​启​动​ DBScale 时​的​配​置​文​件​信​息​不​一​致​,这​时​就​需​要​及​时​地​手​动​调​整​配​置​文​件​,或​者​通​过​第 7.10.5 节 “保​存​ DBScale 的​配​置​信​息​”命​令​将​最​新​的​运​行​时​配​置​信​息​保​存​到​配​置​文​件​。​

7.4.1. 在​线​动​态​添​加​一​个​数​据​节​点​

DBScale 通​过​命​令​
DBSCALE DYNAMIC ADD DATASERVER SERVER_NAME=name, SERVER_HOST="host", SERVER_USER="user"[,SERVER_PASSWORD="password"]
进​行​在​线​动​态​添​加​一​个​数​据​节​点​。​参​数​都​是​字​符​串​类​型​,密​码​可​以​给​出​也​可​以​不​给​出​,不​给​出​则​默​认​为​空​。​
动​态​修​改​的​节​点​,需​要​手​动​将​动​态​配​置​持​久​化​到​配​置​文​件​中​,否​则​如​果​DBScale重​启​后​会​出​现​topo不​一​致​.
mysql> DBSCALE DYNAMIC ADD DATASERVER
       SERVER_NAME=server1,
       SERVER_HOST="127.0.0.1",
       SERVER_PORT=13001,
       SERVER_USER=root,
       SERVER_PASSWORD="";

7.4.2. 在​线​动​态​删​除​一​个​数​据​节​点​

DBScale 通​过​命​令​
DBSCALE DYNAMIC REMOVE DATASERVER server_name
进​行​在​线​动​态​删​除​一​个​数​据​节​点​。​
动​态​修​改​的​节​点​,需​要​手​动​将​动​态​配​置​持​久​化​到​配​置​文​件​中​,否​则​如​果​DBScale重​启​后​会​出​现​topo不​一​致​.
mysql> DBSCALE DYNAMIC REMOVE DATASERVER SERVER1;

7.4.3. 在​线​动​态​添​加​数​据​源​

DBScale 通​过​命​令​
DBSCALE DYNAMIC ADD SERVER DATASOURCE source_name, server_name-min-max-low-high [GROUP_ID = INTNUM]
在​线​添​加​一​个​SERVER类​型​的​数​据​源​。​
动​态​修​改​的​节​点​,需​要​手​动​将​动​态​配​置​持​久​化​到​配​置​文​件​中​,否​则​如​果​DBScale重​启​后​会​出​现​topo不​一​致​.
mysql> dbscale dynamic add server datasource single server1-1-2-1-1 GROUP_ID=1;
DBScale 通​过​命​令​
DBSCALE DYNAMIC ADD READ_ONLY DATASOURCE source_name, server_name-min-max-low-high [GROUP_ID = INTNUM]
在​线​添​加​一​个​READ_ONLY类​型​的​数​据​源​。​
mysql> dbscale dynamic add read_only datasource single server1-1-2-1-1 GROUP_ID=2;
DBScale 通​过​命​令​
DBSCALE DYNAMIC ADD RWSPLIT DATASOURCE source_name master=server_name-min-max-low-high slave=server_name-min-max-low-high [slave...] [GROUP_ID = INTNUM]
在​线​添​加​一​个​RWSPLIT类​型​的​数​据​源​。​slave列​表​可​以​给​出​多​个​。​
mysql> dbscale dynamic add rwsplit datasource rw_source master=server1-1-2-1-1 slave=server2-1-2-1-1 GROUP_ID=3;
DBScale 通​过​命​令​
DBSCALE DYNAMIC ADD REPLICATION DATASOURCE source_name master=server_name-min-max-low-high slave=server_name-min-max-low-high [slave...] [GROUP_ID = INTNUM]
在​线​添​加​一​个​REPLICATION类​型​的​数​据​源​。​slave列​表​可​以​给​出​多​个​。​
mysql> dbscale dynamic add replication datasource rep_source master=server1-1-2-1-1  slave=server2-1-2-1-1 GROUP_ID=4;
DBScale 通​过​命​令​
DBSCALE DYNAMIC ADD SHARE_DISK DATASOURCE source_name active=server_name-min-max-low-high cold_standby=server_name-min-max-low-high [GROUP_ID = INTNUM]
在​线​添​加​一​个​SHARE_DISK类​型​的​数​据​源​。​
mysql> dbscale dynamic add share_disk datasource sd_source active=server1-1-2-1-1 cold_standby=server2-1-2-1-1;
DBScale 通​过​命​令​
DBSCALE DYNAMIC ADD LOAD_BALANCE DATASOURCE source_name server=server_name-min-max-low-high [server...] [GROUP_ID = INTNUM]
在​线​添​加​一​个​LOAD_BALANCE类​型​的​数​据​源​。​server列​表​可​是​是​多​个​。​
mysql> dbscale dynamic add load_balance datasource lb_source server=server1-1-2-1-1 server=server2-1-2-1-1;

7.4.4. 在​线​删​除​数​据​源​

DBScale 通​过​命​令​
DBSCALE DYNAMIC REMOVE DATASOURCE source_name;
在​线​删​除​一​个​数​据​源​。​
mysql> dbscale dynamic remove datasource single2;
目​前​只​支​持​在​线​删​除​ server 或​ replication的​数​据​源​。​

7.4.5. 在​线​动​态​添​加​数​据​空​间​

DBScale 通​过​命​令​
DBSCALE DYNAMIC ADD SCHEMA DATASPACE schema_name DATASOURCE=source_name [alias_real_name] [WITH PUSHDOWN_PROCEDURE]
在​线​添​加​一​个​SCHEMA类​型​的​数​据​空​间​。​
alias_real_name参​数​用​于​设​置​该​schema的​运​行​时​替​换​的​名​字​,该​参​数​只​有​在​数​据​迁​移​时​才​会​用​到​,通​常​不​配​置​,关​于​使​用​alias schema进​行​数​据​迁​移​参​考​章​节​第 5 章 数​据​导​入​导​出​。​
WITH PUSHDOWN_PROCEDURE 用​于​设​置​该​schema的​ pushdown-stored-procedure 参​数​,默​认​为​0, 具​体​请​参​考​章​节​pushdown-stored-procedure [schema]。​
动​态​修​改​的​节​点​,需​要​手​动​将​动​态​配​置​持​久​化​到​配​置​文​件​中​,否​则​如​果​DBScale重​启​后​会​出​现​topo不​一​致​.
mysql> dbscale dynamic add schema dataspace test datasource="single1";
DBScale 通​过​命​令​
DBSCALE DYNAMIC ADD NORMAL_TABLE DATASPACE schema.table [PATTERN = "name_pattern"] DATASOURCE=source_name
在​线​添​加​一​个​NORMAL_TABLE类​型​的​数​据​空​间​。​新​加​表​是​否​为​正​则​可​选​,表​名​必​须​被​双​引​号​包​含​。​
mysql> dbscale dynamic add normal_table  dataspace test.norm_table datasource = rep_part2;
mysql> dbscale dynamic add normal_table  dataspace "test.norm" pattern = "norm.*" datasource = rep_part2;
DBScale 通​过​命​令​
DBSCALE DYNAMIC ADD HASH_TYPE PARTITION_SCHEME scheme_name PARTITION=par_name [PARTITION=par_nam...] [hash_type_str] [IS_SHARD] [SHARD_NUMS shard_nums]
或​者​命​令​
DBSCALE DYNAMIC ADD MOD_TYPE PARTITION_SCHEME scheme_name PARTITION=par_name [PARTITION=par_nam...] [NOT_SIMPLE] [IS_SHARD] [SHARD_NUMS shard_nums]
在​线​添​加​一​个​PARTITION_SCHEME数​据​空​间​。​用​于​添​加​分​片​表​使​用​。​目​前​只​支​持​在​线​添​加​hash 或​mod 类​型​的​partition_scheme。​
注​:hash_type_str的​值​,参​考​配​置​一​章​中​,hash partition-scheme中​的​说​明​,默​认​值​为​ "CHAR" 。​
mysql> dbscale dynamic add hash_type partition_scheme par partition=sd_part1 partition=rep_part2;
mysql> dbscale dynamic add hash_type partition_scheme par partition=sd_part1 partition=rep_part2 is_shard shard_nums 3;
“​par”​为​新​建​partition_scheme的​名​字​,hash_type表​明​分​片​算​法​为​hash,该​命​令​通​过​partition=name来​指​定​这​个​partiton_scheme所​包​含​的​分​片​信​息​,每​个​分​片​partition需​要​关​联​到​一​个​datasource的​名​字​,即​命​令​中​的​sd_part1和​rep_part2都​是​一​个​已​经​配​置​好​的​datasource的​名​字​,is_shard 为​是​否​是​shard partition,即​是​否​允​许​在​同​一​个​mysql实​例​内​部​部​署​多​个​分​片​,shard_nums 表​示​每​个​物​理​分​区​上​有​几​个​shard分​区​,当​ shard_nums 为​ 0 或​者​不​指​定​时​,新​建​立​的​ partition_scheme 的​ shard_nums 的​值​将​被​设​置​为​所​指​定​的​ partition 个​数​ * 3。​
DBScale 通​过​命​令​
DBSCALE DYNAMIC ADD PARTITION_TABLE DATASPACE schema.table [PATTERN = "name_pattern"] PARTITION_KEY=key_name PARTITION_SCHEME=scheme_name
在​线​添​加​一​个​分​片​表​数​据​空​间​。​新​增​分​片​表​的​分​片​算​法​取​决​于​所​指​定​的​partition_scheme的​分​片​算​法​。​新​加​表​是​否​为​正​则​可​选​,表​名​必​须​被​双​引​号​包​含​。​
mysql> dbscale dynamic add partition_table dataspace test.t1 partition_key=c1 partition_scheme=par;
mysql> dbscale dynamic add partition_table dataspace test.t1 pattern= "t.*" partition_key=c1 partition_scheme=par;

7.4.6. 在​线​为​主​从​集​群​添​加​ Slave 节​点​

DBScale 可​以​通​过​命​令​
DBSCALE DYNAMIC ADD SLAVE server-min-max-low-high TO replication_source_name
在​线​动​态​为​ DBScale 主​从​复​制​集​群​添​加​ Slave 从​节​点​。​
动​态​修​改​的​节​点​,需​要​手​动​将​动​态​配​置​持​久​化​到​配​置​文​件​中​,否​则​如​果​DBScale重​启​后​会​出​现​topo不​一​致​.
在​使​用​这​个​命​令​之​前​请​确​保​ slave 已​经​可​以​正​常​的​与​ master 进​行​主​从​复​制​工​作​并​且​延​迟​很​小​。​这​个​命​令​仅​仅​是​将​指​定​的​ slave 添​加​到​集​群​中​。​在​添​加​之​前​请​确​保​server信​息​已​经​存​在​于​ DBScale 中​了​。​
mysql> dbscale dynamic add slave server1-1-2-1-1 to rep;
添​加​成​功​后​可​以​通​过​ dbscale show datasource name 命​令​查​看​是​否​添​加​成​功​。​

7.4.7. 在​线​从​主​从​集​群​删​除​ Slave 节​点​

DBScale 可​以​通​过​命​令​
DBSCALE DYNAMIC REMOVE SLAVE slave_name FROM  master_name
在​线​动​态​为​ DBScale 从​主​从​复​制​集​群​删​除​ Slave 从​节​点​。​
动​态​修​改​的​节​点​,需​要​手​动​将​动​态​配​置​持​久​化​到​配​置​文​件​中​,否​则​如​果​DBScale重​启​后​会​出​现​topo不​一​致​.
与​ DBSCALE DYNAMIC ADD SLAVE 配​合​使​用​用​于​在​线​升​级​使​用​。​手​动​升​级​步​骤​如​下​:
1. 使​用​ dbscale dynamic remove slave 命​令​删​除​要​升​级​的​节​点​,手​动​停​止​主​从​关​系​,然​后​对​该​节​点​进​行​升​级​;
2. 步​骤​1中​的​节​点​升​级​后​,重​启​主​从​关​系​一​直​等​到​与​主​节​点​一​致​且​延​迟​比​较​小​;
3. 使​用​ dbscale dynamic add slave 命​令​添​加​升​级​完​成​的​节​点​到​集​群​。​
mysql> dbscale dynamic remove slave slave1 from rep;
删​除​成​功​后​可​以​通​过​ dbscale show datasource name 命​令​查​看​是​否​删​除​成​功​。​
需​要​注​意​,如​果​在​删​除​过​程​中​,slave节​点​有​连​接​正​在​被​使​用​,则​此​命​令​会​一​直​等​待​至​到​slave节​点​的​没​有​连​接​被​使​用​为​止​。​因​此​建​议​在​使​用​此​命​令​之​前​,请​使​用​ DBSCALE SHOW CONNECTION POOL 命​令​保​证​slave节​点​没​有​连​接​正​在​被​使​用​或​使​用​的​压​力​较​低​。​

7.4.8. 在​线​手​动​进​行​主​从​切​换​

DBScale 可​以​通​过​命​令​
DBSCALE DYNAMIC CHANGE MASTER master TO new_master
进​行​在​线​手​动​主​从​切​换​。​
在​使​用​这​个​命​令​之​前​请​确​保​ new_master 已​经​可​以​正​常​的​与​ master 进​行​主​从​复​制​工​作​并​且​延​迟​很​小​,同​时​在​dbscale端​ new_master 要​求​是​ master 的​一​个​从​节​点​。​可​以​通​过​命​令​ DBSCALE SHOW DATASOURCE master 来​查​看​ new_master 是​否​在​ master 的​主​从​集​群​中​。​
DBScale 空​闲​时​才​会​进​行​主​从​切​换​,所​以​要​确​保​证​此​时​系​统​空​闲​或​不​是​很​繁​忙​。​
mysql> dbscale dynamic change master rep to slave1;
添​加​成​功​后​可​以​通​过​ dbscale show datasource name 命​令​查​看​是​否​添​加​成​功​。​

7.4.9. 在​线​设​置​ replication 数​据​源​ load_balance 策​略​

DBScale 可​以​在​线​设​置​ replication 数​据​源​的​ Load Balance 策​略​, 通​过​执​行​语​句​:
mysql> DBSCALE DYNAMIC SET LOAD_BALANCE_STRATEGY = "val" FOR data_source_name;
进​行​设​置​,其​中​ val 的​值​限​定​为​目​前​支​持​的​ SLAVES, MASTER, MASTER-SLAVES 3种​,data_source_name 对​应​的​数​据​源​必​须​为​ replication 类​型​。​

7.4.10. 在​线​调​整​ MultipleMaster 数​据​源​的​ active 节​点​

DBScale 可​以​通​过​命​令​
mysql> DBSCALE DYNAMIC CHANGE MULTIPLEMASTER 'multiple_master_source' ACTIVE TO 'multiple_master_source_lb_multiple_master_serverx'
在​线​动​态​将​ MultipleMaster 数​据​源​内​的​ Active 数​据​源​调​整​为​ 'multiple_master_source_lb_multiple_master_serverx'。​
动​态​修​改​后​,需​要​将​动​态​配​置​持​久​化​到​配​置​文​件​中​,否​则​ DBScale 重​启​后​会​出​现​ MultipleMaster 的​ Active 与​预​期​不​一​致​的​情​况​。​
添​加​成​功​后​可​以​通​过​
mysql> DBSCALE SHOW DATASOURCE name
命​令​查​看​是​否​添​加​成​功​。​

7.4.11. 在​线​动​态​删​除​一​个​分​片​策​略​

DBScale 通​过​命​令​
mysql> DBSCALE DYNAMIC REMOVE PARTITION_SCHEME scheme_name
进​行​在​线​动​态​删​除​一​个​分​片​策​略​。​
动​态​修​改​的​节​点​,需​要​手​动​将​动​态​配​置​持​久​化​到​配​置​文​件​中​,否​则​如​果​DBScale重​启​后​会​出​现​topo不​一​致​.

7.4.12. 在​线​调​整​数​据​源​内​某​个​ Server DataSource 的​权​重​

DBScale 通​过​命​令​
mysql> DBSCALE DYNAMIC SET DATASOURCE datasource_name SERVER server_name WEIGHT TO intnum
进​行​在​线​调​整​某​个​ scheduler-type=WEIGHT 的​数​据​源​内​的​某​个​ server datasource 的​权​重​。​
由​于​目​前​ DBScale 只​支​持​ RWSplit、​Replication、​Load_Balance类​型​的​数​据​源​配​置​其​内​部​的​轮​询​方​式​为​WEIGHT(即​ scheduler-type = weight),所​以​该​动​态​调​整​命​令​也​只​对​配​置​为​ scheduler-type = weight 的​ RWSplit、​Replication、​Load_Balance 类​型​的​数​据​源​起​作​用​。​
动​态​修​改​的​节​点​,需​要​手​动​将​动​态​配​置​持​久​化​到​配​置​文​件​中​,否​则​如​果​DBScale重​启​后​会​出​现​topo不​一​致​.

7.4.13. 在​线​调​某​张​自​增​分​片​表​的​自​增​值​

DBScale 通​过​命​令​
mysql> DBSCALE DYNAMIC SET table_name AUTO_INCREMENT OFFSET TO auto_increment_value;
进​行​在​线​调​整​某​某​张​自​增​分​片​表​的​自​增​值​。​
如​果​调​小​自​增​值​,而​后​端​数​据​库​表​中​已​经​有​大​于​给​定​的​值​的​数​据​行​,会​导​致​未​给​定​自​增​值​的​插​入​语​句​失​败​,可​能​报​错​该​自​增​值​已​经​存​在​。​建​议​使​用​该​命​令​时​调​大​自​增​值​.
对​于​新​创​建​的​自​增​表​,无​法​调​整​自​增​值​,需​要​进​行​插​入​后​才​能​执​行​该​命​令​.
在​多​ DBScale 模​式​下​,调​整​自​增​值​不​能​小​于​ DBScale 设​定​的​一​个​初​值​,否​则​报​错​.

7.4.14. 在​线​调​SCHEMA的​pushdown_procedure行​为​

DBScale 通​过​命​令​
mysql> DBSCALE SET SCHEMA schema_name PUSHDOWN_PROCEDURE = int;
进​行​在​线​调​整​schema的​pushdown_procedure配​置​。​参​考​pushdown-stored-procedure [schema]
设​置​ 0 表​示​关​闭​,非​0表​示​开​启​。​

7.4.15. 在​线​调​整​IP黑​白​名​单​

DBScale 通​过​命​令​
mysql> DBSCALE DYNAMIC ADD/REMOVE BLACK/WHITE ip
在​线​调​整​IP黑​白​名​单​。​语​句​中​的​ip需​要​用​引​号​括​起​来​。​
只​有​root和​dbscale两​个​用​户​有​权​限​执​行​该​语​句​。​

7.5. 数​据​迁​移​相​关​命​令​

7.5.1. 在​线​迁​移​数​据​

DBScale 通​过​命​令​
DBSCALE MIGRATE NO_PARTITION norm_table_name TO source_name,PARTITION part_table_name vid TO source_name[ vid TO source_name], SHARD part_table_name FROM source_name TO target_source_name, SPLIT part_table_name FROM source_name to target_source_name [target_source_name];
进​行​在​线​迁​移​数​据​,具​体​可​以​查​看​高​级​特​性​中​数​据​迁​移​部​分​。​
迁​移​命​令​主​要​有​4种​模​式​:
  1. 迁​移​非​分​片​表​: DBSCALE MIGRATE NO_PARTITION norm_table_name TO source_name;
  2. 迁​移​普​通​分​片​表​:DBSCALE MIGRATE PARTITION part_table_name vid TO source_name[ vid TO source_name]; 该​方​式​基​于​虚​拟​分​片​,目​前​以​不​推​荐​使​用​。​
  3. 迁​移​shard分​片​表​:DBSCALE MIGRATE SHARD part_table_name FROM source_name TO target_source_name; 推​荐​使​用​这​种​方​式​。​
  4. 分​裂​普​通​分​片​表​的​一​个​分​片​为​一​组​新​的​分​片​:DBSCALE MIGRATE SPLIT part_table_name FROM source_name to target_source_name [target_source_name]; 推​荐​使​用​这​种​方​式​。​
通​常​我​们​推​荐​使​用​shard 分​片​表​并​使​用​ DBSCALE MIGRATE SHARD 进​行​数​据​迁​移​。​对​于​非​shard的​普​通​分​片​表​,我​们​推​荐​使​用​ DBSCALE MIGRATE SPLIT 进​行​扩​展​。​
上​述​4种​方​式​在​同​一​条​命​令​中​可​以​混​合​使​用​,例​如​:
mysql> DBSCALE MIGRATE
       NO_PARTITION norm_table TO rep_source,
       PARTITION part_table 3 TO rep_source
                            4 to another_source
                            5 to rep_source,
       SHARD shard_part_table FROM source TO rep_source,
       SPLIT part_table_name from source_name to target_source_name1 target_source_name2;

7.5.2. 清​理​等​待​清​理​的​ SHARD 表​

DBScale 通​过​命​令​
DBSCALE CLEAN MIGRATE int_val
来​清​理​这​个​表​. 其​中​ INTNUM 是​第 7.3.29 节 “查​看​等​待​清​理​的​ SHARD 表​”返​回​结​果​中​的​ ID 列​。​
mysql> DBSCALE CLEAN MIGRATE 1;

7.6. DBScale 状​态​清​理​/刷​新​/重​置​命​令​

7.6.1. 刷​新​连​接​池​版​本​

DBScale 可​以​通​过​命​令​
dbscale flush [force] connection pool [pool_name]
刷​新​连​接​池​版​本​,当​使​用​的​连​接​放​回​连​接​池​时​,如​果​连​接​的​版​本​不​等​于​连​接​池​的​版​本​,会​将​这​条​连​接​回​收​。​dbscale flush connection pool 刷​新​所​有​连​接​池​的​版​本​,dbscale flush connection pool pool_name 刷​新​名​字​叫​ pool_name 的​连​接​池​版​本​。​如​果​带​有​ force 属​性​,DBScale会​立​即​刷​新​所​有​的​连​接​成​为​最​新​版​本​。​
mysql> dbscale flush [force] connection pool [auth];

7.6.2. 重​置​资​源​池​最​大​资​源​数​

DBScale 的​资​源​池​包​括​连​接​池​、​前​端​线​程​池​、​后​端​线​程​池​、​swap线​程​池​。​
连​接​池​主​要​用​于​保​存​后​端​连​接​,基​本​参​数​由​数​据​源​配​制​,由​参​数​conn-pool-num控​制​每​个​数​据​源​拥​有​的​连​接​池​数​目​,可​以​由​命​令​:dbscale show connection pool;查​看​。​
前​端​线​程​池​主​要​用​于​保​存​登​陆​线​程​,由​如​下​参​数​控​制​前​端​线​程​池​内​资​源​数​目​。​通​过​如​下​命​令​查​询​前​端​线​程​池​使​用​情​况​,其​中​“​LOGIN HANDLER THREAD”​就​是​前​端​线​程​池​。​在​开​启​swap模​式​后​,线​程​仅​仅​用​于​登​录​,登​录​后​由​swap线​程​池​服​务​客​户​请​求​。​在​关​闭​swap模​式​后​,前​端​线​程​池​内​的​线​程​既​用​于​登​录​,也​服​务​客​户​端​请​求​。​swap模​式​控​制​由​参​数​“​enable-session-swap”​控​制​。​
thread-pool-min 默认值为30
thread-pool-low 默认值为200
thread-pool-max 默认值为2048
查​询​线​程​池​命​令​
mysql> dbscale show thread pool info;
后​端​线​程​池​主​要​用​于​保​存​后​端​线​程​,由​如​下​参​数​控​制​后​端​线​程​池​内​资​源​数​目​。​通​过​如​下​命​令​查​询​后​端​线​程​池​使​用​情​况​,其​中​“​BACKEND THREAD”​就​是​后​端​线​程​池​。​
backend-thread-pool-min 默认值为10
backend-thread-pool-low 默认值为100
backend-thread-pool-max 默认值为2048
backend-thread-pool-num 后端线程池数目,默认值为1
swap线​程​池​主​要​用​于​保​存​swap线​程​,由​如​下​参​数​控​制​后​端​线​程​池​内​资​源​数​目​。​通​过​如​下​命​令​查​询​后​端​线​程​池​使​用​情​况​,其​中​“​HANDLER THREAD”​就​是​swap线​程​池​。​
handler-thread-pool-num 线程池数目,默认值为1
handler-thread-pool-min 默认值为2
handler-thread-pool-low 默认值为2
handler-thread-pool-max 默认值为100
对​四​种​资​源​池​进​行​最​大​资​源​数​修​改​需​要​遵​循​给​定​的​最​大​资​源​数​目​要​不​小​于​高​水​位​,不​小​于​当​前​最​大​值​,同​时​修​改​后​DBScale程​序​所​能​使​用​的​文​件​句​柄​总​数​小​于​操​作​系​统​给​定​的​ulimit -n。​
修​改​连​接​池​最​大​连​接​数​由​如​下​命​令​进​行​修​改​,可​以​同​时​修​改​所​有​连​接​池​,也​可​以​指​定​连​接​池​名​字​来​只​修​改​一​个​连​接​池​。​
mysql> DBSCALE RESET CONNECTION POOL [POOL_NAME] MAX_VALUE;
如​修​改​所​有​连​接​池​最​大​值​:
mysql> DBSCALE RESET CONNECTION POOL 50;
修​改​指​定​连​接​池​数​目​最​大​值​:
mysql> DBSCALE RESET CONNECTION POOL ds_catalog 50;
修​改​前​端​线​程​池​池​最​大​线​程​数​由​如​下​命​令​进​行​修​改​。​
mysql> DBSCALE RESET LOGIN HANDLER THREAD POOL MAX_VALUE;
如​:
mysql> DBSCALE RESET LOGIN HANDLER THREAD POOL 2000;
修​改​后​端​线​程​池​池​最​大​线​程​数​由​如​下​命​令​进​行​修​改​。​
mysql> DBSCALE RESET BACKEND THREAD POOL MAX_VALUE;
如​:
mysql> DBSCALE RESET BACKEND THREAD POOL 2000;
修​改​swap线​程​池​池​最​大​线​程​数​由​如​下​命​令​进​行​修​改​。​
mysql> DBSCALE RESET HANDLER THREAD POOL MAX_VALUE;
如​:
mysql> DBSCALE RESET HANDLER THREAD POOL 20;

7.6.3. 清​理​跨​节​点​ JOIN 临​时​表​

DBScale 可​以​通​过​命​令​
DBSCALE RESET TMP_TABLE;
清​理​跨​节​点​ JOIN 临​时​表​。​

7.6.4. 清​理​ zookeeper 中​的​配​置​文​件​相​关​信​息​

DBScale 可​以​通​过​命​令​
DBSCALE RESET ZOOKEEPER CONFIG INFO;
清​理​ zookeeper 中​的​配​置​文​件​相​关​信​息​。​此​命​令​只​能​在​ root用​户​下​执​行​。​

7.6.5. 清​理​未​自​动​恢​复​的​故​障​分​布​式​事​务​信​息​

可​以​通​过​命​令​
DBSCALE CLEAN FAIL TRANSACTION [xid_str]
清​理​目​前​集​群​中​部​分​提​交​的​分​布​式​事​务​信​息​。​
在​DBA通​过​第 7.3.27 节 “查​看​未​自​动​恢​复​的​故​障​分​布​式​事​务​信​息​”中​的​命​令​获​得​集​群​部​分​提​交​的​分​布​式​事​务​信​息​,并​根​据​集​群​redo日​志​进​行​人​工​补​偿​之​后​,可​以​使​用​该​命​令​清​理​所​有​的​部​分​提​交​的​分​布​式​事​务​信​息​或​指​定​xid字​符​串​进​行​清​理​。​

7.7. 异​步​操​作​管​理​命​令​

DBScale对​集​群​异​步​操​作​提​供​一​系​列​的​管​理​命​令​,目​前​主​要​管​理​的​异​步​操​作​主​要​包​括​:
本​小​节​中​介​绍​的​命​令​只​允​许​dbscale或​root账​户​操​作​。​

7.7.1. 查​看​异​步​操​作​命​令​

可​以​通​过​命​令​
DBSCALE SHOW ASYNC TASKS;
查​看​dbscale集​群​异​步​操​作​命​令​的​运​行​状​态​。​
Id Name State Progress StartTime Extra
1 DynamicChangeMaster_rep_MASTER_master EXEC 50 2017-3-8 6:59:6 Start to check master using connection.
State 可​能​的​值​包​括​:INIT、​EXEC、​SUSPEND、​CANCEL、​FIN、​ERROR。​

7.7.2. 异​步​操​作​控​制​

可​以​通​过​命​令​
DBSCALE SUSPEND ASYNC TASK task_id;
暂​停​一​个​处​于​EXEC状​态​异​步​操​作​任​务​。​
可​以​通​过​命​令​
DBSCALE CONTINUE ASYNC TASK task_id;
继​续​一​个​处​于​SUSPEND状​态​异​步​操​作​任​务​。​
可​以​通​过​命​令​
DBSCALE CANCEL ASYNC TASK task_id;
取​消​一​个​还​未​达​到​FIN或​ERROR状​态​异​步​操​作​任​务​。​
可​以​通​过​命​令​
DBSCALE DELETE ASYNC TASK task_id;
删​除​一​个​处​于​FIN或​ERROR或​CANCEL状​态​异​步​操​作​任​务​。​
task_id为​第 7.7.1 节 “查​看​异​步​操​作​命​令​”命​令​输​出​的​第​一​列​。​
异​步​操​作​的​管​理​也​是​异​步​的​,并​且​如​何​响​应​控​制​操​作​由​异​步​任​务​的​实​现​决​定​,某​些​情​况​下​控​制​操​作​可​能​会​被​忽​略​。​下​达​控​制​命​令​之​后​还​需​配​合​第 7.7.1 节 “查​看​异​步​操​作​命​令​”命​令​使​用​。​
目​前​迁​移​暂​不​支​持​ 除​ show 和​ delete 以​外​的​ 异​步​任​务​控​制​命​令​。​

7.8. 消​息​订​阅​平​台​相​关​命​令​

消​息​订​阅​平​台​全​部​管​理​命​令​,详​见​章​节​:消​息​订​阅​平​台​第 18 章 消​息​订​阅​平​台​。​

7.9. 多​dbscale集​群​相​关​命​令​

多​dbscale集​群​相​关​管​理​命​令​,详​见​章​节​第 19.4 节 “多​dbscale集​群​管​理​操​作​”。​

7.10. 其​他​管​理​命​令​

7.10.1. 默​认​ session 变​量​动​态​管​理​

DBScale提​供​了​
DBSCALE SHOW/ADD/REMOVE DEFAULT SESSION VARIABLES para_list
命​令​实​现​对​默​认​ session 变​量​的​动​态​管​理​功​能​。​
默​认​ session 变​量​是​ DBScale 用​户​连​接​的​会​话​变​量​,这​些​变​量​和​MySQL的​ session 变​量​一​一​对​应​。​若​设​置​了​某​个​默​认​ session 变​量​则​用​户​每​次​登​录​后​的​,该​ session 变​量​总​是​以​验​证​服​务​器​中​的​默​认​ session 变​量​做​初​始​化​。​未​配​置​默​认​值​的​ session 变​量​时​ DBScale 不​会​保​证​用​户​每​次​登​录​后​该​ session 变​量​不​会​改​变​。​所​以​,对​于​用​户​比​较​重​要​的​ session 变​量​,建​议​设​置​默​认​值​,这​些​默​认​的​ session 变​量​可​以​在​ DBScale 的​配​置​文​件​中​设​置​。​详​细​配​置​请​见​default-session-variables。​
可​以​通​过​命​令​
mysql> DBSCALE SHOW DEFAULT SESSION VARIABLES
显​示​目​前​已​经​设​置​了​默​认​值​的​ session 变​量​名​。​
可​以​通​过​命​令​
mysql> DBSCALE ADD DEFAULT SESSION VARIABLES para_list
命​令​动​态​添​加​默​认​ session 变​量​。​若​该​变​量​不​存​在​或​者​变​量​为​只​读​,则​命​令​中​的​变​量​列​表​中​的​变​量​均​设​置​失​败​,否​则​,显​示​设​置​成​功​。​
可​以​通​过​命​令​
mysql> DBSCALE REMOVE DEFAULT SESSION VARIABLES para_list
动​态​删​除​默​认​ session 变​量​。​若​该​变​量​不​在​ DBScale 默​认​ session 变​量​列​表​中​时​,则​删​除​失​败​; 若​有​一​部​分​ session 变​量​不​存​在​,一​部​分​存​在​,则​存​在​的​部​分​删​除​失​败​,部​分​删​除​成​功​。​
mysql> DBSCALE REMOVE DEFAULT SESSION VARIABLES wait_timeout;

7.10.2. 设​置​某​一​用​户​的​优​先​级​

DBScale 通​过​命​令​
mysql> DBSCALE PRIORITY SET number TO USER BY USER_NAME user_name;
进​行​设​置​某​一​用​户​的​优​先​级​。​优​先​级​的​数​字​包​含​1,2,3; 如​果​数​字​大​于​3, 则​被​强​制​转​换​成​3, 默​认​不​设​置​优​先​级​为​1. 优​先​级​数​字​越​大​, 优​先​级​越​低​, 1为​最​大​优​先​级​, 3为​最​小​优​先​级​.
动​态​设​置​用​户​的​优​先​级​需​要​通​过​两​个​配​置​变​量​配​合​使​用​ user-priority-high-access-pct和​user-priority-high-access-pct.
mysql> DBSCALE PRIORITY SET 1 TO USER BY USER_NAME "root";

7.10.3. 阻​塞​表​请​求​

是​否​可​以​执​行​阻​塞​请​求​命​令​由​参​数​ enable-block-table 控​制​。​
DBScale 通​过​命​令​
DBSCALE BLOCK TABLE name_or_full ALL block_time
将​表​请​求​阻​塞​,所​有​使​用​该​表​的​请​求​都​会​返​回​错​误​。​
DBScale 通​过​命​令​
DBSCALE BLOCK TABLE name_or_full PARTITION
将​分​片​表​请​求​阻​塞​,范​围​查​询​会​返​回​错​误​,指​定​分​片​列​请​求​可​以​执​行​。​非​分​片​表​可​以​执​行​请​求​,迁​移​除​外​.
DBScale 通​过​命​令​
DBSCALE STOP BLOCK TABLE name_or_full
将​表​解​除​阻​塞​, 一​个​用​户​可​以​解​除​其​他​用​户​的​表​阻​塞​。​

7.10.4. DBScale 执​行​命​令​信​号​

当​ DBScale 出​现​故​障​时​,无​法​登​陆​ DBScale, 可​以​使​用​信​号​(kill -10 dbscale.pid)让​ DBScale 来​执​行​一​些​收​集​命​令​,命​令​执​行​的​结​果​将​保​存​在​文​件​ current-status-result-file 中​。​
目​前​支​持​的​命​令​有​:
dbscale show user status;
dbscale show thread pool info;
dbscale show connection pool;
DBScale set 命令, 如 dbscale set instance log_level='INFO';

7.10.5. 保​存​ DBScale 的​配​置​信​息​

可​以​通​过​命​令​
mysql> DBSCALE FLUSH [ALL] CONFIG TO FILE [file_name]
将​本​ DBScale 节​点​的​配​置​信​息​刷​到​指​定​文​件​里​。​如​果​未​指​定​ ALL 选​项​,则​在​将​ main section 内​的​配​置​项​保​存​到​目​标​文​件​内​时​,只​会​将​值​为​非​默​认​值​的​参​数​保​存​到​文​件​里​;如​果​未​指​定​目​标​文​件​,则​覆​盖​本​ DBScale 节​点​的​原​配​置​文​件​。​
命​令​示​例​:
mysql> DBSCALE FLUSH ALL CONFIG TO FILE '/tmp/dbscale_config_backup.conf';
或​者​
mysql> DBSCALE FLUSH CONFIG TO FILE;
或​者​
mysql> DBSCALE FLUSH ALL CONFIG TO FILE;
可​以​配​置​自​动​运​行​程​序​,周​期​性​的​将​当​前​最​新​的​ DBScale 配​置​刷​新​到​配​置​文​件​中​。​为​了​实​现​该​目​标​,需​要​做​如​下​工​作​:
1. 配​置​ DBScale 安​装​目​录​下​的​ flush_config.sh,根​据​实​际​情​况​填​充​其​中​的​参​数​;
2. 通​过​ crontab -e 命​令​配​置​一​个​定​时​任​务​,向​定​时​任​务​列​表​添​加​如​下​一​行​(根​据​实​际​情​况​调​整​相​关​路​径​):
* * * * * /path/to/dbscale/flush_config.sh
这​样​配​置​之​后​,定​时​任​务​将​每​隔​ 1 分​钟​发​起​一​次​配​置​文​件​的​ flush 操​作​,从​而​将​最​新​的​ DBScale 运​行​时​配​置​信​息​保​存​到​配​置​文​件​中​。​
在​实​际​部​署​中​,通​常​我​们​会​将​ HA 和​ DBScale 联​合​配​置​。​在​这​种​情​况​下​,请​在​ HA 的​两​个​节​点​上​都​做​如​下​操​作​,实​现​ HA 环​境​下​刷​新​ DBScale 的​配​置​文​件​的​目​的​。​
1. 配​置​ HA 两​个​节​点​之​间​ ssh 免​登​录​;
2. 配​置​ DBScale 安​装​目​录​下​的​ flush_config.sh,将​被​注​释​掉​的​含​有​ scp 命​令​的​那​一​行​打​开​,根​据​实​际​情​况​填​充​其​中​的​参​数​;
3. 通​过​ crontab -e 命​令​配​置​一​个​定​时​任​务​,向​定​时​任​务​列​表​添​加​如​下​一​行​(根​据​实​际​情​况​调​整​相​关​路​径​):
* * * * * /path/to/flush_config.sh
这​样​配​置​之​后​,定​时​任​务​将​每​隔​ 1 分​钟​发​起​一​次​配​置​文​件​的​ flush 操​作​,并​将​最​新​配​置​文​件​拷​贝​到​ HA 的​对​端​。​

7.10.6. 通​过​机​器​名​与​连​接​id获​取​持​有​这​个​连​接​的​ DBScale session id值​

可​以​通​过​命​令​
mysql> DBSCALE [REQUEST | SHOW] SESSION ID WITH DATASERVER = server_name CONNECTION = connection_id;
获​取​是​那​个​session持​有​后​端​连​接​ , 其​中​ SHOW 会​返​回​整​个​ DBSCALE 集​群​的​信​息​, REQUEST 只​会​返​回​当​前​节​点​的​信​息​。​
命​令​示​例​:
mysql> DBSCALE SHOW SESSION ID WITH DATASERVER = master CONNECTION = 10;
或​者​
mysql> DBSCALE REQUEST SESSION ID WITH DATASERVER = master CONNECTION = 10;

7.10.7. 在​dataserver端​执​行​特​定​命​令​

DBScale 可​以​通​过​命​令​
DBSCALE BACKEND SERVER EXECUTE sql
向​dataserver端​发​送​set、​grant、​drop user、​flush privileges等​命​令​,为​后​端​数​据​库​设​置​变​量​更​改​用​户​等​。​
mysql> DBSCALE BACKEND SERVER EXECUTE sql;

7.10.8. 在​线​获​取​数​据​一​致​性​点​

DBScale提​供​了​
DBSCALE GET GLOBAL CONSISTENCE POINT
命​令​来​获​取​运​行​状​态​下​数​据​一​致​性​点​。​
一​致​性​点​是​指​ binlog 的​位​置​,在​这​个​位​置​上​,数​据​是​一​致​的​。​因​为​ DBScale 是​分​布​式​的​,DBScale 的​一​致​性​点​是​由​所​有​主​节​点​机​器​的​ binlog 位​置​组​成​,是​一​组​ binlog 位​置​。​对​于​这​组​ binlog 位​置​上​的​数​据​,是​全​局​一​致​的​,不​存​在​部​分​机​器​提​交​成​功​部​分​机​器​未​提​交​的​数​据​。​
在​线​状​态​下​,使​用​该​命​令​后​,如​果​有​分​布​式​事​务​提​交​, DBScale 会​阻​塞​这​个​事​务​。​对​于​在​这​之​前​进​入​提​交​状​态​的​分​布​式​事​务​,DBScale 会​等​待​这​个​事​务​提​交​完​成​。​在​所​有​分​布​式​事​务​提​交​后​,DBScale 获​取​一​致​性​点​,然​后​解​除​锁​,分​布​式​事​务​可​以​继​续​提​交​。​对​于​分​布​式​ DDL 语​句​采​取​相​同​处​理​方​式​。​
对​于​本​地​事​务​或​者​只​在​不​超​过​一​台​后​端​机​器​有​写​操​作​的​事​务​,本​操​作​不​会​阻​塞​。​
本​命​令​会​显​示​所​有​的​后​端​ Master 服​务​器​的​主​机​名​,bin_log 文​件​名​,位​置​。​
mysql>DBSCALE GET GLOBAL CONSISTENCE POINT;
Server_name File Position
auth_server master-bin.000001 120057
global_master master-bin.000001 120057
partition1_master master-bin.000001 123057
partition2_master master-bin.000001 128048

7.10.9. 扩​展​ EXPLAIN 语​句​

DBScale 扩​展​了​ MySQL 原​生​的​ EXPLAIN 语​句​,使​用​方​法​基​本​不​变​,只​是​在​原​生​的​每​ MySQL EXPLAIN 语​句​的​开​头​加​了​ DBSCALE 关​键​字​。​比​如​原​来​的​语​句​是​
EXPLAIN SELECT * FROM t1
那​么​改​造​成​ DBScale 的​扩​展​ EXPLAIN 语​句​就​是​
DBSCALE EXPLAIN SELECT * FROM t1
,比​如​ t1 表​结​构​为​只​有​一​列​ c1 的​一​个​二​分​片​、​shard-num=6、​无​数​据​的​分​区​表​,该​ DBSCALE EXPLAIN 语​句​的​输​出​如​下​
mysql> create table t1 (c1 int);
Query OK, 0 rows affected (1.10 sec)

mysql> DBSCALE EXPLAIN SELECT * FROM t1;
+--------------------+-------------+------+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
| exec_node          | data_source | id   | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | extra |
+--------------------+-------------+------+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
| *MySQLSendNode [1] |             |      |             |       |            |      |               |      |         |      |      |          |       |
| --MySQLFetchNode   | ds_part1    | 1    | SIMPLE      | t1    |            | ALL  |               |      |         |      | 1    | 100.00   |       |
| --MySQLFetchNode   | ds_part2    | 1    | SIMPLE      | t1    |            | ALL  |               |      |         |      | 1    | 100.00   |       |
| --MySQLFetchNode   | ds_part1    | 1    | SIMPLE      | t1    |            | ALL  |               |      |         |      | 1    | 100.00   |       |
| --MySQLFetchNode   | ds_part2    | 1    | SIMPLE      | t1    |            | ALL  |               |      |         |      | 1    | 100.00   |       |
| --MySQLFetchNode   | ds_part1    | 1    | SIMPLE      | t1    |            | ALL  |               |      |         |      | 1    | 100.00   |       |
| --MySQLFetchNode   | ds_part2    | 1    | SIMPLE      | t1    |            | ALL  |               |      |         |      | 1    | 100.00   |       |
+--------------------+-------------+------+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
7 rows in set (0.01 sec)

+---------+------------------+
| node_id | sql              |
+---------+------------------+
| 1       | SELECT * FROM t1 |
+---------+------------------+
1 row in set (0.01 sec)
从​其​输​出​中​可​以​看​到​ DBScale 内​部​的​执​行​计​划​的​执​行​节​点​、​涉​及​的​数​据​源​以​及​目​标​ server 上​实​际​语​句​的​原​生​ EXPLAIN 结​果​,以​及​每​一​个​ DBScale 执​行​节​点​所​涉​及​的​ SQL 语​句​。​

第 8 章 DBScale 权​限​认​证​

8.1. DBScale 权​限​认​证​概​述​

当​开​启​参​数​enable-acl时​,DBScale 提​供​库​级​别​和​表​级​别​的​权​限​认​证​。​
权​限​认​证​概​述​:
1. 库​/表​权​限​控​制​的​内​容​包​括​ NO_TOUCH, READ_ONLY, WRITABLE。​
2. NO_TOUCH 指​该​库​/表​既​不​可​读​也​不​可​写​,READ_ONLY 指​该​库​/表​可​读​但​是​不​可​写​,WRITABLE 指​该​库​/表​可​读​可​写​。​
3. 权​限​控​制​有​优​先​级​,表​级​别​的​权​限​控​制​设​置​具​有​最​高​的​优​先​级​,库​级​别​的​次​之​,最​后​是​默​认​权​限​(默​认​为​可​读​可​写​)。​
4. DBScale 的​库​级​别​权​限​认​证​规​则​是​对​库​有​读​权​限​就​可​以​通​过​初​步​认​证​,通​过​初​步​认​证​后​,如​果​没​有​通​过​第 8.2 节 “库​级​别​的​权​限​设​置​”或​者​第 8.3 节 “表​级​别​的​权​限​设​置​”对​该​库​或​其​内​部​表​做​额​外​的​权​限​设​置​,那​么​该​用​户​就​拥​有​这​个​库​的​所​有​权​限​,所​以​在​使​用​ DBScale 时​,要​求​ DBScale 集​群​内​的​任​何​用​户​,如​果​该​用​户​对​一​个​库​有​读​权​限​,那​它​就​必​须​拥​有​对​这​个​库​的​所​有​权​限​。​
5. 在​开​启​权​限​认​证​时​,当​执​行​ GRANT 语​句​或​ DBSCALE SET/RESET 等​可​能​改​变​权​限​控​制​属​性​的​语​句​时​,对​于​已​经​连​接​到​ DBScale 的​ session(包​括​执​行​该​语​句​的​session),其​相​关​权​限​维​持​旧​的​版​本​不​变​,需​要​重​新​登​录​后​能​够​获​得​最​新​版​本​的​权​限​属​性​。​
6. DBScale 可​以​通​过​ GRANT/CREATE USER 创​建​用​户​并​通​过​ GRANT 分​配​权​限​,但​是​在​创​建​用​户​和​分​配​权​限​时​,DBScale 会​将​用​户​账​户​(例​如​ user1@host1)的​ HOST 部​分​(host1)替​换​为​配​置​项​dbscale-hosts设​置​的​值​,即​ DBScale 不​能​通​过​ GRANT/CREATE USER 实​现​限​制​登​录​ IP 的​功​能​。​
7. 只​有​ root 和​ dbscale 两​个​用​户​有​权​限​调​整​其​他​用​户​对​库​/表​权​限​;DBScale 禁​止​通​过​ DBSCALE SET 命​令​更​改​ root 和​ dbscale 的​库​/表​权​限​。​

8.2. 库​级​别​的​权​限​设​置​

DBScale 通​过​如​下​命​令​实​现​某​个​用​户​对​某​个​库​的​权​限​设​置​。​
mysql> DBSCALE SET ACL ON SCHEMA schema_name TO user_name [NO_TOUCH | READ_ONLY | WRITABLE];
可​以​通​过​ RESET 操​作​来​清​除​用​户​对​库​的​权​限​设​置​。​可​以​清​除​某​个​用​户​对​某​单​个​库​的​权​限​设​置​,也​可​以​清​除​某​个​用​户​对​所​有​库​的​权​限​设​置​。​命​令​分​别​如​下​:
mysql> DBSCALE RESET ACL ON SCHEMA schema_name TO user_name;
mysql> DBSCALE RESET ACL ON ALL SCHEMA TO user_name;

8.3. 表​级​别​的​权​限​设​置​

DBScale 通​过​如​下​命​令​实​现​某​个​用​户​对​某​个​表​的​权​限​设​置​。​
mysql> DBSCALE SET ACL ON TABLE schema_name.table_name TO user_name [NO_TOUCH | READ_ONLY | WRITABLE];
可​以​通​过​ RESET 操​作​来​清​除​用​户​对​表​的​权​限​设​置​。​可​以​清​除​某​个​用​户​对​某​单​个​表​的​权​限​设​置​,也​可​以​清​除​某​个​用​户​对​某​个​库​下​所​有​表​的​权​限​设​置​。​命​令​分​别​如​下​:
mysql> DBSCALE RESET ACL ON TABLE schema_name.table_name TO user_name;
mysql> DBSCALE RESET ACL ON ALL TABLE IN SCHEMA schema_name TO user_name;

8.4. 设​置​用​户​对​ DDL 语​句​的​执​行​权​限​

如​果​开​启​了​权​限​认​证​,那​么​默​认​情​况​下​,除​了​ root 和​ dbscale 两​个​用​户​,DBScale 禁​止​其​他​用​户​执​行​ DDL 语​句​。​
可​以​通​过​相​关​命​令​对​其​他​用​户​赋​予​/撤​销​其​执​行​ DDL 语​句​的​权​限​。​
使​用​如​下​命​令​赋​予​/撤​销​某​个​用​户​执​行​ DDL 语​句​的​权​限​:
mysql> DBSCALE SET [NOT] ALLOW DDL FOR user_name;
上​述​语​句​只​有​ root 用​户​有​权​限​执​行​。​

8.5. IP 黑​白​名​单​

DBScale 支​持​基​于​黑​白​名​单​的​ IP 过​滤​。​具​体​参​数​设​置​方​式​请​参​考​第 3.3.3 节 “black-white section”
黑​白​名​单​可​以​在​线​调​整​,具​体​命​令​请​参​考​第 7.4.15 节 “在​线​调​整​IP黑​白​名​单​”
黑​白​名​单​可​以​通​过​命​令​查​看​,具​体​请​参​考​第 7.3.4 节 “查​看​ DBScale IP黑​白​名​单​”。​

8.6. ACL混​合​演​示​示​例​

本​小​节​会​混​合​演​示​一​个​DBScale ACL控​制​效​果​。​
演​示​的​内​容​根​据​如​下​DBScale配​置​进​行​:
[main]
driver = mysql
log-level = INFO
log-file = dbscale.log
authenticate-source = auth
datasource-in-one=1
restrict-auth-source-topo=0
enable-acl=1

admin-user=root
admin-password=mysql

[driver mysql]
type = MySQLDriver
port = 3308
bind-address = 0.0.0.0

[catalog def]
data-source = single

[data-source auth]
type = server
server = auth_server-10-20-10-10
user = root
password = mysql

[data-source single]
type = server
server = single_server-10-20-10-10
user = root
password = mysql

[data-server auth_server]
host = s12
port = 3304

[data-server single_server]
host = s12
port = 3305

[black-white]
black = .*
white = 172.16.90.12
white = 172.16.70.95
1. 根据上述配置,启动一个dbscale
2. 从172.16.90.12和172.16.70.95登录,确认登录成功
3. 从其他IP登录,确认登录失败,效果如下:
   $ mysql -uroot -pmysql -h172.16.70.95 -P3308
   ERROR 1045 (HY000): #28000Access denied
4. 用root登录到dbscale,执行如下命令:
  mysql> dbscale dynamic add white '172.16.90.13';
  Query OK, 0 rows affected (0.03 sec)

  mysql> dbscale dynamic add white '172.16.70.*';
  Query OK, 0 rows affected (0.04 sec)
  然后再从172.16.90.13登录dbscale,确认登录成功;从任意172.16.70.*登录dbscale,确认登录成功。

5. 登录成功后,确认如下命令结果
  [root@172-16-90-12 ~]# mysql -uroot -pmysql -h172.16.70.95 -P3308
  (省略登录信息)

  mysql> dbscale show black white list;
  +--------------+----------------+
  | ip           | black_or_white |
  +--------------+----------------+
  | .*           | black          |
  | 172.16.70.*  | white          |
  | 172.16.70.95 | white          |
  | 172.16.90.12 | white          |
  | 172.16.90.13 | white          |
  +--------------+----------------+
  5 rows in set (0.01 sec)

  mysql> create database db1;
  Query OK, 1 row affected (0.00 sec)

  mysql> create database db2;
  Query OK, 1 row affected (0.00 sec)

  mysql> create database db3;
  Query OK, 1 row affected (0.00 sec)

  mysql> show databases;
  +--------------------+
  | Database           |
  +--------------------+
  | information_schema |
  | db1                |
  | db2                |
  | db3                |
  | dbscale            |
  | dbscale_tmp        |
  | mysql              |
  | performance_schema |
  | sys                |
  | test               |
  +--------------------+
  10 rows in set (0.00 sec)

  mysql> create user 'user1'@'%' identified by 'user1pwd';
  Query OK, 0 rows affected (0.01 sec)

  mysql> grant all on db1.* to 'user1'@'%';
  Query OK, 0 rows affected (0.03 sec)

  mysql> grant all on db2.* to 'user1'@'%';
  Query OK, 0 rows affected (0.00 sec)

  mysql> create user 'user2'@'%' identified by 'user2pwd';
  Query OK, 0 rows affected (0.01 sec)

  mysql> grant all on db1.* to 'user2'@'%';
  Query OK, 0 rows affected (0.03 sec)

  mysql> grant all on db2.* to 'user2'@'%';
  Query OK, 0 rows affected (0.00 sec)

  mysql> dbscale set acl on table db1.t1 to user1 writable;
  Query OK, 0 rows affected (0.06 sec)

  mysql> dbscale set acl on table db1.t2 to user1 no_touch;
  Query OK, 0 rows affected (0.03 sec)

  mysql> dbscale set acl on table db1.t3 to user1 read_only;
  Query OK, 0 rows affected (0.06 sec)

  mysql> dbscale set acl on schema db1 to user1 no_touch;
  Query OK, 0 rows affected (0.14 sec)

  mysql> dbscale set acl on schema db1 to user2 read_only;
  Query OK, 0 rows affected (0.14 sec)

  mysql> dbscale show acl schema info;
  Empty set (0.00 sec)

  mysql> dbscale show all acl schema info;
  +-----------+-------------+-----------------+
  | user_name | schema_name | schema_acl_type |
  +-----------+-------------+-----------------+
  | user1     | db1         | no_touch        |
  | user2     | db1         | read_only       |
  +-----------+-------------+-----------------+
  2 rows in set (0.00 sec)

  mysql> dbscale show acl table info;
  Empty set (0.00 sec)

  mysql> dbscale show all acl table info;
  +-----------+-----------------+----------------+
  | user_name | full_table_name | table_acl_type |
  +-----------+-----------------+----------------+
  | user1     | db1.t1          | writable       |
  | user1     | db1.t2          | no_touch       |
  | user1     | db1.t3          | read_only      |
  +-----------+-----------------+----------------+
  3 rows in set (0.00 sec)

6. 用user1登录dbscale,确认其不可执行DDL语句:
  mysql> create table db1.tt(c1 int);
  ERROR 1044 (42000): Access denied for user [user1] to execute DDL statement. SQL: [create table db1.tt(c1 int)]
  mysql> show databases;
  +--------------------+
  | Database           |
  +--------------------+
  | information_schema |
  | db1                |
  | db2                |
  +--------------------+
  3 rows in set (0.13 sec)

7. 用root登录dbscale,给user1赋予DDL权限
  mysql> dbscale set allow ddl for user1;
  Query OK, 0 rows affected (0.05 sec)

  mysql> dbscale show allow ddl user;
  +-------------------+
  | is_user_allow_ddl |
  +-------------------+
  | YES               |
  +-------------------+
  1 row in set (0.00 sec)

  mysql> dbscale show all allow ddl user;
  +----------------------+
  | users_allow_ddl_stmt |
  +----------------------+
  | dbscale              |
  | root                 |
  | user1                |
  +----------------------+
  3 rows in set (0.00 sec)

8. 用user1重新登录dbscale,确认如下命令和对应结果
  mysql> create table db1.tt(c1 int);
  ERROR 1044 (42000): Access denied for user [user1] to database [db1]
  mysql> create table db1.t1(c1 int);
  Query OK, 0 rows affected (0.38 sec)

  mysql> create table db1.t2(c1 int);
  ERROR 1044 (42000): Access denied for user [user1] to table [db1.t2]
  mysql> create table db1.t3(c1 int);
  ERROR 1044 (42000): Access denied for user [user1] to table [db1.t3]
  mysql> create table db1.t4(c1 int);
  ERROR 1044 (42000): Access denied for user [user1] to database [db1]
  mysql> dbscale show allow ddl user;
  +-------------------+
  | is_user_allow_ddl |
  +-------------------+
  | YES               |
  +-------------------+
  1 row in set (0.00 sec)

  mysql> dbscale show acl schema info;
  +-------------+-----------------+
  | schema_name | schema_acl_type |
  +-------------+-----------------+
  | db1         | no_touch        |
  +-------------+-----------------+
  1 row in set (0.00 sec)

  mysql> dbscale show acl table info;
  +-----------------+----------------+
  | full_table_name | table_acl_type |
  +-----------------+----------------+
  | db1.t1          | writable       |
  | db1.t2          | no_touch       |
  | db1.t3          | read_only      |
  +-----------------+----------------+
  3 rows in set (0.00 sec)

  mysql> dbscale show all acl schema info;
  ERROR 9002 (): Current User does not have the privilege to show ALL schema ACL
  mysql> dbscale show all acl table info;
  ERROR 9002 (): Current User does not have the privilege to show ALL table ACL

9. 用root登录dbscale,建表db1.t2 db1.t3 db1.t4
  mysql> create table db1.t2(c1 int);
  Query OK, 0 rows affected (0.33 sec)

  mysql> create table db1.t3(c1 int);
  Query OK, 0 rows affected (0.55 sec)

  mysql> create table db1.t4(c1 int);
  Query OK, 0 rows affected (0.55 sec)

10. 用user1登录dbscale,验证如下命令和结果
  mysql> use db1;
  Database changed
  mysql> insert into t1 values (1);
  Query OK, 1 row affected (0.02 sec)

  mysql> insert into t2 values (1);
  ERROR 1044 (42000): Access denied for user [user1] to table [db1.t2]
  mysql> select * from t2;
  ERROR 1044 (42000): Access denied for user [user1] to table [db1.t2]
  mysql> insert into t3 values (1);
  ERROR 1044 (42000): Access denied for user [user1] to table [db1.t3]
  mysql> select * from t3;
  Empty set (0.89 sec)
  mysql> insert into t4 values (1);
  ERROR 1044 (42000): Access denied for user [user1] to database [db1]
  mysql> select * from t4;
  ERROR 1044 (42000): Access denied for user [user1] to database [db1]

11. 用shutdown命令关闭dbscale,然后重启dbscale,然后用root登录dbscale,确认如下命令输出
  mysql> dbscale show all acl schema info;
  +-----------+-------------+-----------------+
  | user_name | schema_name | schema_acl_type |
  +-----------+-------------+-----------------+
  | user1     | db1         | no_touch        |
  | user2     | db1         | read_only       |
  +-----------+-------------+-----------------+
  2 rows in set (0.00 sec)

  mysql> dbscale show all acl table info;
  +-----------+-----------------+----------------+
  | user_name | full_table_name | table_acl_type |
  +-----------+-----------------+----------------+
  | user1     | db1.t1          | writable       |
  | user1     | db1.t2          | no_touch       |
  | user1     | db1.t3          | read_only      |
  +-----------+-----------------+----------------+
  3 rows in set (0.00 sec)

  mysql> dbscale show black white list;
  +--------------+----------------+
  | ip           | black_or_white |
  +--------------+----------------+
  | .*           | black          |
  | 172.16.70.*  | white          |
  | 172.16.70.95 | white          |
  | 172.16.90.12 | white          |
  | 172.16.90.13 | white          |
  +--------------+----------------+
  5 rows in set (0.01 sec)

12. 用user1登录dbscale,确认如下命令结果
  mysql> dbscale show acl schema info;
  +-------------+-----------------+
  | schema_name | schema_acl_type |
  +-------------+-----------------+
  | db1         | no_touch        |
  +-------------+-----------------+
  1 row in set (0.00 sec)

  mysql> dbscale show acl table info;
  +-----------------+----------------+
  | full_table_name | table_acl_type |
  +-----------------+----------------+
  | db1.t1          | writable       |
  | db1.t2          | no_touch       |
  | db1.t3          | read_only      |
  +-----------------+----------------+
  3 rows in set (0.00 sec)

  mysql> dbscale show allow ddl user;
  +-------------------+
  | is_user_allow_ddl |
  +-------------------+
  | YES               |
  +-------------------+
  1 row in set (0.00 sec)

  mysql> insert into db1.t1 values (1);
  Query OK, 1 row affected (1.57 sec)

  mysql> insert into db1.t2 values (1);
  ERROR 1044 (42000): Access denied for user [user1] to table [db1.t2]
  mysql> select * from db1.t2;
  ERROR 1044 (42000): Access denied for user [user1] to table [db1.t2]
  mysql> insert into db1.t3 values (1);
  ERROR 1044 (42000): Access denied for user [user1] to table [db1.t3]
  mysql> select * from db1.t3;
  Empty set (2.74 sec)

  mysql> insert into db1.t4 values (1);
  ERROR 1044 (42000): Access denied for user [user1] to database [db1]
  mysql> select * from db1.t4;
  ERROR 1044 (42000): Access denied for user [user1] to database [db1]
  mysql> use db2;
  Database changed
  mysql> create table t1 (c1 int);
  Query OK, 0 rows affected (0.47 sec)

  mysql> insert into t1 values (1);
  Query OK, 1 row affected (1.83 sec)

  mysql> select * from t1;
  +------+
  | c1   |
  +------+
  |    1 |
  +------+
  1 row in set (0.00 sec)

13. 用user2登录dbscale,确认如下输出
  mysql> dbscale show acl schema info;
  +-------------+-----------------+
  | schema_name | schema_acl_type |
  +-------------+-----------------+
  | db1         | read_only       |
  +-------------+-----------------+
  1 row in set (0.00 sec)

  mysql> dbscale show all acl schema info;
  ERROR 9002 (): Current User does not have the privilege to show ALL schema ACL
  mysql> dbscale show acl table info;
  Empty set (0.00 sec)

  mysql> select * from db1.t1;
  +------+
  | c1   |
  +------+
  |    1 |
  |    1 |
  +------+
  2 rows in set (0.00 sec)

  mysql> insert into db1.t1 values (1);
  ERROR 1044 (42000): Access denied for user [user2] to database [db1]
  mysql> select * from db1.t4;
  Empty set (0.00 sec)

  mysql> select * from db2.t1;
  +------+
  | c1   |
  +------+
  |    1 |
  +------+
  1 row in set (0.00 sec)

  mysql> insert into db2.t1 values (1);
  Query OK, 1 row affected (0.00 sec)

  mysql> create table db2.t2(c1 int);
  ERROR 1044 (42000): Access denied for user [user2] to execute DDL statement. SQL: [create table db2.t2(c1 int)]

8.7. DBScale 集​群​密​码​修​改​

DBScale 支​持​修​改​登​录​用​户​密​码​,修​改​密​码​时​,DBScale 将​ SET 或​ GRANT 语​句​中​指​明​的​ HOST 值​替​换​为​配​置​的​ dbscale-hosts 值​,详​见​第 12.1.7 节 “SET PASSWORD”第 12.1.4 节 “GRANT”。​该​方​式​修​改​的​是​认​证​数​据​源​的​用​户​密​码​。​
DBScale 保​留​用​户​(管​理​连​接​用​户​,业​务​连​接​用​户​)密​码​需​要​停​ DBScale 服​务​进​行​修​改​:
1.停​止​ DBScale 服​务​。​
2.连​接​至​后​端​数​据​节​点​(包​括​认​证​节​点​)使​用​ SET 或​ GRANT 修​改​用​户​密​码​。​注​意​事​项​:
a.如​果​存​在​主​从​复​制​关​系​,只​需​要​在​每​个​主​节​点​上​执​行​密​码​修​改​命​令​,且​如​果​修​改​密​码​的​用​户​是​主​从​连​接​的​用​户​,需​要​使​用​新​密​码​重​建​主​从​。​
b.查​看​ mysql.user 表​中​用​户​的​ HOST 值​,一​般​为​ DBScale 所​在​机​器​的​网​段​值​,将​语​句​中​的​ HOST 值​指​定​为​该​值​。​
3.修​改​配​置​文​件​,将​配​置​文​件​中​保​留​用​户​的​密​码​修​改​为​新​密​码​.
4.启​动​ DBScale。​

第 9 章 DBScale 外​部​工​具​

9.1.  DBScale 集​群​数​据​备​份​工​具​

DBScale 提​供​了​ backup_all_server.sh 工​具​来​进​行​集​群​数​据​备​份​。​
备​份​方​式​有​三​种​,分​别​是​全​备​份​、​增​量​备​份​与​一​致​点​备​份​。​
全​备​份​是​指​对​数​据​库​集​群​的​所​有​数​据​进​行​备​份​。​增​量​备​份​是​指​在​全​量​备​份​基​础​上​,对​近​一​段​时​间​新​增​的​数​据​进​行​备​份​。​一​致​点​备​份​是​指​在​上​一​次​备​份​基​础​上​,获​取​当​前​ DBScale 运​行​一​致​点​,然​后​保​存​到​该​位​置​数​据​。​一​致​点​备​份​与​增​量​备​份​的​区​别​在​于​,一​致​点​备​份​一​般​用​于​少​量​数​据​更​新​时​备​份​,一​般​是​上​一​次​备​份​后​一​天​内​。​增​量​备​份​可​以​备​份​较​多​的​增​量​数​据​。​
  1. 环​境​要​求​:
    要​在​集​群​需​要​备​份​的​每​台​机​器​上​安​装​ xtrabackup 工​具​,并​将​它​的​ bin 目​录​放​到​ PATH 中​。​
    要​在​集​群​需​要​备​份​的​每​台​机​器​上​,将​ mysql 的​ bin 目​录​放​到​ PATH 中​。​
  2. 配​置​文​件​:
    配​置​文​件​第​一​行​用​于​配​置​ DBScale 的​相​关​信​息​,分​别​是​ DBScale 所​在​机​器​的​ ip 地​址​、​连​接​ DBScale 所​用​的​用​户​名​、​密​码​、​端​口​。​
    配​置​文​件​从​第​二​行​开​始​,每​一​行​用​于​配​置​一​台​后​端​ mysql 相​关​信​息​,分​别​是​ ip 地​址​、​操​作​系​统​用​户​名​、​操​作​系​统​密​码​、​数​据​库​用​户​名​、​数​据​库​密​码​、​数​据​库​使​用​端​口​号​、​启​动​ mysql 使​用​的​配​置​文​件​(需​要​绝​对​路​径​)、​binlog 文​件​所​在​目​录​绝​对​路​径​(一​般​为​ mysql 的​数​据​目​录​)、​临​时​目​录​(如​/tmp, 临​时​存​放​备​份​文​件​,需​要​空​间​较​大​)、​这​台​机​器​在​ DBScale 配​置​文​件​中​对​应​的​机​器​名​称​(如​果​有​多​个​,用​“​/”​分​隔​)。​
    配​置​文​件​示​例​如​下​:
      192.168.1.1 dbscale dbscale 3307
      192.168.1.12 root abc123 dbscale dbscale 13003 /usr/local/mysql/my13003.cnf /usr/local/mysql/data13003/ /tmp auth_server/single
      192.168.1.13 root abc123 dbscale dbscale 13003 /usr/local/mysql/my13003.cnf /usr/local/mysql/data13003/  /tmp single2
      192.168.1.14 root abc123 dbscale dbscale 13003 /usr/local/mysql/my13003.cnf /usr/local/mysql/data13003/  /tmp single3
  3. 备​份​工​具​使​用​:
    直​接​使​用​命​令​: ./backup_all_server.sh 可​以​看​到​工​具​的​使​用​方​法​。​
    工​具​有​两​个​选​项​:
    -t 表​示​使​用​的​类​型​,有​四​种​,all 表​示​进​行​全​备​份​, inc 表​示​进​行​增​量​备​份​, point 表​示​进​行​一​致​点​备​份​, clean 表​示​进​行​清​理​,如​过​之​前​有​备​份​失​败​,使​用​ clean 进​行​清​理​。​
    -d 表​示​备​份​文​件​保​存​的​目​录​,对​于​全​量​备​份​,工​具​会​在​你​提​供​的​备​份​目​录​内​使​用​当​前​备​份​时​间​创​建​一​个​目​录​,用​于​标​识​这​个​备​份​的​备​份​时​间​,然​后​将​备​份​文​件​放​到​这​个​时​间​目​录​中​。​对​于​增​量​备​份​,因​为​增​量​备​份​依​赖​全​备​份​,所​以​增​量​备​份​提​供​的​目​录​需​要​是​具​体​全​备​份​的​路​径​,也​就​是​自​动​生​成​的​一​个​时​间​目​录​。​一​致​点​备​份​和​清​理​都​与​增​量​备​份​使​用​方​法​相​同​。​
    工​具​使​用​示​例​如​下​:
      ./backup_all_server.sh -t all -d /tmp/backup
      ./backup_all_server.sh -t inc -d /tmp/backup/2014-10-28_14-55-38
      ./backup_all_server.sh -t point -d /tmp/backup/2014-10-28_14-55-38
      ./backup_all_server.sh -t clean -d /tmp/backup/2014-10-28_14-55-38
    
  4. 备​份​目​录​结​构​:
    对​于​全​量​备​份​给​定​的​备​份​目​录​,会​在​这​个​目​录​中​生​成​一​个​时​间​目​录​,代​表​一​个​备​份​。​在​时​间​目​录​中​,“​0”​目​录​代​表​全​备​份​。​“​1~...”​目​录​代​表​增​量​备​份​。​在​每​个​备​份​目​录​中​,有​一​个​“​point”​目​录​,用​于​保​存​一​致​点​数​据​。​“​point”​目​录​中​有​“​0~...”​目​录​,里​面​保​存​每​次​一​致​点​备​份​的​数​据​。​
  5. 备​份​注​意​:
    如​果​从​当​前​机​器​登​录​到​需​要​备​份​的​机​器​上​已​经​配​置​了​无​密​码​登​录​,需​要​在​备​份​配​置​文​件​中​密​码​位​置​写​ "NULL" 来​标​识​,否​则​会​备​份​失​败​。​
    备​份​数​据​库​中​不​能​有​ dbscale_point 这​个​库​,如​果​有​这​个​库​,还​原​时​候​请​联​系​开​发​人​员​,否​则​会​删​除​这​个​库​。​
    备​份​前​需​要​将​ mysql 的​ bin 目​录​和​ xtrabackup 的​bin 目​录​添​加​到​环​境​变​量​中​。​
  6. 备​份​结​果​:
    备​份​失​败​的​话​,会​在​备​份​目​录​中​含​有​有​文​件​“​dbscale_backup_failed”​表​示​备​份​失​败​,此​时​可​以​使​用​命​令​类​型​“​clean”​对​失​败​文​件​进​行​清​理​。​
      ./backup_all_server.sh -t clean -d /tmp/backup/2014-10-28_14-55-38
    
    备​份​成​功​的​话​,会​在​屏​幕​显​示​“​end back up all server!”​,同​时​备​份​目​录​中​有​文​件​“​dbscale_backup_success”​,且​没​有​文​件​“​dbscale_backup_failed”​表​示​备​份​成​功​。​

9.2.  DBScale 集​群​数​据​恢​复​工​具​

DBScale 提​供​了​ recover_all_server.sh 工​具​来​进​行​集​群​数​据​还​原​。​
要​做​集​群​数​据​还​原​首​先​要​有​一​个​全​量​备​份​文​件​,使​用​工​具​ backup_all_server.sh 备​份​集​群​可​以​得​到​全​量​备​份​数​据​。​
做​恢​复​前​首​先​要​保​证​备​份​数​据​目​录​可​用​,如​果​之​前​做​增​量​备​份​有​失​败​,需​要​手​动​执​行​命​令​ ./backup_all_server.sh -t clean -d /tmp/backup 来​进​行​清​理​。​
  1. 环​境​要​求​:
    要​在​集​群​需​要​恢​复​的​每​台​机​器​上​安​装​ xtrabackup 工​具​,并​将​它​的​ bin 目​录​放​到​ PATH 中​。​
    确​保​使​用​的​mysql用​户​名​密​码​可​以​登​录​到​mysql数​据​库​,并​且​具​有​远​端​和​本​地​登​录​权​限​。​
  2. 配​置​文​件​:
    配​置​文​件​第​一​部​分​用​ server 标​记​,包​含​恢​复​ mysql 的​相​关​信​息​,共​八​项​,分​别​是​备​份​数​据​服​务​器​、​恢​复​数​据​到​的​机​器​ ip, 端​口​, 登​录​系​统​用​户​名​, 系​统​密​码​, mysql 配​置​文​件​位​置​, mysql 数​据​恢​复​目​录​, mysql 的​ bin 文​件​夹​路​径​, 临​时​目​录​(如​/tmp, 用​于​存​放​临​时​文​件​,需​要​空​间​较​大​)。​
    备​份​数​据​服​务​器​是​指​ dbscale 的​一​个​数​据​源​,包​含​还​原​数​数​据​时​所​需​要​的​备​份​数​据​,这​个​数​据​源​可​能​只​包​含​一​个​ server, 也​可​能​含​有​多​个​主​从​复​制​ server, 如​果​是​多​个​主​从​复​制​ server,需​要​将​主​机​从​机​的​ ip 地​址​与​端​口​号​都​列​出​来​,使​用​"/"分​割​。​
    配​置​文​件​第​二​部​分​用​ global_info 标​记​,包​含​三​项​,分​别​是​:执​行​脚​本​所​在​机​器​的​ mysql 的​ bin 文​件​夹​路​径​,可​以​登​录​后​端​所​有​数​据​库​的​用​户​名​以​及​这​个​用​户​的​密​码​。​
    配​置​文​件​第​三​部​分​用​ topo 标​记​,包​含​五​项​,分​别​是​:原​全​局​主​节​点​数​据​所​在​将​机​器​的​ ip 地​址​、​端​口​号​ 、​分​区​主​节​点​ ip 地​址​、​端​口​号​、​要​同​步​的​数​据​库​名​。​
    如​果​全​局​主​节​点​与​分​区​主​节​点​有​主​从​关​系​,那​么​分​区​主​节​点​上​的​数​据​与​全​局​主​节​点​的​数​据​可​能​不​一​致​,需​要​使​用​全​局​主​节​点​数​据​进​行​恢​复​来​保​持​一​致​。​如​果​没​有​主​从​关​系​,不​需​要​配​置​此​项​。​
    配​置​文​件​示​例​如​下​:
     <server>
    172.16.90.13-12001/172.16.90.14-12001 172.16.90.12 12004 root abc123 /usr/local/mysql5.6/my12004.cnf /usr/local/mysql5.6/data12004/ /usr/local/mysql5.6/bin /tmp
    
    172.16.90.13-12002/172.16.90.14-12002 172.16.90.13 12004 root si /usr/local/mysql/my12004.cnf /usr/local/mysql/data12004/  /usr/local/mysql/bin /tmp
    
    172.16.90.13-12003/172.16.90.14-12003 172.16.90.14 12004 root NULL /usr/local/mysql/my12004.cnf /usr/local/mysql/data12004/ /usr/local/mysql/bin /tmp
    </server>
    
    
    <global_info>
    /usr/local/mysql5.6/bin dbscale dbscale
    </global_info>
    
    <topo>
    172.16.90.12 12004 172.16.90.13 12004 test
    
    172.16.90.12 12004 172.16.90.14 12004 test
    </topo>
  3. 恢​复​工​具​使​用​:
    直​接​使​用​命​令​: ./recover_all_server.sh 可​以​看​到​工​具​的​使​用​方​法​。​
    工​具​有​两​个​选​项​:
    -d 表​示​保​存​的​全​量​备​份​目​录​。​
    -t 表​示​进​行​恢​复​拓​扑​时​选​用​的​恢​复​工​具​,如​果​不​指​定​使​用​ mysqldump 进​行​恢​复​。​
    工​具​使​用​示​例​如​下​:
     ./recover_all_server.sh -d /tmp/backup/2014-10-28_14-55-38
    
    如​果​在​脚​本​所​在​机​器​有​安​装​工​具​ mydumper,myloader,可​以​使​用​这​两​个​工​具​进​行​还​原​,可​以​提​高​还​原​速​度​,需​要​将​mydumper所​在​目​录​添​加​到​环​境​变​量​中​,执​行​命​令​如​下​:
     ./recover_all_server.sh -d /tmp/backup/2014-10-28_14-55-38 -t mydumper
    
  4. 恢​复​日​志​:
    恢​复​工​具​会​将​恢​复​数​据​过​程​中​产​生​的​日​志​放​在​目​录​ ./dbscale_recover_log 中​,会​为​每​一​个​ server 生​成​一​个​日​志​文​件​,由​ ip 和​端​口​名​组​合​成​。​如​:172.16.90.14_12004.log
  5. 恢​复​注​意​:
    如​果​从​当​前​机​器​登​录​到​需​要​还​原​的​机​器​上​已​经​配​置​了​无​密​码​登​录​,需​要​在​恢​复​配​置​文​件​中​密​码​位​置​写​ "NULL" 来​标​识​,否​则​恢​复​失​败​。​
    确​保​要​恢​复​到​的​mysql 数​据​目​录​中​没​有​任​何​文​件​,否​则​会​恢​复​失​败​。​
    确​保​要​恢​复​到​的​mysql 的​端​口​号​没​有​被​占​用​,否​则​会​恢​复​失​败​。​
    确​保​使​用​的​全​局​mysql用​户​名​密​码​可​以​登​录​所​有​的​mysql数​据​库​,并​且​具​有​远​端​和​本​地​登​录​权​限​。​
    全​量​备​份​在​恢​复​过​程​中​会​进​行​应​用​日​志​,一​旦​做​恢​复​操​作​,那​么​这​个​全​量​备​份​就​无​法​被​继​续​用​来​备​份​,即​使​进​行​新​的​增​量​备​份​,在​恢​复​时​,新​的​增​量​也​不​会​被​应​用​。​如​果​想​使​用​这​个​全​量​备​份​继​续​进​行​备​份​,那​么​在​恢​复​前​需​要​进​行​这​个​目​录​的​备​份​。​
  6. 恢​复​结​果​:
    恢​复​失​败​的​话​,会​在​命​令​行​提​示​恢​复​失​败​。​
    恢​复​成​功​的​话​,会​在​屏​幕​显​示​“​recover all server successfully!”​。​

9.3.  jemalloc

DBScale 强​制​使​用​ jemalloc 来​使​用​内​存​。​
jemalloc 的​安​装​与​使​用​。​
  1. jemalloc的​下​载​:
    http://www.canonware.com/download/jemalloc/
    ~$ wget http://www.canonware.com/download/jemalloc/jemalloc-3.5.0.tar.bz2
  2. 解​压​下​载​下​来​的​tar包​:
    ~$ tar jxvf jemalloc-3.5.0.tar.bz2
  3. 安​装​jemalloc shell:
    ~$ ./configure --prefix=/usr/local
    ~$ make
    ~$ sudo make install
  4. 使​用​jemalloc:
    export LD_PRELOAD=/usr/local/lib/libjemalloc.so
  5. 检​查​ DBScale 是​否​正​常​引​用​了​ jemalloc:
    sudo cat/proc/$dbscale_pid/maps
    如​果​有​看​到​ jemalloc.so 表​名​使​用​ jemalloc 成​功​。​

9.4.  dbscale-online-schema-change

DBScale 使​用​dbscale-online-schema-change来​进​行​在​线​的​表​结​构​变​更​。​
  1. dbscale_online_schema_change 工​具​的​参​数​说​明​:
    -u 连​接​dbscale的​账​户​用​户​
    -p 连​接​dbscale的​账​户​密​码​
    -h dbscale的​ip地​址​
    -P dbscale的​端​口​
    -D 要​修​改​的​表​所​在​的​database
    -t 要​修​改​的​表​所​在​的​table
    --charset 设​置​字​符​集​,默​认​utf8
    --help 查​看​有​哪​些​参​数​
    --alter 后​面​跟​alter的​子​句​比​如​"add column a int"
    --execute 表​示​做​执​行​alter操​作​
    --rollback 表​示​做​执​行​rollback操​作​
    --clean 表​示​做​执​行​clean操​作​
  2. dbscale_online_schema_change 工​具​的​使​用​禁​忌​:
    1)本​工​具​不​可​以​在​同​一​个​目​录​进​行​并​发​执​行​。​
    2)并​发​执​行​时​不​可​以​同​时​同​一​张​表​进​行​修​改​。​
    3)不​推​荐​在​业​务​高​峰​执​行​。​
    4)不​推​荐​并​发​执​行​该​程​序​。​
  3. rollback的​使​用​场​景​
    1)在​alter失​败​后​进​行​清​理​的​报​错​的​时​候​。​
    2)在​执​行​过​程​中​出​现​"Alter Successful."前​的​时​候​杀​死​程​序​后​。​
  4. clean的​使​用​场​景​
    在​alter成​功​后​进​行​清​理​的​报​错​的​时​候​。​

9.5.  mysql_auto_install

mysql_auto_install
DBScale mysql_auto_install来进行mysql的自动安装和部署。
使用说明:
1. 将dbscale的配置文件复制到脚本所在的目录。命名为dbscale.conf
2. ./make_install_cnf.py 执行生成安装配置文件install.cnf的脚本。
3. 打开install.cnf,开始进行配置。
1) main部分
a) 默认配置文件,其中的一些内容是根据dbscale.conf中提取出来的
[main]
packet_position = 
remote_tmp_dir = 
global_ssh_user = 
global_ssh_password = 
global_ssh_port = 
global_cnf = 
#这行是登陆dbscale的用户,请在后面''中把能够访问该dbscale的ip段写上,如同mysql复制一样,如果需要用到'%',请使用'%%'来代替
db_admin_user = dbscale@''
db_admin_password = "dbscale"
b) 示例
[main]
packet_position = /home/hu/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz 这里填写数据包所在的位置
remote_tmp_dir = /tmp                                                这里填写全局的tmp目录,用来存放
global_ssh_user = root                                               这里填写全局的ssh使用的系统账户
global_ssh_password = "abc123"                                       这里填写全局的ssh账户的密码(一定要用""来引上)
global_ssh_port = 22                                                 这里填写全局的ssh的端口
global_cnf = my13306.cnf                                             这里填写全局的配置文件
db_admin_user = dbscale@'%%'                                         这里填写全局的数据库的账户,这里格式是user@'host' (由于python模块的问题,host的%要使用%%带替)
db_admin_password = "dbscale"                                        这里填写全局的数据库账户的密码(一定要用""来引上)

2) my_cnf_info部分
a) 默认配置文件的部分
[my_cnf_info]
#这个表示有那几个MySQL的配置文件,使用','来间隔
my_cnf_name = myexample.cnf
b) 示例
[my_cnf_info]
my_cnf_name = my13305.cnf,my13306.cnf,my13307.cnf                   这里有几个配置文件就填写几个,以','来分割具体的每一个配置文件

3) 配置文件的section
a) 默认配置文件的部分
[myexample.cnf]
#这个是用来告诉程序从哪里获得这个配置文件
local_position = /tmp/myexample.cnf
#这个是用来告诉程序从这个脚本最终将放在服务器的哪个位置,这个配置将影响到所有使用这个配置文件的实例即dbscale内的server,如果是单机多实例,可以放到一个统一的目录中,比如配置文件配置datadir在/opt/mysql13306/data,可以把配置文件放置到/opt/mysql13306中,方便多实例的管理
remote_position = /etc/my.cnf

b)示例
[my13305.cnf]							    给配置文件起一个名字
local_position = /opt/mysql_auto_install/my13305.cnf		    配置文件在本地所在的位置
remote_position = /database/mysql13305/my13305.cnf		    配置文件在远程最终存放的位置,可以是安装过程中创建的,而默认不存在的位置

4) mysql_server_info部分
[mysql_server_info]
mysql_instance_name = data-server global_master,data-server global_slave,data-server part_1_master,data-server part_1_slave,data-server part_2_master,data-server part_2_slave,data-server part_3_master,data-server part_3_slave
这部分是自动生成的,如果要进行修改,至少保证,在这里出现的项在后面都有配置。

5) data-server部分
a) 默认根据给定dbscale.conf生成
[data-server global_master]
host = 172.16.110.60
ssh_user = 							    使用的ssh登陆的账户如果不配置默认使用global的,可以将次行删除掉
ssh_password = 							    使用的ssh登陆的账户密码如同全局一样,可删掉。
ssh_port = 							    使用的ssh登陆的端口,如同全局一样,可删掉。
db_user = dbscale@''						    数据库要授权的账户和机器如果需要使用'%',那需要使用'%%'来配置,不配置默认使用global的,可以将次行删除掉。
db_password = "dbscale"						    数据库要授权的账户和机器的密码,使用""将密码引上,不配置默认使用global的,可以将次行删除掉。
db_port = 13305							    数据库的端口号,不配置默认使用global的,可以将次行删除掉。
cnf = 								    这个实例使用的MySQL配置文件,如同全局一样,可删掉。
tmp_dir = 							    使用的临时目录如同全局一样,可删掉。

b)配置示例
[data-server global_master]
host = 172.16.110.60
db_user = dbscale@'%%'
db_password = "dbscale"
db_port = 13305
cnf = my13305.cnf

6) 配置文件完整示例
[main]
packet_position = /home/hu/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz
remote_tmp_dir = /tmp
global_ssh_user = root
global_ssh_password = "abc123"
global_ssh_port = 22
db_admin_user = dbscale@'%%'
db_admin_password = "dbscale"

[my_cnf_info]
my_cnf_name = my13305.cnf,my13306.cnf,my13307.cnf

[my13305.cnf]
local_position = /opt/mysql_auto_install/my13305.cnf
remote_position = /database/mysql13305/my13305.cnf

[my13306.cnf]
local_position = /opt/mysql_auto_install/my13306.cnf
remote_position = /database/mysql13306/my13306.cnf
	
[my13307.cnf]
local_position = /opt/mysql_auto_install/my13307.cnf
remote_position = /database/mysql13307/my13307.cnf
	
[mysql_server_info]
mysql_instance_name = data-server global_master,data-server global_slave,data-server part_1_master,data-server part_1_slave,data-server part_2_master,data-server part_2_slave,data-server part_3_master,data-server part_3_slave

[data-server global_master]
host = 172.16.110.60
db_user = dbscale@'%%'
db_password = "dbscale"
db_port = 13305
cnf = my13305.cnf

[data-server global_slave]
host = 172.16.110.47
db_user = dbscale@'%%'
db_password = "dbscale"
db_port = 13305
cnf = my13305.cnf

[data-server part_1_master]
host = 172.16.110.60
db_user = dbscale@'%%'
db_password = "dbscale"
db_port = 13306
cnf = my13306.cnf

[data-server part_1_slave]
host = 172.16.110.47
db_user = dbscale@'%%'
db_password = "dbscale"
db_port = 13307
cnf = my13307.cnf

[data-server part_2_master]
host = 172.16.110.47
db_user = dbscale@'%%'
db_password = "dbscale"
db_port = 13306
cnf = my13306.cnf

[data-server part_2_slave]
host = 172.16.110.60
db_user = dbscale@'%%'
db_password = "dbscale"
db_port = 13307
cnf = my13307.cnf

[data-server part_3_master]
host = 172.16.110.34
db_user = dbscale@'%%'
db_password = "dbscale"
db_port = 13306
cnf = my13306.cnf

[data-server part_3_slave]
host = 172.16.110.34
db_user = dbscale@'%%'
db_password = "dbscale"
db_port = 13307
cnf = my13307.cnf

4. ./auto_install.py 开始安装
--thread参数可以指定最大使用多少个线程来并发执行,由于python的多线程模块最多使用一个core,所以不建议使用很多线程,而此处的thread只限定文件传输和权限修改时的并发量,不限定最后安装和初始化的并发量。因为文件传输的机器过多可能会导致网络压力过大,导超时。默认并发数为2。

额外工具:
1. check_ssh.py
此工具解析install.cnf来对其中的server进行ssh测试。
./check_ssh.py 
Start Ping Test ......
IP:172.16.110.34	............  [OK]
IP:172.16.110.47	............  [OK]
IP:172.16.110.60	............  [OK]
Start SSH Test .....
IP:172.16.110.47	USER:root	............  [OK]
IP:172.16.110.60	USER:root	............  [OK]
IP:172.16.110.34	USER:root	............  [OK]
测试结束

2. clean.py
清理工具,如果安装出现问题,想要完全重新安装,可以执行此工具。
执行是会输出一堆的目录,请确认目录无问题再进行执行。
清理过程中会kill掉所有的mysqld进程,如果在某台有生产的非此次安装的实例,可能导致误杀,请谨慎使用。
Are you sure you want to delete these [Y/N]:		输入Y后就开始清理。

9.6. 集​群​rebalance工​具​

该​工​具​主​要​用​于​集​群​shard分​片​表​(第 11.4 节 “Shard 分​片​表​”)的​rebalance。​
Usage: ./rebalance
  -u user for login dbscale
  -p password for login dbscale
  -h ip/host of dbscale
  -P port of dbscale
  -t thread num for rebalance
  -s new source list
  -d print the debug log

Example of rebalance:
  ./rebalance -u dbscale_user -p dbscale_password -h 127.0.0.1 -P 3307 -t 4 -s s1,s2,s3,s4 -d
参​数​"-u","-p","-h","-P"用​于​指​定​如​何​登​录​dbscale集​群​。​参​数​"-t"用​于​指​定​并​发​迁​移​的​线​程​数​目​, 目​前​并​发​是​表​级​的​并​行​, 参​数​"-s"用​于​指​定​新​增​的​source,该​参​数​可​选​且​source用​","分​割​,如​果​给​定​,那​么​新​source也​将​参​与​rebalance,如​果​没​有​给​定​,那​么​rebalance只​会​在​已​有​的​source上​进​行​。​参​数​"-d"如​果​给​定​,那​么​工​具​的​日​志​输​出​中​将​包​含​debug信​息​。​
在​新​source “​s1,s2,s3,s4”​ 被​添​加​进​集​群​之​后​,可​以​使​用​上​面​这​个​命​令​自​动​对​集​群​中​所​有​的​shard表​进​行​rebalance,将​数​据​扩​展​到​新​的​source上​。​
工​具​执​行​过​程​中​的​日​志​文​件​位​于​工​具​运​行​目​录​的​dbscale_rebalance.log。​

第 10 章 DBScale 数​据​源​

DBScale 数​据​源​( data-source )是​提​供​数​据​库​连​接​用​来​执​行​具​体​客​户​端​请​求​的​一​组​数​据​库​实​例​。​DBScale 支​持​五​种​类​型​的​ data-source,分​别​为​:server 类​型​、​read_only类​型​、​share_disk 类​型​、​load_baleance 类​型​、​multiple_master 类​型​、​rwsplit 类​型​、​以​及​ replication 类​型​, 不​同​的​ data-source 类​型​定​义​了​不​同​的​组​织​管​理​策​略​。​本​章​将​对​这​四​种​类​型​的​ data-source 进​行​详​细​的​介​绍​。​

10.1. server 类​型​

Server 类​型​的​ data-source 对​应​于​一​台​数​据​库​实​例​,其​详​细​配​置​参​照​ 第 3.3.5.1 节 “server data-source”。​
DBScale 为​该​类​型​ data-source 的​唯​一​数​据​库​实​例​维​护​一​个​连​接​池​,并​需​要​在​配​置​时​指​定​其​初​始​值​、​最​大​值​、​低​阈​值​、​以​及​高​阈​值​。​其​中​最​大​值​定​义​了​连​接​池​最​大​允​许​的​连​接​数​,其​值​直​接​限​制​连​接​的​客​户​端​上​限​,该​值​过​低​会​影​响​同​时​连​接​的​客​户​端​的​数​量​,值​过​高​时​则​会​在​同​时​连​接​的​客​户​端​较​多​时​影​响​数​据​的​读​写​操​作​的​性​能​,其​它​类​型​的​ data-source 在​配​置​连​接​池​时​需​要​考​虑​同​样​的​问​题​。​由​于​ server data-source 只​维​护​一​个​数​据​库​实​例​,该​类​型​ data-source 上​所​有​的​执​行​都​将​直​接​发​送​到​其​唯​一​的​后​端​数​据​库​ server 实​例​中​,它​并​不​能​提​供​其​它​额​外​的​功​能​,因​而​不​推​荐​在​实​际​应​用​场​景​中​单​独​配​置​使​用​。​

10.2. read-only 类​型​

Read-only 类​型​的​ data-source 对​应​于​一​台​数​据​库​实​例​,其​详​细​配​置​参​照​ 第 3.3.5.2 节 “read-only data-source”。​
由​于​ read-only data-source 只​维​护​一​个​数​据​库​实​例​,该​类​型​ data-source 上​所​有​的​执​行​都​将​直​接​发​送​到​其​唯​一​的​后​端​数​据​库​ server 实​例​中​,并​且​该​类​型​的​ data-source 只​支​持​读​操​作​,如​果​用​户​进​行​写​操​作​ DBScale 会​报​错​。​同​时​该​类​型​的​ data-source 不​能​作​为​其​他​类​型​ data-source 的​子​ data-source。​

10.3. share_disk 类​型​

Share_disk 类​型​的​ data-source 封​装​了​一​对​共​享​数​据​存​储​的​数​据​库​实​例​,分​别​为​ active 和​ cold_standby,其​详​细​配​置​参​照​ 第 3.3.5.3 节 “share_disk data-source”。​
该​类​型​的​ data-source 一​般​情​况​下​只​会​使​用​ active 获​取​连​接​,但​当​ active 的​ server 不​可​用​时​,该​类​型​数​据​源​会​自​动​启​用​ cold_standby 的​ server,并​且​交​换​这​2个​ server 的​角​色​。​当​新​ active 节​点​正​常​启​动​后​,该​类​型​数​据​源​会​自​动​去​停​止​ cold_standby 节​点​。​如​果​有​主​从​复​制​关​系​,在​进​行​角​色​交​换​时​会​自​动​进​行​主​从​复​制​的​调​整​。​
参​数​ mysql-server-script 是​ share_disk 数​据​源​用​于​启​动​和​停​止​ cold_standby server 的​脚​本​。​
需​要​注​意​的​是​,share disk 数​据​源​本​身​不​维​护​ active 和​ cold_standby 节​点​间​的​数​据​共​享​,可​以​在​外​部​使​用​ DRBD 或​ gluster-fs 来​实​现​数​据​共​享​。​

10.4. load_balance 类​型​

Load_balance 类​型​的​ data-source 封​装​了​一​组​负​载​均​衡​的​数​据​库​实​例​,其​详​细​配​置​参​照​ 第 3.3.5.4 节 “load_balance data-source”。​
该​类​型​的​ data-source 配​置​了​多​个​数​据​库​ server 实​例​,当​需​要​从​ data-source 中​获​取​连​接​时​,会​按​照​一​定​的​负​载​均​衡​算​法​,选​择​一​个​数​据​库​实​例​来​提​供​连​接​。​DBScale 目​前​只​提​供​了​基​于​轮​询​的​负​载​均​衡​算​法​ round_robin,该​算​法​会​依​次​顺​序​的​从​所​有​配​置​的​ server 中​获​取​用​户​执​行​ sql 请​求​的​连​接​。​同​时​,DBScale 需​要​对​所​有​配​置​的​ server 维​护​一​个​连​接​池​,详​见​ server 类​型​数​据​源​中​对​连​接​池​的​说​明​。​
该​类​ data-source 能​够​降​低​用​户​执​行​的​ sql 请​求​分​散​到​多​个​ server 中​执​行​,降​低​单​个​ server 执​行​语​句​的​压​力​,因​而​在​实​际​应​用​中​有​较​为​广​泛​的​应​用​场​景​。​DBScale 用​于​登​陆​验​证​的​ authenticate-source 可​以​配​置​为​ load_balance,此​外​,load_balance 也​被​用​来​配​置​一​组​只​读​的​数​据​库​实​例​用​以​提​供​高​效​的​历​史​信​息​查​询​等​。​

10.5. multiple_master 类​型​

multiple_master 类​型​的​数​据​源​与​ share_disk 类​型​的​数​据​源​类​似​,但​没​有​ coldstandby,取​而​代​之​的​是​多​个​读​实​例​,所​有​写​操​作​都​发​往​ active 实​例​,而​读​操​作​会​在​多​个​读​实​例​之​间​轮​询​,实​现​读​操​作​的​负​载​均​衡​,其​详​细​配​置​参​照​ 第 3.3.5.5 节 “multiple_master data-source”。​
multiple_master 类​型​数​据​源​的​多​个​数​据​库​实​例​之​间​可​以​进​行​角​色​互​换​。​当​ active 节​点​故​障​时​,一​个​读​实​例​会​被​提​升​成​新​的​ active,而​当​故​障​的​ active 重​新​恢​复​后​,它​会​被​降​级​为​读​实​例​,不​再​负​责​相​应​写​操​作​,只​参​与​读​操​作​的​负​载​均​衡​轮​询​。​
需​要​注​意​的​是​,multiple_master 数​据​源​本​身​不​维​护​节​点​间​的​数​据​一​致​性​,需​要​使​用​类​似​于​ Galera Cluster 的​数​据​库​集​群​来​实​现​数​据​一​致​性​保​证​。​

10.6. rwsplit 类​型​

Rwsplit 类​型​的​ data-source 是​一​个​读​写​分​离​的​数​据​源​,详​细​配​置​参​照​ 第 3.3.5.6 节 “rwsplit data-source”。​
该​类​型​的​ data-source 配​置​了​一​个​写​ server 和​多​个​读​ server,其​中​所​有​的​查​询​操​作​,如​ select、​show、​desc 等​,其​ sql 请​求​都​将​发​送​到​读​节​点​的​ server 执​行​;而​所​有​的​写​操​作​,如​ insert、​update、​delete 等​,都​只​发​送​到​写​节​点​的​ server 上​执​行​。​同​时​,所​有​的​读​节​点​ server 之​间​采​用​负​载​均​衡​的​策​略​,同​ load_balance 一​样​, DBScale 目​前​只​提​供​ round-robin 一​种​负​载​均​衡​的​算​法​。​DBScale 同​样​需​要​对​写​节​点​和​所​有​的​读​节​点​ server 配​置​维​护​一​个​连​接​池​,详​见​ server 类​型​中​对​连​接​池​的​说​明​。​
DBScale 只​负​责​对​ rwsplit 数​据​源​进​行​读​写​分​离​,并​不​维​护​读​写​节​点​之​间​的​主​从​关​系​。​

10.7. replication 类​型​

Replication 类​型​的​ data-source 封​装​了​一​组​主​从​复​制​的​数​据​库​实​例​,其​详​细​配​置​参​照​ 第 3.3.5.7 节 “replication data-source”。​
该​类​型​的​ data-source 由​一​个​主​节​点​( master )和​多​个​从​节​点​( slave )组​成​,不​同​于​其​它​类​型​的​ data-source,其​主​节​点​或​从​节​点​既​可​以​是​ server,也​可​以​是​一​个​独​立​的​ data-source,而​主​节​点​和​所​有​的​从​节​点​之​间​属​于​主​从​复​制​的​关​系​。​
Replication data-source 可​以​级​联​其​他​的​ data-source,包​括​ replication data-source。​通​过​级​联​别​的​ replication data-source 的​方​式​,可​以​搭​建​ 2 级​甚​至​多​级​复​制​的​复​杂​集​群​,并​且​ replication data-source 会​在​集​群​出​现​故​障​的​时​候​自​动​调​整​多​级​复​制​集​群​的​复​制​关​系​,保​持​集​群​的​可​用​性​。​
大​多​数​情​况​下​推​荐​使​用​ replication 数​据​源​,replication 数​据​源​ 提​供​了​数​据​热​备​、​故​障​切​换​高​可​用​、​负​载​均​衡​等​实​用​功​能​可​以​很​大​程​度​上​提​高​线​上​业​务​的​可​靠​性​与​性​能​。​

10.7.1. 主​从​复​制​功​能​

Replication data-source 一​个​基​本​功​能​就​是​进​行​数​据​的​主​从​复​制​,实​现​数​据​的​热​备​分​。​它​有​一​个​主​节​点​( master )和​多​个​从​节​点​( slave )组​成​,不​同​与​其​它​ 3 类​ data-source,它​的​主​节​点​和​从​节​点​不​但​可​以​配​置​为​ data-server,也​可​以​配​置​为​任​何​类​型​的​ data-source,而​主​节​点​的​ data-server 或​者​ data-source 和​所​有​从​节​点​的​ data-server 或​者​ data-source 之​间​属​于​主​从​复​制​的​关​系​,从​节​点​能​够​复​制​主​节​点​的​数​据​并​实​现​数​据​的​热​备​分​。​同​时​,当​配​置​从​节​点​为​ replication data-source 的​时​候​,可​以​搭​建​ 2 级​甚​至​多​级​复​制​的​复​杂​集​群​。​同​样​,replication 需​要​为​所​有​的​ data-source 的​所​有​ server 维​护​连​接​池​,每​个​ server 的​连​接​池​详​见​ server data-source 中​对​连​接​池​的​说​明​。​
数​据​的​主​从​复​制​,不​能​避​免​的​存​在​数​据​延​迟​的​问​题​。​DBScale 能​够​技​术​性​屏​蔽​延​迟​过​高​的​从​节​点​,当​某​个​从​节​点​的​延​迟​高​于​ DBScale 允​许​的​最​大​延​迟​,DBScale 认​为​该​节​点​不​可​用​,并​屏​蔽​该​节​点​。​(见​ max-replication-delay。​)DBScale 同​时​提​供​策​略​规​避​查​询​时​的​数​据​不​一​致​的​问​题​,通​过​指​定​ real-time-queries 参​数​,用​户​可​以​指​定​一​个​写​操​作​之​后​的​几​个​读​操​作​将​会​被​发​往​主​节​点​执​行​,如​此​,这​些​操​作​的​数​据​将​是​没​有​延​迟​的​正​确​数​据​,从​而​减​少​了​数​据​延​迟​的​几​率​。​(见​ real-time-queries。​)

10.7.2. 读​写​分​离​功​能​

Replication 默​认​提​供​数​据​读​写​分​离​的​功​能​,它​较​ rwsplit 更​为​复​杂​。​和​ rwsplit 不​同​的​是​,写​节​点​和​所​有​的​读​节​点​之​间​存​在​主​从​关​系​,而​且​所​有​的​读​写​节​点​本​身​都​可​以​为​ data-source。​Replication 提​供​ 3 种​读​写​分​离​的​策​略​来​实​现​负​载​均​衡​,这​ 3 种​策​略​分​别​为​:
1. SLAVE,正​常​的​读​写​分​离​策​略​,所​有​的​写​操​作​发​送​到​主​节​点​执​行​,读​操​作​发​送​到​从​节​点​。​
2. MASTER,所​有​的​读​写​操​作​均​发​送​到​主​节​点​进​行​,此​时​相​当​于​关​闭​了​读​写​分​离​的​功​能​。​
3. MASTER-SLAVE, 写​操​作​发​送​到​主​节​点​,读​操​作​则​会​发​送​到​主​节​点​和​从​节​点​中​,此​时​主​从​节​点​均​参​与​读​操​作​的​负​载​均​衡​。​
由​于​每​个​节​点​既​可​以​是​单​个​ server,也​可​以​是​ data-source,因​此​在​进​行​负​载​均​衡​时​,需​要​在​所​有​的​单​个​ data-server 和​ data-source 下​的​所​有​ server 之​间​进​行​。​同​样​,DBSCale 目​前​仅​支​持​轮​询​的​ round_robin 负​载​均​衡​算​法​。​

10.7.3. 故​障​切​换​

DBScale 会​自​动​维​护​节​点​之​间​的​主​从​复​制​关​系​,当​ replication 的​主​节​点​发​生​故​障​时​,会​自​动​从​从​节​点​中​选​择​一​个​作​为​新​的​主​节​点​,这​个​选​择​的​节​点​可​以​是​一​个​ data-server,也​可​以​是​一​个​ data-source。​当​选​择​的​节​点​为​ data-source,是​从​该​ data-source 中​选​择​一​个​ data-server,并​且​它​只​能​是​ server 类​型​或​者​ load_balance 类​型​,rwsplit 及​ replication 类​型​的​ data-source 不​会​被​选​择​为​新​的​主​节​点​;此​外​,选​主​的​ data-server 的​ master-backup 值​不​能​为​ 0。​此​外​,在​重​新​选​主​时​,对​于​延​迟​超​过​ max-replication-delay-potential-master 的​节​点​,DBScale 会​自​动​忽​略​该​节​点​。​
当​原​来​的​主​节​点​恢​复​时​,DBScale 会​自​动​将​它​调​整​为​新​主​节​点​的​一​个​从​节​点​。​对​于​ 2 级​甚​至​多​级​复​制​的​复​杂​集​群​,replication 也​能​够​在​集​群​出​现​故​障​的​时​候​自​动​调​整​集​群​的​多​级​复​制​关​系​,保​持​集​群​的​可​用​性​。​
当​开​启​自​动​回​切​功​能​时​,需​要​配​置​几​个​相​关​的​参​数​:
1. master-change-back-conn-in-use-retry:主​节​点​回​切​过​程​中​等​待​当​前​工​作​主​节​点​释​放​正​在​使​用​的​连​接​的​次​数​。​
2. master-change-back-wait:重​试​回​切​主​节​点​的​时​间​间​隔​。​

第 11 章  DBScale 分​片​表​