0

我正在使用带有 Innodb 存储引擎版本 10.x 的 Mysql/MariaDB。

我想设置一个具有主从配置的集群。可以选择使用 --innodb-read-only 或 --read-only 从从站读取数据。

但是,除了上述之外,当且仅当 max slave lag 小于 x seconds 时,客户端才需要从 slave 读取数据

由于网络拥塞、低磁盘吞吐量、长时间运行的操作等,从属服务器可能落后于主服务器。具有最大允许陈旧性选项的读取首选项应该让应用程序为从服务器的读取指定最大复制延迟或“陈旧性”。当辅助节点的估计过期时间超过时,客户端停止将其用于从节点的读取操作并开始从主节点读取。

我想知道 MySql/InnoDB 中是否有选项?

4

3 回答 3

1

没有将查询切换到主服务器的自动选项。这由应用程序逻辑处理。

您可以运行查询SHOW SLAVE STATUS,返回的字段之一是Seconds_Behind_Master. 您必须编写应用程序代码来检查这一点,如果滞后大于您的阈值,请改为查询主节点。

您可能会发现某种类型的代理可以为您执行此逻辑。见https://mydbops.wordpress.com/2018/02/19/proxysql-series-mysql-replication-read-write-split-up/

将延迟 X 秒的副本视为不可用并不总是最佳选择。无论滞后如何,一些查询都完全没问题。几年前我写了一篇关于这个的演示文稿,其中包括一些示例查询。 使用 MySQL 和 PHP 进行读/写拆分(Percona 网络研讨会 2013)

于 2018-07-06T15:58:13.240 回答
0
  • There are many Proxy products that may have code for such.
  • If you automatically switch to the Master, then it may get overwhelmed, thereby leading to worse system problem.
  • If you try to switch to another Slave, it is too easy to get into a flapping situation.
  • Galera has a way to deal with "critical read", if you wanted to go to a Cluster setup instead of Master + Slaves.
  • If part of the problem is the distance between Master and Slave, and if you switch to the Master, where is the Client? If it is near the Slave, won't the added time to reach the master cancel out some of the benefit?
  • Avoid long-running queries, beef up the Slave to avoid slow disks, speed up queries that are hitting the disk a lot, look into network improvements.

In summary, I don't like the idea of attempt to move a query to the Master; I would work on dealing with the underlying problem.

于 2018-07-07T14:39:39.850 回答
0

MariaDB MaxScale有多种处理复制滞后的方法。

最简单的方法是使用参数限制最大允许复制延迟max_slave_replication_lag。这完全按照您描述的方式工作:如果一个奴隶比主人落后太多秒,其他奴隶,作为最后的手段,使用主人。这是处理 MaxScale 中复制滞后的最常用方法。

另一种选择是使用causal_reads利用MASTER_GTID_WAITMariaDB 10.2 和更新版本中的其他功能的功能。这允许读取一致性,而不会在主服务器上增加额外的负载。这确实是以延迟为代价的:如果服务器滞后读取几秒钟,则可能需要更长的时间。当数据一致性很重要但请求延迟不那么重要时,使用此选项。

第三种选择是在写入发生后使用CCRFilter强制读取到主机。与此相比,这是一种更简单的方法,causal_reads但它以增加主节点负载为代价提供了数据一致性。

于 2019-12-13T12:33:08.993 回答