database 什么是 ACID 的真实示例?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/999394/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 07:21:25  来源:igfitidea点击:

What's a real-world example of ACID?

databaseacid

提问by Fred Stanley

I'm looking for a real-world example for the various ACID properties of a database.

我正在寻找数据库的各种 ACID 属性的真实示例。

回答by eggdrop

  • Atomicity- a transaction to transfer funds from one account to another involves making a withdrawal operation from the first account and a deposit operation on the second. If the deposit operation failed, you don't want the withdrawal operation to happen either.

  • Consistency- a database tracking a checking account may only allow unique check numbers to exist for each transaction

  • Isolation- a teller looking up a balance must be isolated from a concurrent transaction involving a withdrawal from the same account. Only when the withdrawal transaction commits successfully and the teller looks at the balance again will the new balance be reported.

  • Durability- A system crash or any other failure must not be allowed to lose the results of a transaction or the contents of the database. Durability is often achieved through separate transaction logs that can "re-create" all transactions from some picked point in time (like a backup).

  • 原子性- 将资金从一个帐户转移到另一个帐户的交易涉及从第一个帐户进行提款操作并在第二个帐户上进行存款操作。如果存款操作失败,您也不希望提款操作发生。

  • 一致性- 跟踪支票账户的数据库可能只允许每笔交易存在唯一的支票号码

  • 隔离- 查找余额的柜员必须与涉及从同一账户提款的并发交易隔离。只有当提现交易提交成功并且柜员再次查看余额时,才会报告新的余额。

  • 持久性- 不允许系统崩溃或任何其他故障导致事务结果或数据库内容丢失。持久性通常是通过单独的事务日志来实现的,这些日志可以从某个选定的时间点(如备份)“重新创建”所有事务。

(summary of the real world examples from le dorfier's link)

(来自 le dorfier链接的真实世界示例摘要)

回答by M.Nabeel

? Atomicity—From a user perspective, a transaction is either completed in its entirety (i.e., all relevant database tables are updated) or not at all. If an error or interruption occurs, all changes made up to that point are backed out.

? 原子性——从用户的角度来看,一个事务要么完全完成(即所有相关的数据库表都被更新),要么根本不完成。如果发生错误或中断,则在该点之前所做的所有更改都将被取消。

? Consistency—All integrity conditions in the database are maintained with each transaction, taking the database from one consistent state into another consistent state.

? 一致性——数据库中的所有完整性条件都与每个事务一起维护,使数据库从一种一致状态进入另一种一致状态。

? Isolation—Each transaction is isolated from other transactions, and hence, each transaction only accesses data that are part of a consistent database state.

? 隔离——每个事务都与其他事务隔离,因此,每个事务只访问属于一致数据库状态的数据。

? Durability—If a transaction has been reported back to a user as complete, the resulting changes to the database survive subsequent hardware or software failures.

? 持久性 —如果事务已完成报告给用户,则对数据库的结果更改在随后的硬件或软件故障中仍然存在。

回答by Todd Gardner

Take any given perl script you use to manipulate a data in a relational database, put a "BEGIN" at the top of it and a "COMMIT" at the bottom, and you know the perl script worked, or didn't have effect your database at all (unless you inserted DDL statements on mysql). Atomicity is very powerful to have an assurance like that when designing robust software (and my favorite of the properties).

使用您用来操作关系数据库中数据的任何给定 perl 脚本,在它的顶部放置一个“BEGIN”,在底部放置一个“COMMIT”,您就知道 perl 脚本起作用了,或者没有影响您的数据库(除非您在 mysql 上插入了 DDL 语句)。在设计健壮的软件(以及我最喜欢的属性)时,原子性非常强大,可以提供这样的保证。