深度剖析 | 关于数据锁定和读取一致性问题

1 背景介绍

传统的 RDBMS 系统在三件事上值得注意:
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:4a92645e-3382-4f53-a1db-75ae6032b299

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:519bee3e-fea0-4b0e-b745-7b2d06735799

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:51e0d5bc-4973-4158-af7f-afe089b9138a

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:33cd674a-59a1-498a-a3b2-cb185dff582c

遗憾的是,其较差的可伸缩性:在线事务处理(OLTP)工作负载无法很好地扩展。在现实情况下,将CPU内核数量加倍不会使您的容量翻倍。

这种失败导致许多人尝试使用NoSQL解决方案,但是随着时间的流逝,越来越明显的是,如果没有这些解决方案,锁定和读取一致性将很难实现。
VOLTDB是唯一的数据平台,可让企业按比例进行锁定和读取一致性。

本文解释了为什么很难做到这一点,以及VOLTDB是如何做到这一点的。

2 为什么缩放OLTP很难?

为了让大家更直观地了解为什么扩展OLTP很难,先来让我们看一下简单的白板交易的典型生命周期:

  • 在表格” a”中插入一行
  • 更新表” b”中的行
  • 更新表” c”中的行
  • 做外部活动
  • 更新表” a”中的行
  • 犯罪

乍一看,可能很难看出这是如何扩展的。但是,让我们看一下使用旧版RDBMS的实际实现:

深度剖析 | 关于数据锁定和读取一致性问题

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:17813291-0b71-46e0-88f1-7a9881d49dfb

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:334b1004-c5e9-49f0-9ab3-39cfb23fb122

1.此操作不会立即完成

您需要12次网络运行,每次运行都需要花费不少时间。在任意一段时间内,”现实世界的设备”都会关闭,并会做任何需要做的事情。
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:11719503-7e08-40bf-9e1b-ad099549ebd6

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:fa4e74cd-256d-428d-a134-b8e6e2508052

2. 长时间运行的数据交换将是数据库服务器的挑战

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:fe122705-555f-44a4-b83f-d08730afd771

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:e91e5665-80f1-4bbb-9d1c-2a0443430073

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:43fe7d85-f99b-4ab9-8744-e94c14e79956

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:7e58f9f5-fc64-42df-9939-549d26d156ed

无论您使用SELECT FOR UPDATE,MVCC还是任何其他机制,此开销仍然存在。

3.当您增加CPU芯数时,递减收益法则就会生效
随着工作量的增加,常规解决方法是添加更多的CPU内核并将工作分散在它们之间。
虽然这在短期内会有所帮助,但它会带来另一个问题:当您只有一个CPU内核时,可以肯定的是,当尝试处理会话请求时,数据库的其他100个实时版本不会改变。这正是我们正在做的。
但是,添加第二个CPU内核后,数据库需要协调它们的活动。这引入了一个全新的层的开销,每当您在”帮助”中添加另一个CPU内核时,问题就会以几何级的速度变得更糟。
最终的结果是形成了一个恶性循环,在其中添加CPU内核以提高TPS,但是每个新内核都需要关联消耗所有其他核心,最终将消耗您通过添加额外核心获得的CPU容量。
如果额外的CPU容量来自群集中的另一个节点,那么事情将会出错。因为CPU内核之间相互争论的问题现在变成了到另一个数据库节点的网络访问。

4.随着容量的增加,性能变得越来越不稳定
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:4a078175-6392-4385-841d-945c66b551c0

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:65fcd105-0320-4083-ae21-b0cc5066a70e

一个典型的例子是网站访问者在添加购物车或购物篮并按下”重新加载”时会不耐烦,这可能会导致以下情况:旧请求已锁定记录,而新请求则通知用户”其他人”已锁定它。物联网(IoT)和电信应用程序尤其容易出现这种情况,因为许多API的默认行为是在未收到即时响应时自动重试。
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:2660a552-f191-4f3c-b129-a6d9b8dfc9f3

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:4a3ebae8-b70c-4a46-a671-247c84210e19

5.应用服务器或微服务器成为系统中的薄弱环节
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:2ec4459f-03d2-456a-9ac0-dcf97e22dce7

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:4c6fd6f5-7ba5-457f-bb75-952399ebf5b4

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:eac74151-83fe-411f-86d4-f67ee7d39a5e

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:4a07e885-72e2-4e4f-97a7-babbacbbd2a8

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:22b6a765-1789-4d82-a662-39d2ed83af4f

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:8d1b113d-be2e-4771-9826-7784795e3f2c

6.没有任何明显的方法可以解决此问题
尝试扩展OLTP的最简单方法是切换到NoSQL存储,该存储要求客户端在进行更改之前发送证明已读取特定版本的记录的证据。
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:a45ed539-270b-42b0-988e-7980fc22f9b9

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:63e31440-65dc-462e-a902-40c3926c52a8

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:f3f16eb6-12c8-4ba5-82eb-474e42730f53

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:c324c1c6-923e-487e-842a-184f93b8adcf

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:3bc3fe27-58a6-4b23-aec8-3e7a749bbeb1

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:c7aa70c3-870b-4584-a48b-2f0632669e5f

3 VOLTDB是如何做到这一点的?

VoltDB的创建者,包括图灵奖获得者Michael Stonebraker,都考虑到了这一特定问题,开发了VoltDB数据平台,并有效地解决了该问题。
VoltDB数据平台在做三件事上有不同之处:

1.IT分区将工作负载分配给每个分区,而这是控制CPU核心的单一物理线程的专有责任
是的,许多现代数据平台都在划分工作负载。但是,我们仅需将分区与在单个CPU内核上运行的单线程对齐即可,这意味着该内核无需担心另一个内核在做什么,因此,VoltDB立即消除了上述几何可伸缩性问题。

2.它允许任意数量的SQL语句和每个TRIP的逻辑关联到VOLTDB
尽管您可以愉快地将JDBC与VoltDB一起使用,但是当您尝试将事例名称和您使用的参数传递到 VoltDB 上的服务器侧逻辑时,您可以减少网络访问次数和VoltDB必须跟踪的中间状态数量。

3.它表明每次访问都以提交结束
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:0e040a99-2615-400b-a754-a8edad617b6d

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:ff09c283-ba64-4b63-9abd-6108cdc51aa8

在任何时候,VoltDB分区都仅仅处理一个事务,因为它只有单个线程”拥有”其中的所有数据。通过坚持所有事务都是”提交”或”返回”状态,VoltDB不必从客户的角度跟踪存储状态数据库的任何额外”副本”。因此,在上面的实例中,VoltDB实现无需跟踪数据库的100个版本, 每个分区仅使用一个活动副本。

综上,这些更改既为您提供了传统RDBMS的功能,并且具有出色的可伸缩性,其性能是同一个硬件的大约9倍。
现在,让我们看一下同一笔交易在VoltDB中是如何进展的。

深度剖析 | 关于数据锁定和读取一致性问题

这可以通过两次调用VoltDB来完成。第一次调用执行前三个更改,并将会话ID /到期日期添加到另外两个软锁列中。这允许其他交互查看正在进行的交易,并自行决定要做什么。当外部任务完成时,第二个调用触发,并清除软锁列。

深度剖析 | 关于数据锁定和读取一致性问题

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:b56eb903-f127-4078-845a-c3bdd5ad590c

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:48ee083c-f87a-45c6-837c-5288eca22f02

如您所见,VoltDB的真实事务是通过更少的网络行程,更少的客户端API调用以及通过避免应用服务器节点丢失的明确方法来完成的。但这并不意味着没有其他可考虑的情况。让我们看看有关VoltDB如何进行锁定和读取一致性的常见问题。

4 Q & A

1.如果数据库服务器出故障了怎么办?
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:9acc7edd-bfa0-4190-b4d2-955648ba813a

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:414b39e9-bcc6-40a3-b03a-b675f8f60b95

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:b92975c6-62c9-44e9-9e11-c71fb467bcc7

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:c8b57aa7-09c8-4119-99e4-c44409c30adb

2.如果应用程序服务器出现故障,该怎么办?
只要客户可以使用正确的锁标识符找我们,我们的处理将照常进行。在传统的RDBMS中,当涉及到锁定时,状态将有效地保留在客户端和服务器上,因为服务器已使用客户端会话唯一的标识符标记行。
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:7052db33-254e-4747-84d8-c3908f258251

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:a2e52fd8-7957-44ef-b5d1-7dcbec46797d

在VoltDB的系统里,我们通过允许多个SQL语句和关联的逻辑在服务器上运行,来”设计”大多数应用场景。如果逻辑交易在关联的交易事件完成之前依然无法完成,您可以使用简单的 SQL 自行锁定逻辑,从而重新控制情况并满足您的 SLAs 。
3.VoltDB是否会自动执行此操作?
不会,但是它在数据库表中多了两列,并增加了大约十二行代码。与处理传统 RDBMS 或 NoSQL 交易和锁定行为所需的开发人员时间相比,这是完全合理的。

4.我们仍然可以使用JDBC吗?

是的,我们的许多应用程序代码是基于JDBC的。在大多数应用程序中,20% 的开发人员时间用于编写 80% 的 SQL,这些 SQL 是友好的或直接的。其他 20% 涉及复杂的交易,正是这种方法使其变得非常有价值。
5.”每个内核一个分区一个线程”为何比共享工作负载的多线程和多内核更快?
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:bb515d07-adeb-4e75-b69b-9d65a2bdaca0

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:b5bdde40-2043-48c2-9f77-c414a6cd238e

5 结论

锁定和读取一致性是当今世纪的两个重要领域,RDBMS和较新的NoSQL系统都无法满足其需求,提供合理答案。在VoltDB,我们的使命是专注于可预测的、符合严苛标准的大规模交易。虽然我们理解我们的一些设计决策可能看起来非常规,但这些决策却是由多年的实际经验决定的。
如果您还有其他疑问,或者想了解更多有关VoltDB如何在保持低延迟的情况下支持现代应用程序的信息,请联系我们吧!

关于VoltDB
VoltDB支持强ACID和实时智能决策的应用程序,以实现互联世界。没有其它数据库产品可以像VoltDB这样,可以同时需要低延时、大规模、高并发数和准确性相结合的应用程序加油。
VoltDB由2014年图灵奖获得者Mike Stonebraker博士创建,他对关系数据库进行了重新设计,以应对当今不断增长的实时操作和机器学习挑战。Stonebraker博士对数据库技术研究已有40多年,在快速数据,流数据和内存数据库方面带来了众多创新理念。
在VoltDB的研发过程中,他意识到了利用内存事务数据库技术挖掘流数据的全部潜力,不但可以满足处理数据的延迟和并发需求,还能提供实时分析和决策。VoltDB是业界可信赖的名称,在诺基亚、金融时报、三菱电机、HPE、巴克莱、华为等领先组织合作有实际场景落地案例。

VoltDB中国:https://www.voltdb-china.cn/

Original: https://www.cnblogs.com/VoltDB/p/14763246.html
Author: VoltActiveData
Title: 深度剖析 | 关于数据锁定和读取一致性问题

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/562679/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球