一致性的3种协议,并发,事务

2023-11-03

Two Phase Commit

MVCC

Paxos


TPC对应于传统数据库上的local cluster的一致性,分布式事务,每个节点上的local事务可以是不同的亦可以是相同的(replica)


MVCC的思想是抓住Transaction的本质:server state从一个一致性state迁移到另一个一致性state,也就是Transaction是工作在一个snapshot上。MVCC模拟时间流逝和历史,对data item的更新就是增加一个新版本。这样,一个事务对应的server state的snapshot就是这个事务对应的时刻,每个data item的相应版本组合而成的视图。


对于长读事务,并发的的写事务是完全没有影响的,只要那个读事务知道每个data item的对应于它这个事务的版本。

对于两个并发的写事务,如果把server state看作一个整体,理论上肯定就是冲突。但是要具体看

1)首先如果更新的是同一个数据,必然是冲突

2)如果更新的是不同的数据,要看作出更新依赖的数据,也就是读的数据,如果T1 没有改变T2读的数据,那么T2在T1之前,之中,之后执行效果是一样的。当然还要看T2对T1的影响。总之,就是看两个写事务是否存在一个sequential equivalence(可能是T1必须在T2前面,可能是T2必须在T1前面,或者都行)

注意两个特点

1)并发事务不存在一个语义上的先后顺序,也就是无所谓的,关键是每个事务从一个consistent state到另一个consistent state就行

2)MVCC依赖一个全局的事务Id 生成器,impose一个事务顺序。

更正:这里可能能把sequential equivalence和 MVCC混了,MVCC应该是impose一个 Transaction的顺序的。


Paxos对应的是一个不依赖一个中心的coordinator role的 peer-to-peer 的cluster的一致性协议。TPC和MVCC都依赖一个coordinator


[MUSIC] Now, how did databases solve this problem,
or why do they take so long? Well, there's a protocol called
two-phase commit that's fairly standard in these situations for
synchronous processing. And so the motivation for why you want
to do Two-Phase Commit goes like this. If you wanna have a bunch of replicas or
other kinds of subordinates, anybody that wants to see the change. You make your status update and
your friends need to see it, the server is holding those different
friends need to be told of the change. And so if you just go ahead and tell them,
say look, I made this change go ahead and update your internal state
to reflect Sue's new status. Then you can have some of them report
back success, but one of them could fail. But now you're in trouble, right? Because this one has the old value
because it failed for some reason. Either you didn't hear back from the
server at all, or it said look something's wrong with my disk, I can't do it so
it responds with a failure, regardless. And these two have already successfully
applied the, I'll put a check mark, have already successfully
applied the transaction. And so now you're in an inconsistent
state, subordinate3 has the old value, and these guys have the new values. Okay? So how you solve this
problem is Two-Phase Commit. So the first phase here is the coordinator
sends a Prepare to Commit message, and the subordinates make sure they take
action to make sure that they can commit that transaction when asked,
no matter what. And so
typically this means writing to a log the information related
to the transaction. So that even if the power goes out, when they wake back up they
can pull it from the log. Okay. And if subordinates reply with
a yes I'm ready to commit and then in phase two if all the subordinates
say they're ready then you go ahead and send the commit message. And if anyone failed, if rather instead anyone failed then
you send back an abort message. And the individuals can clean up. Okay, so this is fine and
here's a schematic of it. In step one they say prepare,
these guys all write ahead to the log and say I'm about to write this, or
I'm going to commit this transaction. They respond with yes, I'm ready to do so. The coordinator comes back with commit and
then finally all the work is done and I'm not gonna show the schematic for
what happens in a failure. That essentially the coordinator
needs to watch out for it and send back an abort if
something has gone wrong. There's a couple of problems with this. One is there's some dependencies
on the coordinator here, that if the coordinator fails at the wrong
time things can go kind of screwy. And a fully distributed protocol for
insuring mutual committment of transactions, or other
kinds of operations, can be achieved. One of the most successful and
popular methods of doing this is an algorithm called Paxos, that we're
not going to talk about in detail. But you're gonna see that term if
you look at some of the readings for the new sequel systems. Okay, so think Two-Phase Commit
on a local cluster for a database, think Paxos for a distributed
sort of peer-to-peer kind of protocol. And just briefly what Paxos is essentially
doing is, it's a voting scheme. So people sort of vote on the individual
servers about to self determine whether or not they're supposed to commit
the transaction or not. And the details can get
a little bit subtle. But, overall it's pretty
simple given the nature, given the difficulty of
the task that's involved. Okay, so fine, so that's one problem. The other problem is just with
that Paxos sort of shares is that this can take a while. Right?
If subordinates don't respond promptly he might be waiting around if things fail
multiple times you need to abort and retry transactions of the applications
there, things can go slow. When there is, it doesn't necessarily
scares when there's thousands or millions of subordinates need to do this
or you're kind of dead in the water. So other protocols that I'm not gonna
talk about in too much detail include multi version, but you will see it
in some of the papers mentioned. Multi-version Concurrency Control where
each write creates a new version of the data item. And the legality of a read is determined
by checking the timestamp of the read transaction versus the current timestamp
of the version that you're trying to read. Okay, and if it's been updated since
the time you're supposed to be reading it, prior to MVCC all you could do
is abort the read and say, look, you're looking at dirty data, you're done. But with Multi-version Concurrency Control
you can actually keep multiple versions around and redirect the read to the, potentially to the prior
version that is correct. Okay, and thereby avoid
aborting certain transactions. That mechanism still has
a dependency on a coordinator role to administer time stamps. A fully distributed scheme,
where the decision to go forward with a transaction or
to abort a transaction is made the revoting scheme among peers is Paxos. And Paxos is very successful and
very widely applied and you'll see it mentioned in some
of those SQL papers if you take the time to read them and
they're on the reading list. And so this relieves the dependency
on having these central coordinator, but is still Synchronous and
still has the potential for deadlock and can take some amount of time to reach
consensus depending on what's going on and what kind of failures are happening. And so it's difficult to
guarantee very high performance or very low latency response times. [MUSIC]

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

一致性的3种协议,并发,事务 的相关文章

  • 【计算机开题报告】基于JSP的服装店销售管理系统

    1 选课目的意义 21世纪是一个信息化时代 随着中国经济的发展和人民生活水平的提高 服装商场的普及程度日益增大 竞争也在逐渐白炽化 为了进一步提高服装商场的经营效率 在服装店销售管理中引入计算机管理系统成为了必然的选择 由于中国环境的特殊性
  • ERROR 5025 (HY000): Insert has filtered data in strict mode, tracking_url=http://IP

    通过http api批量插入数据的时候报Reason null value for not null column column xxx src line 解决方法 检查是否有null值存在 增加数据库字段长度 如下语句更改长度 ALTER
  • 如何在CentOS安装SQL Server数据库并通过内网穿透工具实现公网访问

    文章目录 前言 1 安装sql server 2 局域网测试连接 3 安装cpolar内网穿透 4 将sqlserver映射到公网 5 公网远程连接 6 固定连接公网地址 7 使用固定公网地址连接 前言 简单几步实现在Linux cento
  • 神州信息一表通监管合规系统

    什么是 一表通 国家金融监督管理总局为进一步建立健全数据统计监管体系 规范数据报送指标体系 明确检测数据规则 而推行建立的一套新体系监管报送方式 提升校验准确性和信息安全性 近期 国家金融监督管理总局更是进一步加大推动 一表通 的实行试点范
  • Qt源码分析:Qt程序是怎么运行起来的?

    一 从 exec 谈起 一个标准的Qt gui程序 在启动时我们会coding如下几行简洁的代码 include widget h include
  • AntDB内存管理之内存上下文之如何使用内存上下文

    5 如何使用内存上下文 使用内存上下文之前 我们需要先对其进行创建 AntDB启动时已经创建并初始化好了部分内存上下文 例如 TopMemoryContext 这个TopMemoryContext是所有内存上下文的父节点或者祖先节点 一般我
  • 阿里技术官亲笔力作:Kafka限量笔记,一本书助你掌握Kafka的精髓

    前言 分布式 堪称程序员江湖中的一把利器 无论面试还是职场 皆是不可或缺的技能 而Kafka 这款分布式发布订阅消息队列的璀璨明珠 其魅力之强大 无与伦比 对于Kafka的奥秘 我们仍需继续探索 要论对Kafka的熟悉程度 恐怕阿里的大佬们
  • 【Mysql】InnoDB 引擎中的页目录

    一 页目录和槽 现在知道记录在页中按照主键大小顺序串成了单链表 那么我使用主键查询的时候 最顺其自然的办法肯定是从第一条记录 也就是 Infrimum 记录开始 一直向后找 只要存在总会找到 这种在数据量少的时候还好说 一旦数据多了 遍历耗
  • 【计算机毕业设计】病房管理系统

    当下 如果还依然使用纸质文档来记录并且管理相关信息 可能会出现很多问题 比如原始文件的丢失 因为采用纸质文档 很容易受潮或者怕火 不容易备份 需要花费大量的人员和资金来管理用纸质文档存储的信息 最重要的是数据出现问题寻找起来很麻烦 并且修改
  • 【计算机毕业设计】线上招聘问答系统

    计算机网络发展到现在已经好几十年了 在理论上面已经有了很丰富的基础 并且在现实生活中也到处都在使用 可以说 经过几十年的发展 互联网技术已经把地域信息的隔阂给消除了 让整个世界都可以即时通话和联系 极大的方便了人们的生活 所以说 线上招聘问
  • 软件测试|SQLAlchemy环境安装与基础使用

    简介 SQLAlchemy 是一个强大的 Python 库 用于与关系型数据库进行交互 它提供了高度抽象的对象关系映射 ORM 工具 允许使用 Python 对象来操作数据库 而不必编写原生SQL查询 本文将介绍如何安装 SQLAlchem
  • 深入了解 Python MongoDB 查询:find 和 find_one 方法完全解析

    在 MongoDB 中 我们使用 find 和 find one 方法来在集合中查找数据 就像在MySQL数据库中使用 SELECT 语句来在表中查找数据一样 查找单个文档 要从MongoDB的集合中选择数据 我们可以使用 find one
  • 【计算机毕业设计】电商个性化推荐系统

    伴随着我国社会的发展 人民生活质量日益提高 于是对电商个性化推荐进行规范而严格是十分有必要的 所以许许多多的信息管理系统应运而生 此时单靠人力应对这些事务就显得有些力不从心了 所以本论文将设计一套电商个性化推荐系统 帮助商家进行商品信息 在
  • 【计算机毕业设计】电影播放平台

    电影播放平台采用B S架构 数据库是MySQL 网站的搭建与开发采用了先进的java进行编写 使用了springboot框架 该系统从两个对象 由管理员和用户来对系统进行设计构建 主要功能包括 个人信息修改 对用户 电影分类 电影信息等功能
  • 【计算机毕业设计】二手家电管理平台

    时代在飞速进步 每个行业都在努力发展现在先进技术 通过这些先进的技术来提高自己的水平和优势 二手家电管理平台当然不能排除在外 二手家电管理平台是在实际应用和软件工程的开发原理之上 运用java语言以及前台VUE框架 后台SpringBoot
  • 盲猜你不懂H5架构和原生架构的区别

    2024软件测试面试刷题 这个小程序 永久刷题 靠它快速找到工作了 刷题APP的天花板 CSDN博客 文章浏览阅读2 3k次 点赞85次 收藏11次 你知不知道有这么一个软件测试面试的刷题小程序 里面包含了面试常问的软件测试基础题 web自
  • 数据库 | 面试官:一次到底插入多少条数据合适啊?.....面试连环炮

    数据库 面试官 一次到底插入多少条数据合适啊 面试连环炮 数据库插入操作的基础知识 插入数据是数据库操作中的基础 但是 我们程序员将面临随之而来的问题 如何快速有效地插入数据 并保持数据库 性能 当你向数据库中插入数据时 这些数据直接存储到
  • DockerCompose - 微服务项目部署全过程(最佳实践)

    目录 一 微服务项目部署 1 1 项目介绍 1 2 准备 MySQL 初始化文件 1 3 pom xml 插件 1 4 测试工作 1 5 编写 Dockerflie 文件 1 6 编写 DockerCompose yml 文件 1 7 修改
  • 温室气体排放更敏感的模型(即更高的平衡气候敏感性(ECS))在数年到数十年时间尺度上也具有更高的温度变化(Python代码实现)

    欢迎来到本博客 博主优势 博客内容尽量做到思维缜密 逻辑清晰 为了方便读者 座右铭 行百里者 半于九十 本文目录如下 目录 1 概述 2 运行结果 3 参考文献 4 Python代码 数据
  • 每日变更的最佳实践

    在优维公司内部 我们采用发布单的方式进行每天的应用变更管理 这里给各位介绍优维的最佳实践 变更是需要多角色合作的 而且他是整体研发流程的一部分 在优维内部 我们坚持每日变更 打通开发环节到最终发布上线的全过程 在保证质量的前提下 尽可能提升

随机推荐

  • 概率论与数理统计

    概率论与数理统计 一 概率论基本概述 1 1 随机试验 1 2 样本空间与随机事件 1 3 频率与概率 1 4 古典概型 1 5 条件概率 1 6 独立性 二 随机变量及其分布 2 1 随机变量 2 2 离散型随机变量及其分布 2 3 随机
  • mbed OS会成为物联网的 Android 吗?

    转载至 http www mbed org cn archives mbed os E4 BC 9A E6 88 90 E4 B8 BA E7 89 A9 E8 81 94 E7 BD 91 E7 9A 84 android E5 90 9
  • 使用远程服务器总是因网络中断、终端不小心关闭、锁屏等导致程序中断

    分享编程工具实用方法 面对无穷无尽的配置bug 其他文章 Windows连接远程Linux服务器 VSCode配置 免密设置 跳板机配置 GeForce RTX 3090无法使用mmsegmentation官方推荐cuda版本 ubuntu
  • 计算机辅助实验圆弧连接画法,机械制图基础-18、圆弧连接的画法

    绘图时 经常要用已知半径的圆弧 但圆心要在作图中确定 这样的圆弧 称为连接圆弧 连接圆弧需要光滑连接已知直线或圆弧 光滑连接也就是要在连接点处相切 为了保证相切 必须准确地作出连接圆弧的圆心和切点 一 用已知半径为R的圆弧连接两条已知直线
  • 超七成阅读APP都借百度语音技术促用户增长

    全国十多亿人在这个春节集体 关门闭户 与手机和网络作伴 除了手游和短视频流量飞涨 在线阅读也迎来 高光时刻 特别是当手机阅读APP标配了语音朗读即 听书 功能 据百度大脑AI开放平台的后台数据显示 疫情期间 支持 听书 功能的语音合成技术的
  • 重新映射图像——OpenCV Remap实例

    重新映射图像 OpenCV Remap实例 在计算机视觉领域中 图像的几何变换是一项重要的工作 重要的任务之一是将图像转换为其他形式 例如投影或扭曲 OpenCV的Remap函数提供了一个简单和灵活的方法来执行这种类型的变换 下面展示了如何
  • unsigned char 数值溢出问题

    include
  • 在D盘使用SVN检出文件后,整个盘出现蓝色问号的解决办法。

    在D盘使用SVN检出文件后 整个盘出现蓝色问号的解决办法 原因 在该盘的根目录执行了checkout操作 SVN将整个盘作为了一个版本库的本地副本 那些问号表示这些文件没有被SVN控制 解决方法 1 在文件上右击 选择TortoiseSVN
  • android studio电影院选座,8排电影院选座最佳位置

    8排电影院选座最佳位置在哪里呢 8排电影院属于小影厅 小影厅银幕宽度在10米以下 座位100以内 座位排数通常拥有8 14排 小影厅整体空间小 选座时要选中间稍靠后一些的位置 由于整体排数少 因此选即便选择靠后一些的排数实际上距银幕的距离也
  • ubuntu 同时使用无线网卡和有线网卡

    转载于这位博主 文章
  • Ubuntu18.04 取消开机密码 实现自动登录

    因为要把Ubuntu设备作为服务器 实现开机自动运行服务程序 所以需要取消开机密码 实现自动登录 1 点击桌面右上角向下的箭头 点击设置图标 2 点击右上角的 Unlock 3 在弹出的窗口中输入系统登录密码 点击右下角 Authentic
  • OpenMP并行编程

    1 总览 OpenMP Open Multi Processing 是一种用于共享内存并行系统的多线程程序设计方案 支持的编程语言包括C C 和Fortran OpenMP提供了对并行算法的高层抽象描述 通过线程实现并行化 特别适合在多核C
  • springboot使用logback日志框架超详细教程

    前言 项目中日志系统是必不可少的 目前比较流行的日志框架有log4j logback等 可能大家还不知道 这两个框架的作者是同一个人 Logback旨在作为流行的log4j项目的后续版本 从而恢复log4j离开的位置 另外 slf4j Si
  • 阶乘约数

    include
  • 【4月第二周学习记录】数据结构与算法王卓-第六章图-图的遍历(邻接矩阵与邻接表,DFS与BFS)

    1 图的遍历基本思路与方法 图的遍历的定义与visited数组 常用的遍历方法 深度优先搜索遍历 Depth First Search DFS 广度优先搜索遍历 Breadth First Search BFS 2 深度优先搜索遍历 Dep
  • 华为SMC2.0视频会议系统总结(一)

    简单总结下 新上手的华为视频会议SMC2 0会控系统 第一次接触华为的会控系统 理解的不是很深刻 简单的记下来 省得以后忘记 因为客户使用的泛微OA系统 我们公司 南大智慧 负责提供华为设备 并做相应的接口开发工作 我们主要的工作内容就是确
  • 控制器的编码器

    一 原理 控制器内部为每个轴配置了脉冲计数装置 控制器默认的脉冲计数源是外部编码器 如果用户 在接线时将外部编码器的信号与端子板 25pin轴接口的编码器信号接在一起 就可以调用指令读取外部编码器的值 如果用户没有接外部编码器反馈信号 例如
  • java基础学习 day22(方法,return,重载)

    1 方法 是程序中最小的执行单元 方法里面的代码 要么全都执行 要么全都不执行 重复的代码 具有独立功能的代码可以抽取到方法中 方法的好处 可以提高代码的复用性 可以提高代码的可维护性 java虚拟机在运行时会先自动调用main 方法 2
  • ## 带AB相编码器直流减速电机测转动速度及角度深度解析

    带AB相编码器直流减速电机测转动速度及角度深度解析 下图为编码器输出的AB相波形 一般情况下 我们只测A相 或B相 的上升沿或下降沿 但四倍频的方法是测A相和B相的上升沿和下降沿 在同样的时间内 计数脉冲是以前的4倍 然后stm32单片机可
  • 一致性的3种协议,并发,事务

    Two Phase Commit MVCC Paxos TPC对应于传统数据库上的local cluster的一致性 分布式事务 每个节点上的local事务可以是不同的亦可以是相同的 replica MVCC的思想是抓住Transactio