当前位置:
文档之家› 腾讯TDSQL分布式事务处理技术概述
腾讯TDSQL分布式事务处理技术概述
T2->T3(session order) 没有判断
无环
按事务+分布式一致性原理推理的执行逻辑: -T1 -> T3 按real-time排定逻辑关系 R1(control)[deposit_no=1] W1(receipt)[deposit_no=1] -> R3(receipt)
T1 -> T2 R1(control) -> R2(control) W2(control)
select * from receipt;
receipt_no | deposit_no | payee | amount
------------+------------+--------+---------
1|
1 | Crosby | $100.00
2|
1 | Stills | $200.00
commit;
ERROR: could not serialize access
due to read/write dependencies among transactions
DETAIL: Cancelled on identification as a pivot, during commit attempt. HINT: The transaction might succeed if retried.
T2->T3(session order) 应该判断
理论分析时的并发情况:
T1
T2
T3
R1-x0
W1-y1
R2-x0
W2-x1
C2
R3-y0
C1 ?
事实并发情况:
T1
T2 /T3
R1-x0
W1-y1
R2-x0
W2-x1
C2
R3-y0 C1 ?
@分布式一致性+事务一致性的问题— PostgreSQL 中一个神奇的例子
P1
T1
begin; -- T1 insert into receipt (deposit_no, payee, amount) values ( (select deposit_no from control), 'Young', '100' );
(3 rows)
https:///wiki/SSI#Deposit_Report
@分布式一致性+事务一致性的问题— PostgreSQL 中一个神奇的例子
可串行化:T3-T1-T2 依赖图:无环 SSI: 无环 Pg SSI:无环,但有“ R W T1 RW”
T2->T3(session order) 没有判断
T3 R W T1 R W T2
发生了Stale read,在事务型DB中,是否合理?
可串行化:T3-T1-T2 <------> 因果序:T2-T3 结论: 单机系统的事务排序,需要考虑因果序( 可串行化的缺陷) DTA:T3的lower >= 符合读已提交的数据的提交时间戳 多级一致性:T3-T1-T2-T3,故有环
腾讯TDSQL分布式事务处理 技术概述
多级一致性技术(强一致性)
“强一致”的 分布式事务型数据库
@分布式一致性+事务一致性的问题—挑战:缺少一致性带来的问题
无事务保障:脏写数据异常
分布式事务型数据库, 两种一致性缺一不可
无一致性 保障:违 反因果序
@分布式一致性+事务一致性的问题— PostgreSQL 中一个神奇的例子
按事务原理推理的执行逻辑: -T1 -> T3 按real-time排定逻辑关系 R1(control)[deposit_no=1] W1(receipt)[deposit_no=1] -> R3(receipt)
T1 -> T2 R1(control) -> R2(control) W2(control)
数据准备 create table control ( deposit_no int not null ); insert into control values (1);
create table receipt ( receipt_no serial primary key, deposit_no int not null, payee text not null, amount money not null ); insert into receipt (deposit_no, payee, amount) values ((select deposit_no from control), 'Crosby', '100’); insert into receipt (deposit_no, payee, amount) values ((select deposit_no from control), 'Stills', '200’); insert into receipt (deposit_no, payee, amount) values ((select deposit_no from control), 'Nash', '300’);
P2 T3
begin; -- T3
select * from receipt where deposit_no = 1;
receipt_no | deposit_no | payee | amount
+
+
+
1|
1 | Crosby | $100.00
2|
1 | Stills | $20.00
3|
1 | Nash | $300.00
4|
1 | Young | $100.00
(4 rows)
T2
begin; -- T2 select deposit_no from control; deposit_no ------------
1
update control set deposit_no = 2; commit;
Pg事实执行逻辑: -T3 -> T1 因为T1没有提交,T3根据MVCC读旧版本 R1(control)[deposit_no=1] R3(receipt) -> W1(receipt)[deposit_no=1]
T1 -> T2 R1(control) -> R2(control) W2(control)