简体   繁体   English

MySQL 是否会在 DDL 语句期间停止整个集群?

[英]Does MySQL stalls the whole cluster during DDL statements?

Recently, I read that Galera based MySQL cluster uses a concept called total order isolation ( https://galeracluster.com/library/documentation/schema-upgrades.html#toi ) for DDL's by default which stalls the writes on the whole cluster until it is commited on all the nodes.最近,我读到基于 Galera 的 MySQL 集群使用一个称为总顺序隔离的概念( https://galeracluster.com/library/documentation/schema-upgrades.html#toi )默认情况下用于 DDL,它会在整个集群上停止写入直到它在所有节点上提交。

How does MySQL handles DDL in native asynchronous replication? MySQL如何处理原生异步复制中的DDL? Does it stall writes for the other schemas as well?它是否也会为其他模式停止写入?

Native Replication sticks the DDL into the replication stream. When the command pops up in the Slave, it executes the DDL before moving on to other queries in the replication stream. Native Replication 将 DDL 粘贴到复制 stream 中。当命令在 Slave 中弹出时,它会在继续执行复制 stream 中的其他查询之前执行 DDL。

Caveat: The above statement assumes old flavor, without multi-master replication or multiple replication threads.警告:上面的语句假设是老式的,没有多主复制或多复制线程。 Regardless of this caveat the table being modified is blocked on the Slave just as it was on the Master.不管这个警告如何,被修改的表在从站上被阻塞,就像在主站上一样。

Galera's TOI goes to some extra effort to make sure all the nodes are in sync, even accounting for the DDL versus ordinary writes. Galera 的 TOI 付出了一些额外的努力来确保所有节点同步,甚至考虑到 DDL 与普通写入。 Hnece the name "Total Order of Inserts". Hnece 名称为“总插入顺序”。

Galera's RSU is, in many cases, a viable alternative.在许多情况下,Galera 的 RSU 是一个可行的替代方案。 It is not more invasive than a crash of each node, one at a time (hence "Rolling").它并不比每个节点的崩溃更具侵入性,一次一个(因此“滚动”)。 Assuming connections can failover to different nodes, RSU avoids other blockage.假设连接可以故障转移到不同的节点,RSU 可以避免其他阻塞。

Still, you should make a conscious choice between RSU and TOI;不过,您应该在 RSU 和 TOI 之间做出有意识的选择; there are use cases for dictating one versus the other.有用于指示一个与另一个的用例。

In a distributed system (multiple nodes, multiple clients, etc), pushing code gets tricky.在分布式系统(多节点、多客户端等)中,推送代码变得很棘手。 I like to take this approach, even though it leads to perhaps 3 times as many pushes:我喜欢采用这种方法,尽管它可能导致 3 倍的推送次数:

  1. Push application code to discover whether the database change has been pushed.推送应用程序代码以发现是否已推送数据库更改。 Have the code work either with the old schema or new.让代码使用旧架构或新架构。 Do this "push" in a "rolling" manor在“滚动”的庄园里做这个“推”
  2. Push the new schema (eg CREATE/ALTER TABLE ).推送新模式(例如CREATE/ALTER TABLE )。
  3. Clean up the code.清理代码。 (Again, "roll" it out to the many clients.) (再次,将其“推广”给许多客户。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM