版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、多级一致性技术(强一致性)腾讯TDSQL分布式事务处理技术概述“强一致”的 分布式事务型数据库分布式一致性+事务一致性的问题挑战:缺少一致性带来的问题无事务保障:脏写数据异常无一致性 保障:违 反因果序分布式事务型数据库, 两种一致性缺一不可分布式一致性+事务一致性的问题 PostgreSQL 中一个神奇的例子数据准备create table control ( deposit_no int not null ); insert into control values (1);create table receipt ( receipt_no serial primary key, depos
2、it_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_n
3、o, payee, amount) values (select deposit_no from control), Nash, 300);理论分析时的并发情况:T2T3T1 R1-x0W1-y1R2-x0 W2-x1 C2R3-y0C1 ?事实并发情况: T1T2 /T3 R1-x0W1-y1R2-x0 W2-x1 C2R3-y0C1 ?P1P2T1T2T3begin; - T1 insert into receipt (deposit_no, payee, amount) values ( (select deposit_no from control), Young, 100 );sel
4、ect * from receipt;receipt_no | deposit_no | payee | amount -+-+-+-1 | 1 | Crosby | $100.002 | 1 | Stills | $200.003 | 1 | Nash | $300.004 | 1 | Young | $100.00(4 rows)begin; - T2select deposit_no from control; deposit_no-1update control set deposit_no = 2; commit;begin; - T3 select * from receipt w
5、here deposit_no = 1; receipt_no | deposit_no | payee | amount + 1 | 1 | Crosby | $100.002 | 1 | Stills | $200.003 | 1 | Nash | $300.00(3 rows)commit;ERROR: could not serialize accessdue to read/write dependencies among transactionsDETAIL: Cancelled on identification as a pivot, during commit attempt
6、. HINT: The transaction might succeed if retried./wiki/SSI#Deposit_Report分布式一致性+事务一致性的问题 PostgreSQL 中一个神奇的例子可串行化:T3-T1-T2 依赖图:无环 SSI:无环Pg SSI:无环,但有“RW T1 RW”按事务原理推理的执行逻辑:-T1 - T3 按real-time排定逻辑关系R1(control)deposit_no=1W1(receipt)deposit_no=1 - R3(receipt)T1 - T2R1(control) - R2(control) W2(control)T
7、2-T3(session order) 没有判断无环按事务+分布式一致性原理推理的执行逻辑:Pg事实执行逻辑:- T3 - T1 因为T1没有提交,T3根据MVCC读旧版本R1(control)deposit_no=1R3(receipt) - W1(receipt)deposit_no=1T1 - T2R1(control) - R2(control) W2(control)T2-T3(session order) 没有判断T3 RW T1 RW T2发生了Stale read,在事务型DB中,是否合理?- T1 - T3 按real-time排定逻辑关系R1(control)deposit
8、_no=1W1(receipt)deposit_no=1 - R3(receipt)T1 - T2R1(control) - R2(control) W2(control)T2-T3(session order) 应该判断有环/wiki/SSI#Deposit_Report单机系统的事务排序,需要考虑因果序(可串行化的缺陷DTA:T3的lower = 符合读已提交的数据的提交时间戳多级一致性:T3-T1-T2-T3,故有环可串行化:T3-T1-T2 因果序:T2-T3结论:)事务:可串行化,需要考虑因果一致性分布式一致性+事务一致性的问题 PostgreSQL 中一个神奇的例子分布式一致性+事
9、务一致性的问题业界观点:(异步)复制数据库/2019/08/an-explanation-of-difference-between.htmlasynchronously replicateddatabase systems, wherewrites are allowed to occur at either replica, it is possible for conflicting writes to occur across the replicas.Stale reads do not violate serializability. The system is simply ti
10、me travelling the read transaction to a point in time in the equivalent serial order of transactions before the new writes to this data itemoccur. Therefore, asynchronously replicated databasesystems can allow stale reads without giving up its serializability (or even one-copy serializability) guara
11、ntee.Immortal writeIn multi-masterT1 T2 T3 T4t0t1 W-Rep1(t1)t2W-Rep1(t2)t3 W-Rep3(t1)t4R-Rep1(t1)t2W-Rep1(t2)t3W-Rep2(t3) (T1-T2)t4R-Rep1(t0) R-Rep2(t3) T2T3 in the same RepCausal reverseT1 T2 T3t0复制型架构中的问题T1 T2t0 t2 t3W-Rep1(t2)R-Rep2(t1)分布式一致性+事务一致性的问题分布式一致性异常总结总结:并发事务之间,属于事务/数据的一致性问题非并发事务之间,存在如下问
12、题(借用了Daniel的词,但含义可能不同)原因/异常示例号场景/现象特点causal lost(绑匪问题)S1P1W1-x-t1P2R2-x-t0不同session之间不存在显式的因果关系因果关系是隐式无法知道的causal reverse(Stale read(不能读到 最新的数据, 读到一个旧 数据)S2S3不同session之间存在显式的因果关系P1W1-x-t1P2R2-x-t1R3-x-t0 (时间关系不确定导致因果反转)或:P1W1-x-t1W1-y-t3P2R3-x-t0(读已提交导致因果反转)因果关系是显式可知 道的S4P1W1-x-t1R1-x-t0相同session之间存
13、在显式的因果关系未来读 读漂移S5P1W1-x1-t1C1P2R2-x1-t0C2 (读后于自己在real-time上发生的数据,无因果关系)时钟漂移到未来,无 因果关系分布式一致性的问题挑战:问题复杂度增加太多的一 致性,如 何与事务 一致性融 合?分布式一致性+事务一致性的问题业界观点Making Consistency More Consistent: A Unified Model for Coherence, Consistency and IsolationBailis P, Davidson A, Fekete A, et al. Highly available transac
14、tions: Virtues and limitations. In Proc. of VLDB. 2013. 181-192.两个体系:分布式一致性事务一致性一个世界:分布式事务型数据库产品名称可串行化多级一致Oxxxxxxxx2.2版本支持因果一致性CorckroachDB支持顺序一致性、因果一致性TxXx不支持因果一致性Spanner支持(性能差)严格可串行化TDSQL支持严格可串行化(正确性)顺序可串行化(性能)问题与背景挑战:业界研究可改进不?分布式一致性+事务一致性的问题业界典型方案Spanner,严格可串行化,存在性能瓶颈原子钟+TrueTime延迟提交(Google Spann
15、er)节点一节点二事务2:查 询B的余额 为120事务1:A给B转账 A=A-20 B=B+20分布式 全局时钟初始时:A=B=100延迟提交时间(TrueTime)节点时钟差异的上限(原子钟)问题:单分片写事务最大发生数:1s/2 = 125个事务/每秒是延迟提交平均值,约为4ms从time master 同步时的网络延迟, 导致的误差 1mslocal clock 的漂移, 误差是时间的锯齿函数,需校准每个可提交的事务,在 时间轴上,是一个点分布式一致性+事务一致性 = 线性一致+可串行化分布式一致性+事务一致性的问题业界观点1.One-copy serializabilityguaran
16、tees sequential consistencywhere no thread of execution can process more than one transaction.2.Strong session serializabilityguarantees sequentialconsistency where each session corresponds to a separatethread of execution.3.Strong write serializabilitycorresponds to a linearizabilityguarantee for w
17、rite transactions, but only sequentialconsistency for read-only transactions.4.Strong partition serializabilityguarantees linearizableconsistency within a partition, but only sequentialconsistency across partitions.5. And strict serializability guarantees linearizable consistency at all times for al
18、l reads and writes (across non-concurrent transactions).the same process./2019/08/an-explanation-of-difference-between.htmlViotti P, Vukoli M. Consistency in Non-Transactional Distributed Storage Systems. ACM Comput. Surv., 2016, 49(1): 19:1-19:34.分布式一致性+事务一致性强一致性/弱一致性In a hybrid consistent system,
19、strong operations are guaranteed to be seen in some sequential order by all processes (as in sequential consistency), while weak operations are designed to be fast, and they eventually become visible by all processes (much like in eventual consistency). Weak operations are only guaranteed to be orde
20、red according to their interleaving with strong operations: if two operations belong to the same session and one of them is strong, then their relative order of invocation is respected and visible by all processes.Similarly to hybrid consistency (see Section 3.8), strong operations are ordered accor
21、ding to processor or sequential consistency, whereas the ordering of weak operations is just restricted by the relative ordering with respect to the strong operations invoked by学术界的方案各种一致性的差异:线性一致性,定义线性一致性:任何2个写操作,串行执行;读、写可并行;写操作的输出值总是全序Viotti P, Vukoli M. Consistency in Non-Transactional Distribute
22、d Storage Systems. ACM Comput. Surv., 2016, 49(1): 19:1-19:34Regular线性一致性:任何2个写操作,串行执行;读、写可并行;但获取到的值可能是最近并发写操作 影响到的的一个值Safe线性一致性:任何2个写操作,串行执行;读、写可并行;但获取到的值可能是副本中的任何一个 值(某个副本可能没有收到最近的写操作的影响而改变值)The difference between the three resides in the allowed set of return values for a read operation concurren
23、t with a writeFig. An execution exhibiting read-write concurrency (real-time flows from left to right). The register is initialized to 0. Atomic (linearizable) semantics allow x to be 0 or 1. Regular semanticsallow x to be 0, 1, or 2. With safe semantics x may be any value理论上:线性一致可以细分为多种级别学术界的方案采用的技
24、术:顺序一致性顺序一致性:对session内的写操作排序;不同session间的写操作,不用全局有序;任何读, 都按照session排定的序读取(读操作读取的结果对于一个session写出的结果是稳定的)In sequential consistency, all writes - no matter which thread made the write, and no matter which data item was written to - are globally ordered. Every single thread of execution must see the writ
25、es occurring in this order.Pipeline RAM (PRAM or FIFO) consistency Lipton and Sandberg 1988 prescribes thatall processes see write operations issued by a given process in the same order as theywere invoked by that processIn a storage system implementing sequential consistency, all operations are serialized in the same order on all replicas
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 专业厨房设备购销协议2024版B版
- 2024版河南省事业编制人员劳动协议样式版B版
- 二零二五年度大巴车租赁与城市庆典活动策划合同3篇
- 二零二五年度酒吧股份投资及风险控制合同3篇
- 二零二五年度科技园区场地租赁详细协议2篇
- 2024版短期劳务合同范例
- 潍坊护理职业学院《材料分析测试与表征》2023-2024学年第一学期期末试卷
- 太原学院《桥梁工程(一)》2023-2024学年第一学期期末试卷
- 2024年食堂管理员与厨师合同3篇
- 二零二五年建筑工程施工企业工程结算与审计合同2篇
- 智慧农业总体实施方案(2篇)
- 天然甜味剂的开发与应用
- 2024年大学试题(宗教学)-佛教文化笔试参考题库含答案
- 农村生活污水处理站运营维护方案
- 部编版小学语文四年级下册二单元教材分析解读主讲课件
- 2023年译林版英语五年级下册Units-1-2单元测试卷-含答案
- 人教版三年级上册脱式计算200题及答案
- 视觉传达设计史平面设计的起源与发展课件
- 施工管理中的文档管理方法与要求
- 医技沟通与合作课件
- 混凝土企业销售计划书
评论
0/150
提交评论