<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/css" href="/css/feed.min.862ab8f8bb15f1f3203a5b9e6a474b6fcd7e7137c22209e346175b0856acfd97.css"?><rss data-theme="dark" data-theme-default="dark" version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:h="http://www.w3.org/1999/xhtml"><channel><title>Region Split · atman · ihx.cc | AirPlan - A biger solution</title><link>https://atman.ihx.cc/tags/region-split/</link><description>君子不器，日日自新。一處關於技術、生活與自我探索的行記。</description><language>zh-CN</language><generator>Hugo</generator><copyright>DataBase - Atman as @man</copyright><lastBuildDate>Fri, 24 Aug 2018 00:00:00 +0800</lastBuildDate><atom:link href="https://atman.ihx.cc/tags/region-split/index.xml" rel="self" type="application/rss+xml"/><h:script src="/js/theme.min.e9b6d7597dde98fbf1181117d7e72cec3c16ab35de5b3f3bdb17dbd866e0c62c.js" type="text/javascript" defer="defer"/><h:header class="feed-header"><h:nav><h:a href="https://atman.ihx.cc/">首页</h:a><h:a href="https://atman.ihx.cc/archive/">Archive</h:a><h:button id="theme-toggle" class="feed-theme-toggle" type="button" aria-label="暗色模式" aria-pressed="true" title="切换亮暗风格">亮 / 暗</h:button></h:nav><h:p class="feed-eyebrow">RSS / 全文订阅</h:p><h:h1>Region Split · atman · ihx.cc | AirPlan - A biger solution</h:h1><h:p>将下面的地址粘贴到 RSS 阅读器，即可订阅更新。这里展示最近 1 篇文章的摘要，阅读器中可阅读文章全文。</h:p><h:a class="feed-address" href="https://atman.ihx.cc/tags/region-split/index.xml">https://atman.ihx.cc/tags/region-split/index.xml</h:a><h:p class="feed-note">包含 post 和 look 中的文章 · 按发布时间倒序</h:p></h:header><item><title>School - TiDB Region Spilt</title><link>https://atman.ihx.cc/post/20180824-34-region-spilt/</link><guid isPermaLink="true">https://atman.ihx.cc/post/20180824-34-region-spilt/</guid><pubDate>Fri, 24 Aug 2018 00:00:00 +0800</pubDate><dc:creator>Atman</dc:creator><category>Region Split</category><category>Troubleshooting</category><description>0x00 元 收到监控 &amp;amp; 业务告警，内容为目前 QPS duration &amp;gt; 1s 首先排查监控缩小范围 交叉信息判定为 region 超过 144mb 以后未分裂，造成 get snapshot 持续失败，同时 region 过大造成写入和读取数据动作资源消耗过大 SQL 读取数据时 tikv 向命中每 region 发送单次 tikvRPC 请求； …</description><content:encoded><![CDATA[<h2 id="0x00-元">0x00 元</h2>
<blockquote>
<p>收到监控 &amp; 业务告警，内容为目前 QPS duration &gt; 1s<br>
首先排查监控缩小范围</p>
</blockquote>
<p><img src="https://atman.ihx.cc/post/20180824-34-region-spilt/1-qps.png" alt="ap.tidb.cc TiDB Region Spilt QPS duration" title="ap.tidb.cc TiDB Region Spilt" loading="lazy" decoding="async">
<br>
<img src="https://atman.ihx.cc/post/20180824-34-region-spilt/2-apply.png" alt="ap.tidb.cc TiDB Region Spilt apply cpu 上涨" title="ap.tidb.cc TiDB Region Spilt" loading="lazy" decoding="async">
<br>
<img src="https://atman.ihx.cc/post/20180824-34-region-spilt/3-max.png" alt="ap.tidb.cc TiDB Region Spilt region 大小" title="ap.tidb.cc TiDB Region Spilt" loading="lazy" decoding="async">
<br>
<img src="https://atman.ihx.cc/post/20180824-34-region-spilt/4-snapshot.png" alt="ap.tidb.cc TiDB Region Spilt get snapshot failed" title="ap.tidb.cc TiDB Region Spilt" loading="lazy" decoding="async">
<br>
<img src="https://atman.ihx.cc/post/20180824-34-region-spilt/5-schedule.png" alt="ap.tidb.cc TiDB Region Spilt schedule duration" title="ap.tidb.cc TiDB Region Spilt" loading="lazy" decoding="async">
</p>
<blockquote>
<p>交叉信息判定为 region 超过 144mb 以后未分裂，造成 get snapshot 持续失败，同时 region 过大造成<strong>写入和读取</strong>数据动作资源消耗过大<br>
SQL 读取数据时 tikv 向命中每 region 发送单次 tikvRPC 请求；由于 region 过大，可能包含该 SQL 命中的所有数据，造成 tikvRPC 数据包过大<br>
写入数据时，region 数量大于过半时才能提交成功，region 过大造成无法 compaction 、被 PD schedule region 时成本加大、region 内查询数据成本过大等</p>
</blockquote>
<h3 id="region-spilt">region spilt</h3>
<blockquote>
<p>正常流程</p>
</blockquote>
<ol>
<li>初始化 region ，region id 2</li>
<li>region id 2 写入数据达到 144MB</li>
<li>region id 2 接收 split 操作
<ol>
<li>region 从尾部追加写入</li>
<li>切割时从头部粗略计算 96mb</li>
<li>保持尾部 id 不变、尾部可持续写入</li>
</ol>
</li>
<li>region id 2 分列成 id 2 &amp; id 10 两个 region / 其中 id 2 为 48mb，id 10 为 96mb（实际非精准计算）</li>
</ol>
<blockquote>
<p>异常场景</p>
</blockquote>
<ul>
<li>数据写入过快时，磁盘或者 split cpu work 跟不上时可能会出现 split 持续失败
<ul>
<li>region spilt 单线程工作，前期版本 reigon spilt 根据 IO 大小扫描 96mb 后执行 split</li>
<li>会实际消耗 96mb 扫描 region 的 IOPS / 消耗创建新 region + 创建 snapshot 等 IOPS</li>
</ul>
</li>
</ul>
<h3 id="0x01-二次确认">0x01 二次确认</h3>
<h3 id="tikv-日志">TiKV 日志</h3>
<pre><code class="language-fallback" data-lang="fallback">2018/08/10 22:13:03.168 scheduler.rs:1306: [ERROR] 
    get snapshot failed for cids=[1792370849], error Request(message: &#34;region is stale&#34; 
        stale_epoch {new_regions {id: 4351912 
            start_key:&#34;t\200\000\000\000\000\0009\377\364_i\200\000\000\000\000\377\000\000\003\001A336\3770001\37762\000\377\000\000\000\000\000\371\003\216\377\000\000\001\344\317\341i\000\376&#34; 
            end_key: &#34;t\200\000\000\000\000\0009\377\364_i\200\000\000\000\000\377\000\000\003\001A760\3770035\37733\000\377\000\000\000\000\000\371\003\200\377\000\000\000\000\2233\242\000\376&#34; 
        region_epoch {conf_ver: 1153 version: 15846} peers {id: 4351914 store_id: 4215749} peers {id: 4351915 store_id: 3169321} peers {id: 4841324 store_id: 8}} 
    new_regions {id: 4841440 
            start_key: &#34;t\200\000\000\000\000\0009\377\364_i\200\000\000\000\000\377\000\000\003\001A120\3770031\37739\000\377\000\000\000\000\000\371\003\200\377\000\000\000\000V\311\254\000\376&#34; 
            end_key: &#34;t\200\000\000\000\000\0009\377\364_i\200\000\000\000\000\377\000\000\003\001A336\3770001\37762\000\377\000\000\000\000\000\371\003\216\377\000\000\001\344\317\341i\000\376&#34; 
        region_epoch {conf_ver: 1153 version: 15846} peers {id: 4841441 store_id: 4215749} peers {id: 4841442 store_id: 3169321} peers {id: 4841443 store_id: 8}}})
</code></pre><h3 id="region-meta">Region meta</h3>
<pre><code class="language-json" data-lang="json">» region 4803248
{
  &#34;id&#34;: 4803248,
  &#34;start_key&#34;: &#34;t\\x80\\x00\\x00\\x00\\x00\\x00:\\xff$_r\\x80\\x00\\x00\\x00&#39;\\xffױ\\xf4\\x00\\x00\\x00\\x00\\x00\\xfa&#34;,
  &#34;end_key&#34;: &#34;&#34;,
  &#34;epoch&#34;: {
    &#34;conf_ver&#34;: 1159,
    &#34;version&#34;: 17467
  },
  &#34;peers&#34;: [
    {
      &#34;id&#34;: 4227577,
      &#34;store_id&#34;: 4215744
    },
    {
      &#34;id&#34;: 4803248,
      &#34;store_id&#34;: 4215749
    },
    {
      &#34;id&#34;: 4804713,
      &#34;store_id&#34;: 4
    }
  ],
  &#34;leader&#34;: {
    &#34;id&#34;: 4803248,
    &#34;store_id&#34;: 4215749
  },
  &#34;pending_peers&#34;: [
    {
      &#34;id&#34;: 4804713,
      &#34;store_id&#34;: 4
    }
  ],
  &#34;written_bytes&#34;: 267,
  &#34;approximate_size&#34;: 124183 // 此处是 MB 大小。正常应该再 144M 以内
}
</code></pre><h3 id="0x02-修复">0x02 修复</h3>
<ul>
<li>
<p>查看 split 线程状态使用用 <code>strace -p &quot;tid of split worker&quot;</code></p>
<ul>
<li>strace 会阻断程序运行，谨慎使用</li>
</ul>
</li>
<li>
<p>使用 PD-ctl 工具手工发起 split region 请求</p>
<pre><code class="language-json" data-lang="json">&gt;&gt; operator add split-region 1 --policy=approximate     // 将 Region 1 对半拆分成两个 Region，基于粗略估计值
&gt;&gt; operator add split-region 1 --policy=scan            // 将 Region 1 对半拆分成两个 Region，基于精确扫描值
</code></pre></li>
</ul>
<p><img src="https://atman.ihx.cc/post/20180824-34-region-spilt/6-split.png" alt="ap.tidb.cc TiDB Region Spilt region split 请求后" title="ap.tidb.cc TiDB Region Spilt" loading="lazy" decoding="async">
<br>
<img src="https://atman.ihx.cc/post/20180824-34-region-spilt/7-snapshot-cpu.png" alt="ap.tidb.cc TiDB Region Spilt region split 请求后 snapshot cpu 占用" title="ap.tidb.cc TiDB Region Spilt" loading="lazy" decoding="async">
<br>
<img src="https://atman.ihx.cc/post/20180824-34-region-spilt/8-region-sum.png" alt="ap.tidb.cc TiDB Region Spilt region split 请求后 region 增长状态" title="ap.tidb.cc TiDB Region Spilt" loading="lazy" decoding="async">
</p>
]]></content:encoded><h:time datetime="2018-08-24T00:00:00+08:00">2018-08-24 · post</h:time><h:a class="feed-article-title" href="https://atman.ihx.cc/post/20180824-34-region-spilt/">School - TiDB Region Spilt</h:a></item></channel></rss>