Read Free Replication特性

MyRocks具有一个名为“Read Free Replication”的功能,可显着提高复制性能。 此功能的灵感来自TokuDB。此外还有一个名为“Skip Unique Checking”的功能。

Read Free Replication意味着在UPDATE或DELETE期间不是从数据库中读取旧数据,而是使用binlog中的信息并跳过此步骤。 跳过唯一检查意味着我们可以禁用正在进行的检查,以确保在INSERT或UPDATE期间不存在PRIMARY或UNIQUE键。 这两个功能都可以提高性能,但也存在一些潜在的问题。

控制这些的设置如下:

  1. * rocksdb-read-free-rpl-tables = <list_of_tables> - 为指定的表列表启用“读取自由复制”。
  2. 此功能需要基于行的二进制日志记录。 master上的binlog_row_image选项必须为FULL
  3. * rocksdb_skip_unique_check_tables = <list_of_tables> - 这允许在复制滞后时跳过唯一键检查,
  4. 并与unique_check_lag_threshold/unique_check_lag_reset_threshold 一起使用。
  5. 设置这些值并且从站上的延迟足够高时,系统将停止对指定表执行唯一键检查。

是逗号分隔的列表,可以包含正则表达式。 例如,要指出您可以使用的所有表 . ,或者如果您希望所有以workdb开头的表,您可以使用workdb.。 Read Free Replication有一些限制,必须小心使用,否则某些索引可能会被破坏。 一般的经验法则是,您不应该在复制之外的从站上直接插入/更新/删除。如果直接修改从站,则二级索引损坏时有两个示例。

1、辅助索引一些行丢失

  1. create table t (id int primary key, i1 int, i2 int, value int, index (i1), index (i2)) engine=rocksdb;
  2. insert into t values (1,1,1,1),(2,2,2,2),(3,3,3,3);
  3. s:
  4. delete from t where id <= 2;
  5. m:
  6. update t set i2=100, value=100 where id=1;
  7. s:
  8. mysql> select count(*) from t force index(primary);
  9. +----------+
  10. | count(*) |
  11. +----------+
  12. | 2 |
  13. +----------+
  14. 1 row in set (0.00 sec)
  15. mysql> select count(*) from t force index(i1);
  16. +----------+
  17. | count(*) |
  18. +----------+
  19. | 1 |
  20. +----------+
  21. 1 row in set (0.00 sec)
  22. mysql> select count(*) from t force index(i2);
  23. +----------+
  24. | count(*) |
  25. +----------+
  26. | 2 |
  27. +----------+
  28. 1 row in set (0.00 sec)
  29. mysql> select * from t where id=1;
  30. +----+------+------+-------+
  31. | id | i1 | i2 | value |
  32. +----+------+------+-------+
  33. | 1 | 1 | 100 | 100 |
  34. +----+------+------+-------+
  35. 1 row in set (0.00 sec)
  36. mysql> select i1 from t where i1=1;
  37. Empty set (0.00 sec)
  38. mysql> select i2 from t where i2=100;
  39. +------+
  40. | i2 |
  41. +------+
  42. | 100 |
  43. +------+
  44. 1 row in set (0.00 sec)

2、辅助索引有额外的行

  1. M:
  2. create table t (id int primary key, i1 int, i2 int, value int, index (i1), index (i2)) engine=rocksdb;
  3. insert into t values (1,1,1,1),(2,2,2,2),(3,3,3,3);
  4. S:
  5. update t set i1=100 where id=1;
  6. M:
  7. delete from t where id=1;
  8. S:
  9. mysql> select count(*) from t force index(primary);
  10. +----------+
  11. | count(*) |
  12. +----------+
  13. | 2 |
  14. +----------+
  15. 1 row in set (0.00 sec)
  16. mysql> select count(*) from t force index(i1);
  17. +----------+
  18. | count(*) |
  19. +----------+
  20. | 3 |
  21. +----------+
  22. 1 row in set (0.00 sec)
  23. mysql> select count(*) from t force index(i2);
  24. +----------+
  25. | count(*) |
  26. +----------+
  27. | 2 |
  28. +----------+
  29. 1 row in set (0.00 sec)
  30. mysql> select i1 from t where i1=100;
  31. +------+
  32. | i1 |
  33. +------+
  34. | 100 |
  35. +------+
  36. 1 row in set (0.00 sec)

MyRocks支持一个类似的mysql系统变量’unique_checks’,我觉得有些用户很有用。 禁用此会话变量(设置unique_checks = OFF)将禁用给定会话的唯一检查。 此系统变量也通过复制流传播,这意味着从属设备也将跳过唯一检查,这可以减少批量加载等大型事务的复制延迟。 与Read Free Replication类似,如果从站上不允许进行其他修改,则使用Skip Unique Checks对从站应该是安全的。 如果从站上允许更改(复制除外),则可能会在从站上获取不正确的数据。建议不要在主服务器上启用“跳过唯一检查”,除非您100%确定已插入的数据尚不存在。