Shadow

Usage

Pre-work

  1. Start the MySQL service
  2. Create MySQL database (refer to ShardingProxy data source configuration rules)
  3. Create a role or user with creation permission for ShardingProxy
  4. Start Zookeeper service (for persistent configuration)

Start ShardingProxy

  1. Add mode and authentication configurations to server.yaml (please refer to the example of ShardingProxy)
  2. Start ShardingProxy (Related introduction)

Create a distributed database and sharding tables

  1. Connect to ShardingProxy
  2. Create a distributed database
  1. CREATE DATABASE shadow_db;
  1. Use newly created database
  1. USE shadow_db;
  1. Configure data source information
  1. ADD RESOURCE ds_0 (
  2. HOST=127.0.0.1,
  3. PORT=3306,
  4. DB=ds_0,
  5. USER=root,
  6. PASSWORD=root
  7. ),ds_1 (
  8. HOST=127.0.0.1,
  9. PORT=3306,
  10. DB=ds_1,
  11. USER=root,
  12. PASSWORD=root
  13. ),ds_2 (
  14. HOST=127.0.0.1,
  15. PORT=3306,
  16. DB=ds_2,
  17. USER=root,
  18. PASSWORD=root
  19. );
  1. Create shadow rule
  1. CREATE SHADOW RULE group_0(
  2. SOURCE=ds_0,
  3. SHADOW=ds_1,
  4. t_order((simple_note_algorithm, TYPE(NAME=SIMPLE_NOTE, PROPERTIES("shadow"="true", foo="bar"))),(TYPE(NAME=COLUMN_REGEX_MATCH, PROPERTIES("operation"="insert","column"="user_id", "regex"='[1]')))),
  5. t_order_item((TYPE(NAME=SIMPLE_NOTE, PROPERTIES("shadow"="true", "foo"="bar")))));
  1. Alter shadow rule
  1. ALTER SHADOW RULE group_0(
  2. SOURCE=ds_0,
  3. SHADOW=ds_2,
  4. t_order_item((TYPE(NAME=SIMPLE_NOTE, PROPERTIES("shadow"="true", "foo"="bar")))));
  1. Drop shadow rule
  1. DROP SHADOW RULE group_0;
  1. Drop resource
  1. DROP RESOURCE ds_0,ds_1,ds_2;
  1. Drop distributed database
  1. DROP DATABASE shadow_db;

Notice

  1. Currently, DROP DATABASE will only remove the logical distributed database, not the user’s actual database.
  2. DROP TABLE will delete all logical fragmented tables and actual tables in the database.
  3. CREATE DATABASE will only create a logical distributed database, so users need to create actual databases in advance .