@@ -754,6 +754,8 @@ new capacity : 00100000
|
||||
- 为 0,那么 hash%00010000 = hash%00100000,桶位置和原来一致;
|
||||
- 为 1,hash%00100000 = hash%00010000 + 16,桶位置是原位置 + 16。
|
||||
|
||||
<div align="center"> <img src="pics/hashmap-resize.png" width="560px"/> </div><br>
|
||||
|
||||
#### 7. 计算数组容量
|
||||
|
||||
HashMap 构造函数允许用户传入的容量不是 2 的 n 次方,因为它可以自动地将传入的容量转换为 2 的 n 次方。
|
||||
|
||||
@@ -234,6 +234,8 @@ epoll_ctl() 用于向内核注册新的描述符或者是改变某个文件描
|
||||
|
||||
从上面的描述可以看出,epoll 只需要将描述符从进程缓冲区向内核缓冲区拷贝一次,并且进程不需要通过轮询来获得事件完成的描述符。
|
||||
|
||||
<div align="center"> <img src="pics/epoll.png" width="600px"/> </div><br>
|
||||
|
||||
epoll 仅适用于 Linux OS。
|
||||
|
||||
epoll 比 select 和 poll 更加灵活而且没有描述符数量限制。
|
||||
|
||||
|
After Width: | Height: | Size: 105 KiB |
|
After Width: | Height: | Size: 104 KiB |
|
After Width: | Height: | Size: 99 KiB |
|
After Width: | Height: | Size: 121 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 81 KiB |
|
After Width: | Height: | Size: 65 KiB |
|
After Width: | Height: | Size: 104 KiB |
|
After Width: | Height: | Size: 116 KiB |
|
After Width: | Height: | Size: 57 KiB |
@@ -210,6 +210,8 @@ TCC(Try-Confirm-Cancel)是在业务层面实现的两阶段提交,每个
|
||||
|
||||
Saga 将一个分布式事务拆分为多个本地事务,每个本地事务直接提交,并且都有一个对应的补偿操作。依次执行各个本地事务,如果某一个失败,就逆序执行前面已经提交的本地事务的补偿操作。
|
||||
|
||||
<div align="center"> <img src="pics/saga.png" width="540px"/> </div><br>
|
||||
|
||||
Saga 没有预留资源的 Try 阶段,中间状态对其它事务可见,因此没有隔离性。它适合流程长、无法长时间锁定资源的业务,正向操作和补偿操作同样需要实现幂等。
|
||||
|
||||
### 本地消息表
|
||||
@@ -226,6 +228,8 @@ Saga 没有预留资源的 Try 阶段,中间状态对其它事务可见,因
|
||||
|
||||
RocketMQ 的事务消息把本地消息表的工作交给了消息队列:生产者先发送一条对消费者不可见的半消息,再执行本地事务,然后根据执行结果通知 Broker 提交或者回滚这条消息。如果 Broker 长时间没有收到通知,会主动回查生产者的本地事务状态。
|
||||
|
||||
<div align="center"> <img src="pics/rocketmq-transaction.png" width="540px"/> </div><br>
|
||||
|
||||
## 三、CAP
|
||||
|
||||
分布式系统不可能同时满足一致性(C:Consistency)、可用性(A:Availability)和分区容忍性(P:Partition Tolerance)。常见的“三选二”说法有误导性,因为网络分区是无法避免的故障,不是可以选择的选项。
|
||||
|
||||
@@ -122,6 +122,8 @@ http://www.examplebank.com/withdraw?account=AccountName&amount=1000&for=PayeeNam
|
||||
|
||||
如果有账户名为 Alice 的用户访问了恶意站点,而之前刚访问过银行不久,登录信息尚未过期,那么就会损失 1000 美元。
|
||||
|
||||
<div align="center"> <img src="pics/csrf.png" width="540px"/> </div><br>
|
||||
|
||||
这种恶意的网址可以有很多种形式,藏身于网页中的许多地方。此外,攻击者也不需要控制放置恶意网址的网站。例如他可以将这种地址藏在论坛,博客等任何用户生成内容的网站中。这意味着如果服务器端没有合适的防御措施的话,用户即使访问熟悉的可信网站也有受攻击的危险。改为 POST 请求也不能解决问题,攻击者可以使用自动提交的表单。
|
||||
|
||||
通过例子能够看出,攻击者并不能通过 CSRF 攻击来直接获取用户的账户控制权,也不能直接窃取用户的任何信息。他们能做到的,是欺骗用户浏览器,让其以用户的名义执行操作。
|
||||
|
||||
@@ -362,6 +362,8 @@ SELECT c FROM t WHERE c BETWEEN 10 and 20 FOR UPDATE;
|
||||
(20, +∞)
|
||||
```
|
||||
|
||||
<div align="center"> <img src="pics/next-key-locks.png" width="560px"/> </div><br>
|
||||
|
||||
## 七、关系数据库设计理论
|
||||
|
||||
### 函数依赖
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
|
||||
Kafka、RocketMQ 等通过消费者组把两种模型结合起来:一条消息会发送给每个订阅它的消费者组,但在一个消费者组内只会被一个消费者消费。
|
||||
|
||||
<div align="center"> <img src="pics/consumer-group.png" width="560px"/> </div><br>
|
||||
|
||||
发布与订阅模式和观察者模式有以下不同:
|
||||
|
||||
- 观察者模式中,观察者和主题都知道对方的存在;而在发布与订阅模式中,生产者与消费者不知道对方的存在,它们之间通过频道进行通信。
|
||||
|
||||
@@ -111,6 +111,10 @@
|
||||
- 降级:主动关闭部分非核心功能,从而保证核心功能可用;
|
||||
- 熔断:某个依赖的服务持续出错时,暂时不再调用它而是直接返回默认结果,避免故障沿着调用链扩散。
|
||||
|
||||
漏桶以固定速率处理请求,桶满时丢弃新的请求;令牌桶以固定速率放入令牌,请求拿到令牌才能被处理,桶中积累的令牌允许一定的突发流量。
|
||||
|
||||
<div align="center"> <img src="pics/rate-limit.png" width="580px"/> </div><br>
|
||||
|
||||
熔断器有关闭、打开和半开三种状态:失败率超过阈值时打开;打开一段时间后进入半开状态,放行少量请求试探,成功则关闭,失败则重新打开。
|
||||
|
||||
<div align="center"> <img src="pics/circuit-breaker.png" width="500px"/> </div><br>
|
||||
|
||||
@@ -97,6 +97,10 @@ CDN 主要有以下优点:
|
||||
- 对这些不存在的数据缓存一个空数据,并设置较短的过期时间;
|
||||
- 使用布隆过滤器保存所有存在的 Key,对不存在的 Key 的请求直接拒绝。
|
||||
|
||||
布隆过滤器用多个哈希函数把 Key 映射到位数组的多个位置并置为 1。查询时只要有一个位置为 0,Key 就一定不存在;全部为 1 时 Key 可能存在,存在一定的误判率。
|
||||
|
||||
<div align="center"> <img src="pics/bloom-filter.png" width="560px"/> </div><br>
|
||||
|
||||
### 缓存击穿
|
||||
|
||||
指的是某个热点数据的缓存过期时,大量对它的请求同时到达数据库。
|
||||
@@ -200,6 +204,8 @@ Redis Cluster 使用的不是一致性哈希,而是把 Key 映射到固定的
|
||||
- 访问某个节点时,将其从原来的位置删除,并重新插入到链表头部。这样就能保证链表尾部存储的就是最近最久未使用的节点,当节点数量大于缓存最大空间时就淘汰链表尾部的节点。
|
||||
- 为了使删除操作时间复杂度为 O(1),就不能采用遍历的方式找到某个节点。HashMap 存储着 Key 到节点的映射,通过 Key 就能以 O(1) 的时间得到节点,然后再以 O(1) 的时间将其从双向队列中删除。
|
||||
|
||||
<div align="center"> <img src="pics/lru.png" width="560px"/> </div><br>
|
||||
|
||||
Java 的 LinkedHashMap 内部就是这种结构,把 accessOrder 设为 true 并重写 removeEldestEntry 方法,就可以直接得到一个 LRU 缓存。
|
||||
|
||||
```java
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="620" height="300" viewBox="0 0 620 300">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #666; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #777; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.sub { font-size: 11px; fill: #888; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #666; stroke-width: 1.3; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #666; stroke-width: 1.3; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #C0C0C0; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#666" stroke-width="1.6"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#C0605A" stroke-width="1.6"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#6A9F68" stroke-width="1.6"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="310" y="28" class="title">布隆过滤器</text>
|
||||
<rect x="54" y="135" width="32" height="30" fill="#FFFFFF" stroke="#999"/>
|
||||
<text x="70" y="155" class="c b">0</text>
|
||||
<text x="70" y="181" class="c sub">0</text>
|
||||
<rect x="86" y="135" width="32" height="30" fill="#B1DDF0" stroke="#999"/>
|
||||
<text x="102" y="155" class="c b">1</text>
|
||||
<text x="102" y="181" class="c sub">1</text>
|
||||
<rect x="118" y="135" width="32" height="30" fill="#FFFFFF" stroke="#999"/>
|
||||
<text x="134" y="155" class="c b">0</text>
|
||||
<text x="134" y="181" class="c sub">2</text>
|
||||
<rect x="150" y="135" width="32" height="30" fill="#FFFFFF" stroke="#999"/>
|
||||
<text x="166" y="155" class="c b">0</text>
|
||||
<text x="166" y="181" class="c sub">3</text>
|
||||
<rect x="182" y="135" width="32" height="30" fill="#B1DDF0" stroke="#999"/>
|
||||
<text x="198" y="155" class="c b">1</text>
|
||||
<text x="198" y="181" class="c sub">4</text>
|
||||
<rect x="214" y="135" width="32" height="30" fill="#FFFFFF" stroke="#999"/>
|
||||
<text x="230" y="155" class="c b">0</text>
|
||||
<text x="230" y="181" class="c sub">5</text>
|
||||
<rect x="246" y="135" width="32" height="30" fill="#B1DDF0" stroke="#999"/>
|
||||
<text x="262" y="155" class="c b">1</text>
|
||||
<text x="262" y="181" class="c sub">6</text>
|
||||
<rect x="278" y="135" width="32" height="30" fill="#FFFFFF" stroke="#999"/>
|
||||
<text x="294" y="155" class="c b">0</text>
|
||||
<text x="294" y="181" class="c sub">7</text>
|
||||
<rect x="310" y="135" width="32" height="30" fill="#FFFFFF" stroke="#999"/>
|
||||
<text x="326" y="155" class="c b">0</text>
|
||||
<text x="326" y="181" class="c sub">8</text>
|
||||
<rect x="342" y="135" width="32" height="30" fill="#FFFFFF" stroke="#999"/>
|
||||
<text x="358" y="155" class="c b">0</text>
|
||||
<text x="358" y="181" class="c sub">9</text>
|
||||
<rect x="374" y="135" width="32" height="30" fill="#B1DDF0" stroke="#999"/>
|
||||
<text x="390" y="155" class="c b">1</text>
|
||||
<text x="390" y="181" class="c sub">10</text>
|
||||
<rect x="406" y="135" width="32" height="30" fill="#FFFFFF" stroke="#999"/>
|
||||
<text x="422" y="155" class="c b">0</text>
|
||||
<text x="422" y="181" class="c sub">11</text>
|
||||
<rect x="438" y="135" width="32" height="30" fill="#FFFFFF" stroke="#999"/>
|
||||
<text x="454" y="155" class="c b">0</text>
|
||||
<text x="454" y="181" class="c sub">12</text>
|
||||
<rect x="470" y="135" width="32" height="30" fill="#B1DDF0" stroke="#999"/>
|
||||
<text x="486" y="155" class="c b">1</text>
|
||||
<text x="486" y="181" class="c sub">13</text>
|
||||
<rect x="502" y="135" width="32" height="30" fill="#FFFFFF" stroke="#999"/>
|
||||
<text x="518" y="155" class="c b">0</text>
|
||||
<text x="518" y="181" class="c sub">14</text>
|
||||
<rect x="534" y="135" width="32" height="30" fill="#FFFFFF" stroke="#999"/>
|
||||
<text x="550" y="155" class="c b">0</text>
|
||||
<text x="550" y="181" class="c sub">15</text>
|
||||
<rect x="123" y="53" width="80" height="30" rx="6" class="shadow"/>
|
||||
<rect x="120" y="50" width="80" height="30" rx="6" fill="#B0E3E6"/>
|
||||
<text x="160" y="69.5" class="b c">key1</text>
|
||||
<rect x="423" y="53" width="80" height="30" rx="6" class="shadow"/>
|
||||
<rect x="420" y="50" width="80" height="30" rx="6" fill="#B0E3E6"/>
|
||||
<text x="460" y="69.5" class="b c">key2</text>
|
||||
<line x1="160" y1="83" x2="102" y2="132" class="arrow "/>
|
||||
<line x1="160" y1="83" x2="198" y2="132" class="arrow "/>
|
||||
<line x1="160" y1="83" x2="262" y2="132" class="arrow "/>
|
||||
<line x1="460" y1="83" x2="262" y2="132" class="arrow "/>
|
||||
<line x1="460" y1="83" x2="390" y2="132" class="arrow "/>
|
||||
<line x1="460" y1="83" x2="486" y2="132" class="arrow "/>
|
||||
<text x="30" y="70" class="b">插入</text>
|
||||
<rect x="93" y="243" width="80" height="30" rx="6" class="shadow"/>
|
||||
<rect x="90" y="240" width="80" height="30" rx="6" fill="#E6E6E6"/>
|
||||
<text x="130" y="259.5" class="b c">key3</text>
|
||||
<rect x="383" y="243" width="80" height="30" rx="6" class="shadow"/>
|
||||
<rect x="380" y="240" width="80" height="30" rx="6" fill="#E6E6E6"/>
|
||||
<text x="420" y="259.5" class="b c">key4</text>
|
||||
<line x1="130" y1="237" x2="102" y2="168" class="arrow "/>
|
||||
<line x1="130" y1="237" x2="166" y2="168" class="arrow red"/>
|
||||
<line x1="130" y1="237" x2="198" y2="168" class="arrow "/>
|
||||
<line x1="420" y1="237" x2="198" y2="168" class="arrow "/>
|
||||
<line x1="420" y1="237" x2="262" y2="168" class="arrow "/>
|
||||
<line x1="420" y1="237" x2="486" y2="168" class="arrow "/>
|
||||
<text x="30" y="260" class="b">查询</text>
|
||||
<text x="180" y="252" class="note">位 3 为 0</text>
|
||||
<text x="180" y="270" class="note">一定不存在</text>
|
||||
<text x="470" y="252">全为 1:可能存在</text>
|
||||
<text x="470" y="270" class="sub">实际未插入过,属于误判</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 6.1 KiB |
@@ -0,0 +1,76 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="620" height="330" viewBox="0 0 620 330">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #666; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #777; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.sub { font-size: 11px; fill: #888; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #666; stroke-width: 1.3; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #666; stroke-width: 1.3; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #C0C0C0; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#666" stroke-width="1.6"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#C0605A" stroke-width="1.6"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#6A9F68" stroke-width="1.6"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="310" y="28" class="title">消费者组</text>
|
||||
<rect x="235" y="58" width="150" height="210" rx="8" class="frame"/>
|
||||
<text x="245" y="76" class="b">Topic</text>
|
||||
<rect x="258" y="95" width="110" height="36" rx="6" class="shadow"/>
|
||||
<rect x="255" y="92" width="110" height="36" rx="6" fill="#B1DDF0"/>
|
||||
<text x="310" y="114.5" class="b c">分区 0</text>
|
||||
<rect x="258" y="150" width="110" height="36" rx="6" class="shadow"/>
|
||||
<rect x="255" y="147" width="110" height="36" rx="6" fill="#B1DDF0"/>
|
||||
<text x="310" y="169.5" class="b c">分区 1</text>
|
||||
<rect x="258" y="205" width="110" height="36" rx="6" class="shadow"/>
|
||||
<rect x="255" y="202" width="110" height="36" rx="6" fill="#B1DDF0"/>
|
||||
<text x="310" y="224.5" class="b c">分区 2</text>
|
||||
<rect x="20" y="58" width="160" height="210" rx="8" class="frame"/>
|
||||
<text x="30" y="76" class="b">消费者组 A</text>
|
||||
<rect x="43" y="110" width="110" height="36" rx="6" class="shadow"/>
|
||||
<rect x="40" y="107" width="110" height="36" rx="6" fill="#B0E3E6"/>
|
||||
<text x="95" y="129.5" class="b c">A1</text>
|
||||
<rect x="43" y="190" width="110" height="36" rx="6" class="shadow"/>
|
||||
<rect x="40" y="187" width="110" height="36" rx="6" fill="#B0E3E6"/>
|
||||
<text x="95" y="209.5" class="b c">A2</text>
|
||||
<line x1="253" y1="110" x2="155" y2="120" class="arrow "/>
|
||||
<line x1="253" y1="165" x2="155" y2="130" class="arrow "/>
|
||||
<line x1="253" y1="220" x2="155" y2="205" class="arrow "/>
|
||||
<rect x="440" y="50" width="160" height="262" rx="8" class="frame"/>
|
||||
<text x="450" y="68" class="b">消费者组 B</text>
|
||||
<rect x="468" y="80" width="110" height="36" rx="6" class="shadow"/>
|
||||
<rect x="465" y="77" width="110" height="36" rx="6" fill="#B0E3E6"/>
|
||||
<text x="520" y="99.5" class="b c">B1</text>
|
||||
<rect x="468" y="135" width="110" height="36" rx="6" class="shadow"/>
|
||||
<rect x="465" y="132" width="110" height="36" rx="6" fill="#B0E3E6"/>
|
||||
<text x="520" y="154.5" class="b c">B2</text>
|
||||
<rect x="468" y="190" width="110" height="36" rx="6" class="shadow"/>
|
||||
<rect x="465" y="187" width="110" height="36" rx="6" fill="#B0E3E6"/>
|
||||
<text x="520" y="209.5" class="b c">B3</text>
|
||||
<rect x="468" y="245" width="110" height="36" rx="6" class="shadow"/>
|
||||
<rect x="465" y="242" width="110" height="36" rx="6" fill="#E6E6E6"/>
|
||||
<text x="520" y="258" class="b c">B4</text>
|
||||
<text x="520" y="273" class="sub c">空闲</text>
|
||||
<line x1="370" y1="110" x2="460" y2="95" class="arrow "/>
|
||||
<line x1="370" y1="165" x2="460" y2="150" class="arrow "/>
|
||||
<line x1="370" y1="220" x2="460" y2="205" class="arrow "/>
|
||||
<text x="310" y="300" class="c">同一个组内,每个分区只分配给一个消费者</text>
|
||||
<text x="310" y="318" class="c sub">每个组都会收到 Topic 的全部消息</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.3 KiB |
@@ -0,0 +1,48 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="600" height="342" viewBox="0 0 600 342">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #666; font-size: 13px; }
|
||||
.head { font-weight: bold; text-anchor: middle; }
|
||||
.msg { text-anchor: middle; font-size: 12px; }
|
||||
.note { font-size: 12px; fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #777; text-anchor: middle; }
|
||||
.life { stroke: #BBB; stroke-width: 1; stroke-dasharray: 4 4; }
|
||||
.arrow { stroke: #666; stroke-width: 1.3; fill: none; marker-end: url(#a); }
|
||||
.reply { stroke-dasharray: 5 4; }
|
||||
.lost { stroke: #C0605A; marker-end: url(#x); }
|
||||
.shadow { fill: #C0C0C0; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#666" stroke-width="1.6"/>
|
||||
</marker>
|
||||
<marker id="x" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#C0605A" stroke-width="1.6"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
<text x="300" y="28" class="title">CSRF 攻击过程</text>
|
||||
<line x1="90" y1="76" x2="90" y2="322" class="life"/>
|
||||
<line x1="300" y1="76" x2="300" y2="322" class="life"/>
|
||||
<line x1="510" y1="76" x2="510" y2="322" class="life"/>
|
||||
<rect x="46" y="48" width="94" height="30" rx="6" class="shadow"/>
|
||||
<rect x="43" y="45" width="94" height="30" rx="6" fill="#B0E3E6"/>
|
||||
<text x="90" y="64.5" class="head">用户浏览器</text>
|
||||
<rect x="263" y="48" width="80" height="30" rx="6" class="shadow"/>
|
||||
<rect x="260" y="45" width="80" height="30" rx="6" fill="#B1DDF0"/>
|
||||
<text x="300" y="64.5" class="head">银行网站</text>
|
||||
<rect x="473" y="48" width="80" height="30" rx="6" class="shadow"/>
|
||||
<rect x="470" y="45" width="80" height="30" rx="6" fill="#F3C6C2"/>
|
||||
<text x="510" y="64.5" class="head">恶意网站</text>
|
||||
<line x1="94" y1="100" x2="296" y2="100" class="arrow"/>
|
||||
<text x="195" y="94" class="msg">① 登录</text>
|
||||
<line x1="296" y1="140" x2="94" y2="140" class="arrow reply"/>
|
||||
<text x="195" y="134" class="msg">Set-Cookie:会话 ID</text>
|
||||
<line x1="94" y1="180" x2="506" y2="180" class="arrow"/>
|
||||
<text x="380" y="174" class="msg">② 访问恶意网站</text>
|
||||
<line x1="506" y1="220" x2="94" y2="220" class="arrow reply"/>
|
||||
<text x="405" y="214" class="msg">返回含 <img src="转账 URL"> 的页面</text>
|
||||
<line x1="94" y1="260" x2="296" y2="260" class="arrow"/>
|
||||
<text x="196" y="254" class="msg note">③ 自动请求转账 URL,携带 Cookie</text>
|
||||
<text x="310" y="304" class="note" text-anchor="start">Cookie 有效,执行转账</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.8 KiB |
@@ -0,0 +1,87 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="640" height="330" viewBox="0 0 640 330">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #666; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #777; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.sub { font-size: 11px; fill: #888; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #666; stroke-width: 1.3; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #666; stroke-width: 1.3; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #C0C0C0; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#666" stroke-width="1.6"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#C0605A" stroke-width="1.6"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#6A9F68" stroke-width="1.6"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="320" y="28" class="title">select / poll 与 epoll</text>
|
||||
<rect x="20" y="50" width="290" height="265" rx="8" class="frame"/>
|
||||
<text x="30" y="68" class="b">select / poll</text>
|
||||
<rect x="98" y="83" width="140" height="34" rx="6" class="shadow"/>
|
||||
<rect x="95" y="80" width="140" height="34" rx="6" fill="#B0E3E6"/>
|
||||
<text x="165" y="101.5" class="b c">用户进程</text>
|
||||
<line x1="30" y1="150" x2="300" y2="150" class="line dash"/>
|
||||
<text x="300" y="143" class="sub e">用户态</text>
|
||||
<text x="300" y="163" class="sub e">内核态</text>
|
||||
<rect x="330" y="50" width="290" height="265" rx="8" class="frame"/>
|
||||
<text x="340" y="68" class="b">epoll</text>
|
||||
<rect x="408" y="83" width="140" height="34" rx="6" class="shadow"/>
|
||||
<rect x="405" y="80" width="140" height="34" rx="6" fill="#B0E3E6"/>
|
||||
<text x="475" y="101.5" class="b c">用户进程</text>
|
||||
<line x1="340" y1="150" x2="610" y2="150" class="line dash"/>
|
||||
<text x="610" y="143" class="sub e">用户态</text>
|
||||
<text x="610" y="163" class="sub e">内核态</text>
|
||||
<line x1="110" y1="117" x2="110" y2="200" class="arrow "/>
|
||||
<text x="104" y="180" class="e sub">每次调用复制</text>
|
||||
<text x="104" y="194" class="e sub">全部描述符</text>
|
||||
<rect x="73" y="206" width="160" height="40" rx="6" class="shadow"/>
|
||||
<rect x="70" y="203" width="160" height="40" rx="6" fill="#B1DDF0"/>
|
||||
<text x="150" y="221" class="b c">遍历全部描述符</text>
|
||||
<text x="150" y="236" class="sub c">检查是否就绪</text>
|
||||
<line x1="195" y1="200" x2="195" y2="117" class="arrow "/>
|
||||
<text x="200" y="180" class="sub">返回后进程</text>
|
||||
<text x="200" y="194" class="sub">再遍历一次</text>
|
||||
<text x="165" y="290" class="c note">每次调用都是 O(N)</text>
|
||||
<line x1="390" y1="117" x2="390" y2="200" class="arrow "/>
|
||||
<text x="397" y="180" class="sub mono">epoll_ctl()</text>
|
||||
<text x="397" y="194" class="sub">注册一次</text>
|
||||
<line x1="400" y1="215" x2="370" y2="245" class="line"/>
|
||||
<line x1="400" y1="215" x2="430" y2="245" class="line"/>
|
||||
<line x1="370" y1="245" x2="355" y2="275" class="line"/>
|
||||
<line x1="370" y1="245" x2="385" y2="275" class="line"/>
|
||||
<line x1="430" y1="245" x2="415" y2="275" class="line"/>
|
||||
<circle cx="400" cy="215" r="9" fill="#61646B"/>
|
||||
<circle cx="370" cy="245" r="9" fill="#C0605A"/>
|
||||
<circle cx="430" cy="245" r="9" fill="#61646B"/>
|
||||
<circle cx="355" cy="275" r="9" fill="#61646B"/>
|
||||
<circle cx="385" cy="275" r="9" fill="#61646B"/>
|
||||
<circle cx="415" cy="275" r="9" fill="#C0605A"/>
|
||||
<text x="400" y="300" class="c sub">红黑树:已注册描述符</text>
|
||||
<rect x="535" y="210" width="50" height="20" rx="3" fill="#F3D9A4"/>
|
||||
<rect x="535" y="238" width="50" height="20" rx="3" fill="#F3D9A4"/>
|
||||
<line x1="560" y1="230" x2="560" y2="237" class="arrow "/>
|
||||
<rect x="535" y="266" width="50" height="20" rx="3" fill="#F3D9A4"/>
|
||||
<line x1="560" y1="258" x2="560" y2="265" class="arrow "/>
|
||||
<text x="560" y="297" class="c sub">就绪链表</text>
|
||||
<path d="M430,245 C470,245 490,220 532,220" class="arrow dash"/>
|
||||
<text x="478" y="267" class="c sub">就绪时回调</text>
|
||||
<line x1="560" y1="202" x2="560" y2="117" class="arrow "/>
|
||||
<text x="553" y="180" class="e sub mono">epoll_wait()</text>
|
||||
<text x="553" y="194" class="e sub">只取就绪的</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.9 KiB |
@@ -0,0 +1,98 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="620" height="290" viewBox="0 0 620 290">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #666; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #777; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.sub { font-size: 11px; fill: #888; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #666; stroke-width: 1.3; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #666; stroke-width: 1.3; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #C0C0C0; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#666" stroke-width="1.6"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#C0605A" stroke-width="1.6"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#6A9F68" stroke-width="1.6"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="310" y="28" class="title">HashMap 扩容时的桶下标</text>
|
||||
<rect x="150" y="70" width="20" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="170" y="70" width="20" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="190" y="70" width="20" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="210" y="70" width="20" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="230" y="70" width="20" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="250" y="70" width="20" height="24" fill="#B1DDF0" stroke="#999"/>
|
||||
<rect x="270" y="70" width="20" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="290" y="70" width="20" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="310" y="70" width="20" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="330" y="70" width="20" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="350" y="70" width="20" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="370" y="70" width="20" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="390" y="70" width="20" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="410" y="70" width="20" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="430" y="70" width="20" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="450" y="70" width="20" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<text x="140" y="87" class="e">capacity = 16</text>
|
||||
<text x="160" y="64" class="c sub">0</text>
|
||||
<text x="260" y="64" class="c sub">5</text>
|
||||
<text x="460" y="64" class="c sub">15</text>
|
||||
<rect x="140" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="154" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="168" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="182" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="196" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="210" y="220" width="14" height="24" fill="#B1DDF0" stroke="#999"/>
|
||||
<rect x="224" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="238" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="252" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="266" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="280" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="294" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="308" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="322" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="336" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="350" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="364" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="378" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="392" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="406" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="420" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="434" y="220" width="14" height="24" fill="#B1DDF0" stroke="#999"/>
|
||||
<rect x="448" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="462" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="476" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="490" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="504" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="518" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="532" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="546" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="560" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<rect x="574" y="220" width="14" height="24" fill="#FFFFFF" stroke="#999"/>
|
||||
<text x="130" y="237" class="e">capacity = 32</text>
|
||||
<text x="147" y="260" class="c sub">0</text>
|
||||
<text x="217" y="260" class="c sub">5</text>
|
||||
<text x="441" y="260" class="c sub">21</text>
|
||||
<text x="581" y="260" class="c sub">31</text>
|
||||
<line x1="257" y1="97" x2="217" y2="217" class="arrow "/>
|
||||
<line x1="263" y1="97" x2="441" y2="217" class="arrow "/>
|
||||
<text x="205" y="150" class="e mono">hash 低 5 位 0 0101</text>
|
||||
<text x="205" y="168" class="e ok">第 5 位为 0:仍在 5</text>
|
||||
<text x="371" y="150" class="mono">hash 低 5 位 1 0101</text>
|
||||
<text x="371" y="168" class="note">第 5 位为 1:移到 5 + 16 = 21</text>
|
||||
<text x="310" y="280" class="c">桶 5 中的键值对扩容后只会落在 5 或 21</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 6.3 KiB |
@@ -0,0 +1,73 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="620" height="270" viewBox="0 0 620 270">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #666; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #777; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.sub { font-size: 11px; fill: #888; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #666; stroke-width: 1.3; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #666; stroke-width: 1.3; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #C0C0C0; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#666" stroke-width="1.6"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#C0605A" stroke-width="1.6"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#6A9F68" stroke-width="1.6"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="310" y="28" class="title">LRU:HashMap + 双向链表</text>
|
||||
<rect x="33" y="160" width="80" height="36" rx="6" class="shadow"/>
|
||||
<rect x="30" y="157" width="80" height="36" rx="6" fill="#E6E6E6"/>
|
||||
<text x="70" y="179.5" class="c b mono">head</text>
|
||||
<rect x="153" y="160" width="80" height="36" rx="6" class="shadow"/>
|
||||
<rect x="150" y="157" width="80" height="36" rx="6" fill="#B1DDF0"/>
|
||||
<text x="190" y="179.5" class="c b mono">k2</text>
|
||||
<rect x="273" y="160" width="80" height="36" rx="6" class="shadow"/>
|
||||
<rect x="270" y="157" width="80" height="36" rx="6" fill="#B1DDF0"/>
|
||||
<text x="310" y="179.5" class="c b mono">k3</text>
|
||||
<rect x="393" y="160" width="80" height="36" rx="6" class="shadow"/>
|
||||
<rect x="390" y="157" width="80" height="36" rx="6" fill="#B1DDF0"/>
|
||||
<text x="430" y="179.5" class="c b mono">k1</text>
|
||||
<rect x="513" y="160" width="80" height="36" rx="6" class="shadow"/>
|
||||
<rect x="510" y="157" width="80" height="36" rx="6" fill="#E6E6E6"/>
|
||||
<text x="550" y="179.5" class="c b mono">tail</text>
|
||||
<line x1="112" y1="169" x2="148" y2="169" class="arrow "/>
|
||||
<line x1="148" y1="181" x2="112" y2="181" class="arrow "/>
|
||||
<line x1="232" y1="169" x2="268" y2="169" class="arrow "/>
|
||||
<line x1="268" y1="181" x2="232" y2="181" class="arrow "/>
|
||||
<line x1="352" y1="169" x2="388" y2="169" class="arrow "/>
|
||||
<line x1="388" y1="181" x2="352" y2="181" class="arrow "/>
|
||||
<line x1="472" y1="169" x2="508" y2="169" class="arrow "/>
|
||||
<line x1="508" y1="181" x2="472" y2="181" class="arrow "/>
|
||||
<rect x="132" y="52" width="356" height="66" rx="8" class="frame"/>
|
||||
<text x="142" y="70" class="b">HashMap</text>
|
||||
<rect x="160" y="72" width="60" height="30" rx="6" fill="#B0E3E6"/>
|
||||
<text x="190" y="91.5" class="c mono">k2</text>
|
||||
<line x1="190" y1="104" x2="190" y2="154" class="arrow dash"/>
|
||||
<rect x="280" y="72" width="60" height="30" rx="6" fill="#B0E3E6"/>
|
||||
<text x="310" y="91.5" class="c mono">k3</text>
|
||||
<line x1="310" y1="104" x2="310" y2="154" class="arrow dash"/>
|
||||
<rect x="400" y="72" width="60" height="30" rx="6" fill="#B0E3E6"/>
|
||||
<text x="430" y="91.5" class="c mono">k1</text>
|
||||
<line x1="430" y1="104" x2="430" y2="154" class="arrow dash"/>
|
||||
<text x="70" y="217" class="c sub">哨兵</text>
|
||||
<text x="550" y="217" class="c sub">哨兵</text>
|
||||
<text x="190" y="217" class="c ok">最近访问</text>
|
||||
<text x="430" y="217" class="c note">最久未访问,最先淘汰</text>
|
||||
<text x="310" y="255" class="c">访问或插入时把节点移到 head 之后,超出容量时删除 tail 之前的节点</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.1 KiB |
@@ -0,0 +1,59 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="620" height="230" viewBox="0 0 620 230">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #666; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #777; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.sub { font-size: 11px; fill: #888; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #666; stroke-width: 1.3; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #666; stroke-width: 1.3; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #C0C0C0; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#666" stroke-width="1.6"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#C0605A" stroke-width="1.6"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#6A9F68" stroke-width="1.6"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="310" y="28" class="title">Next-Key Locks</text>
|
||||
<rect x="40" y="106" width="110" height="28" fill="#D8ECF5"/>
|
||||
<text x="95" y="160" class="c mono">(-∞, 10]</text>
|
||||
<rect x="150" y="106" width="105" height="28" fill="#C9E6EC"/>
|
||||
<text x="202.5" y="160" class="c mono">(10, 11]</text>
|
||||
<rect x="255" y="106" width="105" height="28" fill="#D8ECF5"/>
|
||||
<text x="307.5" y="160" class="c mono">(11, 13]</text>
|
||||
<rect x="360" y="106" width="105" height="28" fill="#C9E6EC"/>
|
||||
<text x="412.5" y="160" class="c mono">(13, 20]</text>
|
||||
<rect x="465" y="106" width="115" height="28" fill="#D8ECF5"/>
|
||||
<text x="522.5" y="160" class="c mono">(20, +∞)</text>
|
||||
<line x1="30" y1="120" x2="590" y2="120" class="line"/>
|
||||
<circle cx="150" cy="120" r="6" fill="#61646B"/>
|
||||
<text x="150" y="98" class="c b">10</text>
|
||||
<circle cx="255" cy="120" r="6" fill="#61646B"/>
|
||||
<text x="255" y="98" class="c b">11</text>
|
||||
<circle cx="360" cy="120" r="6" fill="#61646B"/>
|
||||
<text x="360" y="98" class="c b">13</text>
|
||||
<circle cx="465" cy="120" r="6" fill="#61646B"/>
|
||||
<text x="465" y="98" class="c b">20</text>
|
||||
<text x="40" y="98" class="c sub">-∞</text>
|
||||
<text x="580" y="98" class="c sub">+∞</text>
|
||||
<text x="202" y="196" class="c note">Gap Lock (10, 11)</text>
|
||||
<text x="255" y="214" class="c">+ Record Lock 11 = Next-Key Lock (10, 11]</text>
|
||||
<path d="M202,184 L202,166" class="arrow red"/>
|
||||
<text x="310" y="60" class="c sub">索引值 10、11、13、20,每个区间前开后闭</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.1 KiB |
@@ -0,0 +1,71 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="640" height="300" viewBox="0 0 640 300">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #666; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #777; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.sub { font-size: 11px; fill: #888; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #666; stroke-width: 1.3; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #666; stroke-width: 1.3; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #C0C0C0; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#666" stroke-width="1.6"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#C0605A" stroke-width="1.6"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#6A9F68" stroke-width="1.6"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="320" y="28" class="title">漏桶与令牌桶</text>
|
||||
<rect x="20" y="45" width="290" height="240" rx="8" class="frame"/>
|
||||
<text x="30" y="63" class="b">漏桶</text>
|
||||
<line x1="95" y1="80" x2="95" y2="108" class="arrow "/>
|
||||
<line x1="125" y1="80" x2="125" y2="108" class="arrow "/>
|
||||
<line x1="155" y1="80" x2="155" y2="108" class="arrow "/>
|
||||
<line x1="185" y1="80" x2="185" y2="108" class="arrow "/>
|
||||
<text x="140" y="75" class="c sub">请求</text>
|
||||
<path d="M90,110 L102,210 L188,210 L200,110" class="line"/>
|
||||
<rect x="104" y="185" width="82" height="18" rx="3" fill="#B1DDF0"/>
|
||||
<rect x="104" y="163" width="82" height="18" rx="3" fill="#B1DDF0"/>
|
||||
<rect x="104" y="141" width="82" height="18" rx="3" fill="#B1DDF0"/>
|
||||
<rect x="104" y="119" width="82" height="18" rx="3" fill="#B1DDF0"/>
|
||||
<text x="82" y="170" class="e sub">排队</text>
|
||||
<line x1="205" y1="116" x2="250" y2="116" class="arrow red"/>
|
||||
<text x="255" y="120" class="note">桶满丢弃</text>
|
||||
<line x1="145" y1="212" x2="145" y2="250" class="arrow "/>
|
||||
<text x="155" y="240" class="ok">固定速率处理</text>
|
||||
<rect x="330" y="45" width="290" height="240" rx="8" class="frame"/>
|
||||
<text x="340" y="63" class="b">令牌桶</text>
|
||||
<line x1="430" y1="80" x2="430" y2="108" class="arrow "/>
|
||||
<text x="440" y="92" class="sub">固定速率放入令牌</text>
|
||||
<path d="M380,110 L392,210 L478,210 L490,110" class="line"/>
|
||||
<circle cx="410" cy="195" r="9" fill="#F3D9A4" stroke="#D9B44A"/>
|
||||
<circle cx="435" cy="195" r="9" fill="#F3D9A4" stroke="#D9B44A"/>
|
||||
<circle cx="460" cy="195" r="9" fill="#F3D9A4" stroke="#D9B44A"/>
|
||||
<circle cx="422" cy="175" r="9" fill="#F3D9A4" stroke="#D9B44A"/>
|
||||
<circle cx="448" cy="175" r="9" fill="#F3D9A4" stroke="#D9B44A"/>
|
||||
<text x="435" y="140" class="c sub">桶满后不再放入</text>
|
||||
<rect x="513" y="143" width="80" height="30" rx="6" class="shadow"/>
|
||||
<rect x="510" y="140" width="80" height="30" rx="6" fill="#B0E3E6"/>
|
||||
<text x="550" y="159.5" class="b c">请求</text>
|
||||
<line x1="507" y1="165" x2="470" y2="190" class="arrow "/>
|
||||
<text x="500" y="196" class="sub">取走令牌</text>
|
||||
<line x1="550" y1="173" x2="550" y2="245" class="arrow green"/>
|
||||
<text x="550" y="262" class="c ok">有令牌:处理</text>
|
||||
<text x="550" y="278" class="c note">没有令牌:拒绝</text>
|
||||
<text x="435" y="238" class="c sub">积累的令牌允许突发流量</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
@@ -0,0 +1,51 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="600" height="408" viewBox="0 0 600 408">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #666; font-size: 13px; }
|
||||
.head { font-weight: bold; text-anchor: middle; }
|
||||
.msg { text-anchor: middle; font-size: 12px; }
|
||||
.note { font-size: 12px; fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #777; text-anchor: middle; }
|
||||
.life { stroke: #BBB; stroke-width: 1; stroke-dasharray: 4 4; }
|
||||
.arrow { stroke: #666; stroke-width: 1.3; fill: none; marker-end: url(#a); }
|
||||
.reply { stroke-dasharray: 5 4; }
|
||||
.lost { stroke: #C0605A; marker-end: url(#x); }
|
||||
.shadow { fill: #C0C0C0; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#666" stroke-width="1.6"/>
|
||||
</marker>
|
||||
<marker id="x" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#C0605A" stroke-width="1.6"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
<text x="300" y="28" class="title">RocketMQ 事务消息</text>
|
||||
<line x1="100" y1="76" x2="100" y2="388" class="life"/>
|
||||
<line x1="300" y1="76" x2="300" y2="388" class="life"/>
|
||||
<line x1="500" y1="76" x2="500" y2="388" class="life"/>
|
||||
<rect x="67" y="48" width="72" height="30" rx="6" class="shadow"/>
|
||||
<rect x="64" y="45" width="72" height="30" rx="6" fill="#B0E3E6"/>
|
||||
<text x="100" y="64.5" class="head">生产者</text>
|
||||
<rect x="267" y="48" width="72" height="30" rx="6" class="shadow"/>
|
||||
<rect x="264" y="45" width="72" height="30" rx="6" fill="#B1DDF0"/>
|
||||
<text x="300" y="64.5" class="head">Broker</text>
|
||||
<rect x="467" y="48" width="72" height="30" rx="6" class="shadow"/>
|
||||
<rect x="464" y="45" width="72" height="30" rx="6" fill="#B0E3E6"/>
|
||||
<text x="500" y="64.5" class="head">消费者</text>
|
||||
<line x1="104" y1="100" x2="296" y2="100" class="arrow"/>
|
||||
<text x="200" y="94" class="msg">① 发送半消息</text>
|
||||
<line x1="296" y1="138" x2="104" y2="138" class="arrow reply"/>
|
||||
<text x="200" y="132" class="msg">② 写入成功,消费者不可见</text>
|
||||
<text x="110" y="180" class="note" text-anchor="start">③ 执行本地事务</text>
|
||||
<line x1="104" y1="214" x2="296" y2="214" class="arrow"/>
|
||||
<text x="200" y="208" class="msg">④ 根据事务结果提交或回滚</text>
|
||||
<text x="300" y="256" class="note" text-anchor="middle">长时间没有收到 ④ 时:</text>
|
||||
<line x1="296" y1="290" x2="104" y2="290" class="arrow reply"/>
|
||||
<text x="200" y="284" class="msg">⑤ 回查本地事务状态</text>
|
||||
<line x1="104" y1="328" x2="296" y2="328" class="arrow"/>
|
||||
<text x="200" y="322" class="msg">⑥ 提交或回滚</text>
|
||||
<line x1="304" y1="366" x2="496" y2="366" class="arrow"/>
|
||||
<text x="400" y="360" class="msg">⑦ 提交后投递消息</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.0 KiB |
@@ -0,0 +1,60 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="600" height="220" viewBox="0 0 600 220">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #666; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #777; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.sub { font-size: 11px; fill: #888; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #666; stroke-width: 1.3; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #666; stroke-width: 1.3; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #C0C0C0; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#666" stroke-width="1.6"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#C0605A" stroke-width="1.6"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1 L9,5 L1,9" fill="none" stroke="#6A9F68" stroke-width="1.6"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="300" y="28" class="title">Saga</text>
|
||||
<rect x="73" y="63" width="110" height="40" rx="6" class="shadow"/>
|
||||
<rect x="70" y="60" width="110" height="40" rx="6" fill="#B1DDF0"/>
|
||||
<text x="125" y="78" class="b c">T1</text>
|
||||
<text x="125" y="93" class="sub c">本地事务提交</text>
|
||||
<rect x="233" y="63" width="110" height="40" rx="6" class="shadow"/>
|
||||
<rect x="230" y="60" width="110" height="40" rx="6" fill="#B1DDF0"/>
|
||||
<text x="285" y="78" class="b c">T2</text>
|
||||
<text x="285" y="93" class="sub c">本地事务提交</text>
|
||||
<rect x="393" y="63" width="110" height="40" rx="6" class="shadow"/>
|
||||
<rect x="390" y="60" width="110" height="40" rx="6" fill="#F3C6C2"/>
|
||||
<text x="445" y="78" class="b c">T3</text>
|
||||
<text x="445" y="93" class="sub c">失败</text>
|
||||
<line x1="183" y1="80" x2="227" y2="80" class="arrow "/>
|
||||
<line x1="343" y1="80" x2="387" y2="80" class="arrow "/>
|
||||
<rect x="73" y="153" width="110" height="40" rx="6" class="shadow"/>
|
||||
<rect x="70" y="150" width="110" height="40" rx="6" fill="#B0E3E6"/>
|
||||
<text x="125" y="168" class="b c">C1</text>
|
||||
<text x="125" y="183" class="sub c">补偿 T1</text>
|
||||
<rect x="233" y="153" width="110" height="40" rx="6" class="shadow"/>
|
||||
<rect x="230" y="150" width="110" height="40" rx="6" fill="#B0E3E6"/>
|
||||
<text x="285" y="168" class="b c">C2</text>
|
||||
<text x="285" y="183" class="sub c">补偿 T2</text>
|
||||
<path d="M445,103 L445,125 Q445,170 400,170 L345,170" class="arrow red"/>
|
||||
<line x1="227" y1="170" x2="183" y2="170" class="arrow red"/>
|
||||
<text x="520" y="84" class="sub">正向依次执行</text>
|
||||
<text x="470" y="150" class="note">失败后逆序补偿</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.2 KiB |