简体   繁体   English

MySQL / MariaDB复制:我可以中断该过程吗?

[英]MySQL/MariaDB replication: Can I interrupt the process?

I have a replication setup here where data get replicated from a stationary host to a notebook. 我这里有一个复制设置,其中数据从固定主机复制到笔记本。

Replication happens in two steps: the copying of the relay files, which is quite fast, and the application of the relay log events to the database, which tends to be slow. 复制过程分两个步骤:中继文件的复制(非常快)和中继日志事件到数据库的应用(这往往很慢)。

Now my question: Suppose the slave has gotten all data from the master, but the "import process" still runs. 现在我的问题是:假设从服务器已从主服务器获取了所有数据,但“导入过程”仍在运行。 Can I safely shut down the slave host and resume the still pending part of the replication without disturbing the process in any way? 我可以安全地关闭从属主机并恢复复制中仍未完成的部分,而不会以任何方式干扰该过程吗?

So I am connected to the host, say "stop slave", shut down the notebook, go home and then "start slave" again without having a connection to the host. 因此,我已连接到主机,说“停止从站”,关闭笔记本计算机,回家,然后再次“启动从站”,而没有连接到主机。 Can I expect the slave instance to resume the import process again? 我可以期望从属实例再次恢复导入过程吗?

Your laptop is permanently a Slave to the other machine, correct? 您的笔记本电脑永远是另一台计算机的从机,对吗? You are just breaking the network connection to the Master every night? 您只是每天晚上都断开与Master的网络连接?

There are two threads on the Slave. 从站上有两个线程。 The I/O thread is responsible for pulling data from the binlog on the Master and putting the stuff into the "relay-log" on the Slave. I / O线程负责从主服务器上的二进制日志中提取数据,并将这些内容放入从属服务器上的“中继日志”中。 If (when) the network goes away, this thread repeatedly retries. 如果(何时)网络消失,则该线程反复重试。 There are settings that say how frequently and when to eventually give up. 有一些设置可以说明最终放弃的频率和时间。 Consider tuning them. 考虑调整它们。

The SQL thread is responsible for applying whatever is in the relay-log. SQL线程负责应用中继日志中的所有内容。 Effectively, the SQL thread can run all the time. 实际上,SQL线程可以一直运行。 It's quite happy to "do nothing" when there is nothing to do. 无事可做时“什么都不做”是很高兴的。

The I/O thread creates new relay-log files as needed; I / O线程根据需要创建新的中继日志文件。 the SQL thread deletes a log as it finishes with it. SQL线程在完成日志后会删除它。

I have dealt with dozens of slaves over the years; 这些年来,我已经与数十名奴隶打交道。 I don't recall any issue with network or power failures. 我不记得任何有关网络或电源故障的问题。 You are essentially causing at least a network failure every night. 本质上,您每天晚上至少会造成网络故障。 If you are also powering down the laptop, do it gracefully. 如果还关闭了笔记本计算机的电源,请优雅地进行操作。 InnoDB (but not MyISAM) recovers nicely from power failures, but don't push your luck. InnoDB(但不​​是MyISAM)可以从电源故障中很好地恢复,但是请不要碰运气。

STOP/START SLAVE seems unnecessary, but won't hurt. 停止/开始从动似乎不必要,但不会造成伤害。 Things should "resume" and eventually "catch up". 事情应该“恢复”并最终“赶上”。

Your quote talks about the Master purging binlogs. 您的报价谈到了Master清除binlog。 Well, there is an issue here. 好吧,这里有个问题。 The Master does not keep track of what Slaves exist, so it can't tell if your Slave is un-connected for longer than the Master is keeping the binlogs. Master不会跟踪存在哪些Slave,因此无法确定您的Slave断开连接的时间是否长于Master保留二进制日志的时间。

See expires_logs_days . 请参阅expires_logs_days Suggest you set that to higher than the number of vacation days you might ever take. 建议您将其设置为高于您可能需要的休假天数。

My experience with Slaves predates GTIDs, Galera, etc.; 我对Slave的经验早于GTID,Galera等。 will you be using such? 你会用这样吗?

I partially have found the answer to my question: 我部分找到了我问题的答案:

The MySQL documentation says : MySQL文档说

If the slave stops before the SQL thread has executed all the fetched statements, the I/O thread has at least fetched everything so that a safe copy of the statements is stored locally in the slave's relay logs, ready for execution the next time that the slave starts. 如果从服务器在SQL线程执行所有获取的语句之前停止运行,则I / O线程至少已获取所有内容,以便将语句的安全副本本地存储在从服务器的中继日志中,以备下次使用时执行。奴隶开始。 This enables the master server to purge its binary logs sooner because it no longer needs to wait for the slave to fetch their contents. 这使主服务器可以更快地清除其二进制日志,因为它不再需要等待从服务器获取其内容。

This indicates that it is perfectly possible to resume the import process (execution of the statements), however, it still remains unclear 这表明完全有可能恢复导入过程(执行语句),但是仍然不清楚

  1. if I need to start slave before the described things happen and 如果我需要在描述的事情发生之前start slave ,并且
  2. what happens if the slave doesn't find its master if I do start slave . 如果我start slave如果奴隶找不到主人,会发生什么?

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

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