<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>读写分离 on C4H</title><link>/tags/%E8%AF%BB%E5%86%99%E5%88%86%E7%A6%BB/</link><description>Recent content in 读写分离 on C4H</description><generator>Hugo</generator><language>zh-CN</language><managingEditor>code4happy@gmail.com (happy-v587)</managingEditor><webMaster>code4happy@gmail.com (happy-v587)</webMaster><lastBuildDate>Mon, 29 Dec 2025 00:00:00 +0800</lastBuildDate><atom:link href="/tags/%E8%AF%BB%E5%86%99%E5%88%86%E7%A6%BB/index.xml" rel="self" type="application/rss+xml"/><item><title>读写分离后为什么会读到旧数据：MaxScale 的一致性读</title><link>/maxscale-mariadb-consistency-read/</link><pubDate>Mon, 29 Dec 2025 00:00:00 +0800</pubDate><author>code4happy@gmail.com (happy-v587)</author><guid>/maxscale-mariadb-consistency-read/</guid><description>&lt;h2 id="问题" class="headerLink"&gt;
 &lt;a href="#%e9%97%ae%e9%a2%98" class="header-mark"&gt;&lt;/a&gt;问题&lt;/h2&gt;&lt;p&gt;读写分离最容易让人困惑的一幕是：写请求已经返回成功，紧接着发起查询，却没有看到刚写入的数据。这里不一定是事务没有提交，而是写落在主库后，读被路由到了尚未追上复制进度的副本。&lt;/p&gt;
&lt;p&gt;那么，有什么办法可以解决这个问题呢？那就是本文要分析的 MaxScale，它解决了这个问题。&lt;/p&gt;
&lt;h2 id="maxscale-的解决方案" class="headerLink"&gt;
 &lt;a href="#maxscale-%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88" class="header-mark"&gt;&lt;/a&gt;MaxScale 的解决方案&lt;/h2&gt;&lt;p&gt;MaxScale 的一致性读思路是把“这次写已经产生到哪里”的 GTID 获取到，再让之后的读请求以这个位置为边界：要么等待只读节点追上，要么直接选择已经追上的只读节点。&lt;/p&gt;</description></item></channel></rss>