牙疼吃什么药最好最有效| 武则天姓什么| 皮肤长斑是什么原因引起的| 寒衣节是什么意思| 手脚发热吃什么药| 经常早上肚子疼是什么原因| 看见双彩虹有什么征兆| 清白是什么意思| 法令纹用什么填充效果最好| 算了吧什么意思| 孕妇吃什么容易滑胎| 气滞血瘀吃什么食物好| 高密度脂蛋白高是什么原因| 什么动物有四个胃| 介词后面跟什么| 赖是什么意思| 血小板低看什么科| 刘字五行属什么| 耳朵红热是什么原因| bea是什么意思| 阴道有豆腐渣用什么药| 幽门螺杆菌是什么意思| 宝宝乳糖不耐受喝什么奶粉比较好| 人为什么要洗澡| 7月8号是什么星座| 微商是什么| 洗面奶什么时候用最好| 曹休和曹操什么关系| 纳闷是什么意思| 多吃苹果有什么好处| 父母有刑是什么意思| 胃炎吃什么中药| 书五行属性是什么| 什么是环切手术| 低血糖什么不能吃| 三高是什么| 麦冬有什么功效| 葫芦什么时候成熟| 各生欢喜什么意思| 鸦雀无声是什么意思| 什么是低碳饮食| 女生白带是什么| 人体最大的排毒器官是什么| 中老年补钙吃什么钙片好| 棺材一般用什么木头| 芒果不可以跟什么一起吃| 阅历是什么意思| 男人右眼跳是什么预兆| 5.8是什么星座| 8月29是什么星座| 氯雷他定片是什么药| 疑虑是什么意思| 七星伴月是什么意思| 8月30号是什么星座| 焦虑症吃什么药效果好| revive是什么意思| 生育保险有什么用| 衣带渐宽终不悔是什么意思| 胃肠感冒吃什么食物比较好| 乳房疼挂什么科室| 为什么叫中日友好医院| 分贝是什么意思| 什么是呼吸性碱中毒| 大黄是什么药| 白事是什么意思| 慢性咽炎吃什么药| pg是什么单位| 越南三宝是什么| 猫代表什么数字| 血压低吃什么好| 脑供血不足吃什么药最好| 七月二十八什么星座| 空调风扇不转是什么原因| 玄武是什么动物| 添丁是什么意思| 射手是什么星象| 烟火气息是什么意思| 小孩睡觉磨牙齿是什么原因| 广东话扑街是什么意思| 吃了发芽的土豆会有什么症状| 不知餍足什么意思| iqc是什么意思| 风言风语是什么意思| 血栓吃什么药最好| 不孕为什么要查胰岛素| 策反是什么意思| 结扎什么意思| 景页读什么| 朕是什么时候开始用的| 开火车什么意思| 脸上长扁平疣是什么原因引起的| 水潴留是什么意思| 阴道炎要用什么药| 冯庸大学现在叫什么| 决断是什么意思| 赛治是什么药| 老人睡眠多是什么原因| 脚背疼是什么原因| 归元寺求什么最灵验| 安宫牛黄丸治什么病| 被蝎子蛰了用什么药| 黄痰吃什么药最好| 蜈蚣属于什么类动物| 一月十八是什么星座| 腹泻呕吐是什么原因| 朱雀玄武是什么意思| 尿频尿急尿痛吃什么药| 欧洲为什么没有统一| 日字旁跟什么有关| 舌苔发白吃什么药| 什么地画| 菩提树是什么树| 颈椎病引起的头晕吃什么药| 前夕是什么意思| 肌肉抖动是什么原因| 跳蚤喜欢咬什么样的人| 花椒什么时候传入中国| 男性湿热吃什么药最好| 手关节疼痛是什么原因| 西洋参什么时候吃效果最好| 风湿性关节炎挂什么科| 月经期间同房有什么危害| 1.15是什么星座| 生化是什么原因引起的| 全脂奶粉是什么意思| 10月24号是什么星座| hr是什么单位| 臆想症是什么| 浑圆是什么意思| 什么是教育| 咬肌疼是什么原因| 6月5号什么星座| 什么一梦| 斗是什么样子| 卡波姆是什么| 四大美女是什么生肖| 八月份是什么季节| 只要睡觉就做梦是什么原因| 郎才女貌是什么意思| 身上长红色的痣是什么原因| 下面外面瘙痒用什么药| vane是什么意思| 85年属什么的| 该说不说的是什么意思| 书到用时方恨少下一句是什么| 什么食物含维生素a| 大三阳是什么病| 上海话册那是什么意思| 为什么眼睛会痛| 怀孕之后身体有什么变化| 泥灸是什么| 私密瘙痒是什么原因| 药剂师是什么专业| 黄芪长什么样子| aoerbo是什么牌子的手表| 九月初十是什么星座| 老人说胡话是什么征兆| 乳腺结节有什么症状| 11月6日什么星座| bi是什么| 喉咙有痰吃什么药| 开业送什么| 葡萄糖粉适合什么人喝| 颈椎骨质增生吃什么药效果好| 拷贝是什么意思| 口头禅是什么意思| 七什么什么什么成语| 扁桃体炎吃什么消炎药| 郁郁寡欢的意思是什么| 散射光是什么意思| 脾脏是人体的什么器官| 黄体不足吃什么| 蓝色配什么颜色好看| 黄体生成素高是什么原因| 教育的本质是什么| 唱反调是什么意思| 晨起口干口苦是什么原因| 日落西山是什么生肖| 男性生殖系统感染吃什么药| 了口是什么字| 耳蜗是什么东西| 什么是更年期| 双生是什么意思| www是什么网| 智齿是什么原因引起的| 肠易激综合征中医叫什么| 什么出什么外| 庄周梦蝶什么意思| 身体缺钾吃什么药| 血稠吃什么药好| ccu病房是什么意思| ige是什么意思| 查乙肝挂什么科| 包虫病是什么症状| 纳财适合做什么| 难能可贵是什么意思| 咂是什么意思| 白醋和白米醋有什么区别| 但愿是什么意思| 机械表是什么意思| 什么无云| 皮肤过敏挂什么科| 东莞市委书记什么级别| 肚子疼恶心想吐吃什么药| 绿茶婊什么意思| 无后为大是什么意思| 男性左下腹痛是什么原因| 水漫金山是什么生肖| 阿耨多罗三藐三菩提是什么意思| 马踏飞燕什么意思| 小鱼吃什么| 胆红素三个指标都高是什么原因| 胡萝卜什么时间种| 05年属什么| 百家姓第一个姓是什么| 戴朱砂有什么好处| 花干是什么做的| 金星原名叫什么| 天蝎座和什么座最配对| 舌苔黄腻吃什么中成药| 小孩包皮挂什么科| 体温偏高的人说明什么| 小孩几天不大便是什么原因怎么办| 夏吃姜有什么好处| 唇珠是什么| 感冒适合吃什么饭菜| 春天能干什么| 故宫为什么叫故宫| 10.30什么星座| 为什么蝙蝠会飞进家里| 名落孙山的意思是什么| 眉毛里面有痣代表什么| 什么是小三阳| 脚趾麻木是什么病先兆| 蛋白是什么东西| 33代表什么意思| 86年属什么的| 日久生情什么意思| 儿童咳嗽吃什么药管用| 阉了是什么意思| 猛犸象什么时候灭绝的| outlets是什么意思| 瑞五行属什么| 披什么散什么| 主动脉硬化吃什么药好| 给孩子测骨龄应该挂什么科| 元字五行属什么| 前列腺肥大吃什么药效果最好| 电灯是什么时候发明的| 忽然流鼻血是什么原因引起的| 黄酒是什么| 脚后跟干裂起硬皮用什么药| 元宝是什么意思| 脚上长鸡眼去医院挂什么科| 对偶是什么| 猫的眼睛晚上为什么会发光| 右肺中叶纤维灶是什么意思| 胃结石有什么症状表现| 6度醋与9度有什么区别| 抠是什么意思| 肺部微结节是什么意思| 梦见把蛇打死了是什么意思| 仓鼠怀孕有什么特征| 东华帝君是什么神仙| 百度Jump to content

From Wikipedia, the free encyclopedia
(Redirected from ACID (computer science))
百度 面向未来,衡水也已经确立以装备制造、功能材料、纺织家居、食品医药、新兴产业、现代农业商贸物流、文化旅游为重点的4+4现代产业体系规划,着力推动相关产业梯次演进。

In computer science, ACID (atomicity, consistency, isolation, durability) is a set of properties of database transactions intended to guarantee data validity despite errors, power failures, and other mishaps. In the context of databases, a sequence of database operations that satisfies the ACID properties (which can be perceived as a single logical operation on the data) is called a transaction. For example, a transfer of funds from one bank account to another, even involving multiple changes such as debiting one account and crediting another, is a single transaction.

In 1983,[1] Andreas Reuter and Theo H?rder coined the acronym ACID, building on earlier work by Jim Gray[2] who named atomicity, consistency, and durability, but not isolation, when characterizing the transaction concept. These four properties are the major guarantees of the transaction paradigm, which has influenced many aspects of development in database systems.

According to Gray and Reuter, the IBM Information Management System supported ACID transactions as early as 1973 (although the acronym was created later).[3]

BASE stands for basically available, soft state, and eventually consistent: the acronym highlights that BASE is opposite of ACID, like their chemical equivalents.[4] ACID databases prioritize consistency over availability — the whole transaction fails if an error occurs in any step within the transaction; in contrast, BASE databases prioritize availability over consistency: instead of failing the transaction, users can access inconsistent data temporarily: data consistency is achieved, but not immediately.[5]

Characteristics

[edit]

The characteristics of these four properties as defined by Reuter and H?rder are as follows:

Atomicity

[edit]

Transactions are often composed of multiple statements. Atomicity guarantees that each transaction is treated as a single "unit", which either succeeds completely or fails completely: if any of the statements constituting a transaction fails to complete, the entire transaction fails and the database is left unchanged. An atomic system must guarantee atomicity in each and every situation, including power failures, errors, and crashes.[6] A guarantee of atomicity prevents updates to the database from occurring only partially, which can cause greater problems than rejecting the whole series outright. As a consequence, the transaction cannot be observed to be in progress by another database client. At one moment in time, it has not yet happened, and at the next, it has already occurred in whole (or nothing happened if the transaction was cancelled in progress).

Consistency

[edit]

Consistency ensures that a transaction can only bring the database from one consistent state to another, preserving database invariants: any data written to the database must be valid according to all defined rules, including constraints, cascades, triggers, and any combination thereof. This prevents database corruption by an illegal transaction. An example of a database invariant is referential integrity, which guarantees the primary keyforeign key relationship.[7]

Isolation

[edit]

Transactions are often executed concurrently (e.g., multiple transactions reading and writing to a table at the same time). Isolation ensures that concurrent execution of transactions leaves the database in the same state that would have been obtained if the transactions were executed sequentially. Isolation is the main goal of concurrency control; depending on the isolation level used, the effects of an incomplete transaction might not be visible to other transactions.[8]

Durability

[edit]

Durability guarantees that once a transaction has been committed, it will remain committed even in the case of a system failure (e.g., power outage or crash). This usually means that completed transactions (or their effects) are recorded in non-volatile memory.[9]

Examples

[edit]

The following examples further illustrate the ACID properties. In these examples, the database table has two columns, A and B. An integrity constraint requires that the value in A and the value in B must sum to 100. The following SQL code creates a table as described above:

CREATE TABLE acidtest (A INTEGER, B INTEGER, CHECK (A + B = 100));

Atomicity

[edit]

Atomicity is the guarantee that series of database operations in an atomic transaction will either all occur (a successful operation), or none will occur (an unsuccessful operation). The series of operations cannot be separated with only some of them being executed, which makes the series of operations "indivisible". A guarantee of atomicity prevents updates to the database from occurring only partially, which can cause greater problems than rejecting the whole series outright. In other words, atomicity means indivisibility and irreducibility.[10] Alternatively, we may say that a logical transaction may be composed of several physical transactions. Unless and until all component physical transactions are executed, the logical transaction will not have occurred.

An example of an atomic transaction is a monetary transfer from bank account A to account B. It consists of two operations, withdrawing the money from account A and depositing it to account B. We would not want to see the amount removed from account A before we are sure it has also been transferred into account B. Performing these operations in an atomic transaction ensures that the database remains in a consistent state, that is, money is neither debited nor credited if either of those two operations fails.[11]

Consistency failure

[edit]

Consistency is a very general term, which demands that the data must meet all validation rules. In the previous example, the validation is a requirement that A + B = 100. All validation rules must be checked to ensure consistency. Assume that a transaction attempts to subtract 10 from A without altering B. Because consistency is checked after each transaction, it is known that A + B = 100 before the transaction begins. If the transaction removes 10 from A successfully, atomicity will be achieved. However, a validation check will show that A + B = 90, which is inconsistent with the rules of the database. The entire transaction must be canceled and the affected rows rolled back to their pre-transaction state. If there had been other constraints, triggers, or cascades, every single change operation would have been checked in the same way as above before the transaction was committed. Similar issues may arise with other constraints. We may have required the data types of both A and B to be integers. If we were then to enter, say, the value 13.5 for A, the transaction will be canceled, or the system may give rise to an alert in the form of a trigger (if/when the trigger has been written to this effect). Another example would be integrity constraints, which would not allow us to delete a row in one table whose primary key is referred to by at least one foreign key in other tables.

Isolation failure

[edit]

To demonstrate isolation, we assume two transactions execute at the same time, each attempting to modify the same data. One of the two must wait until the other completes in order to maintain isolation.

Consider two transactions:

  • T1 transfers 10 from A to B.
  • T2 transfers 20 from B to A.

Combined, there are four actions:

  1. T1 subtracts 10 from A.
  2. T1 adds 10 to B.
  3. T2 subtracts 20 from B.
  4. T2 adds 20 to A.

If these operations are performed in order, isolation is maintained, although T2 must wait. Consider what happens if T1 fails halfway through. The database eliminates T1's effects, and T2 sees only valid data.

By interleaving the transactions, the actual order of actions might be:

  1. T1 subtracts 10 from A.
  2. T2 subtracts 20 from B.
  3. T2 adds 20 to A.
  4. T1 adds 10 to B.

Again, consider what happens if T1 fails while modifying B in Step 4. By the time T1 fails, T2 has already modified A; it cannot be restored to the value it had before T1 without leaving an invalid database. This is known as a write-write contention,[12] because two transactions attempted to write to the same data field. In a typical system, the problem would be resolved by reverting to the last known good state, canceling the failed transaction T1, and restarting the interrupted transaction T2 from the good state.

Durability failure

[edit]

Consider a transaction that transfers 10 from A to B. First, it removes 10 from A, then it adds 10 to B. At this point, the user is told the transaction was a success. However, the changes are still queued in the disk buffer waiting to be committed to disk. Power fails and the changes are lost, but the user assumes (understandably) that the changes persist.

Implementation

[edit]

Processing a transaction often requires a sequence of operations that is subject to failure for a number of reasons. For instance, the system may have no room left on its disk drives, or it may have used up its allocated CPU time. There are two popular families of techniques: write-ahead logging and shadow paging. In both cases, locks must be acquired on all information to be updated, and depending on the level of isolation, possibly on all data that may be read as well. In write ahead logging, durability is guaranteed by writing the prospective change to a persistent log before changing the database. That allows the database to return to a consistent state in the event of a crash. In shadowing, updates are applied to a partial copy of the database, and the new copy is activated when the transaction commits.

Locking vs. multiversioning

[edit]

Many databases rely upon locking to provide ACID capabilities. Locking means that the transaction marks the data that it accesses so that the DBMS knows not to allow other transactions to modify it until the first transaction succeeds or fails. The lock must always be acquired before processing data, including data that is read but not modified. Non-trivial transactions typically require a large number of locks, resulting in substantial overhead as well as blocking other transactions. For example, if user A is running a transaction that has to read a row of data that user B wants to modify, user B must wait until user A's transaction completes. Two-phase locking is often applied to guarantee full isolation.

An alternative to locking is multiversion concurrency control, in which the database provides each reading transaction the prior, unmodified version of data that is being modified by another active transaction. This allows readers to operate without acquiring locks, i.e., writing transactions do not block reading transactions, and readers do not block writers. Going back to the example, when user A's transaction requests data that user B is modifying, the database provides A with the version of that data that existed when user B started his transaction. User A gets a consistent view of the database even if other users are changing data. One implementation, namely snapshot isolation, relaxes the isolation property.

Distributed transactions

[edit]

Guaranteeing ACID properties in a distributed transaction across a distributed database, where no single node is responsible for all data affecting a transaction, presents additional complications. Network connections might fail, or one node might successfully complete its part of the transaction and then be required to roll back its changes because of a failure on another node. The two-phase commit protocol (not to be confused with two-phase locking) provides atomicity for distributed transactions to ensure that each participant in the transaction agrees on whether the transaction should be committed or not.[13] Briefly, in the first phase, one node (the coordinator) interrogates the other nodes (the participants), and only when all reply that they are prepared does the coordinator, in the second phase, formalize the transaction.

See also

[edit]

References

[edit]
  1. ^ Haerder, T.; Reuter, A. (1983). "Principles of transaction-oriented database recovery". ACM Computing Surveys. 15 (4): 287. doi:10.1145/289.291. S2CID 207235758.
  2. ^ Gray, Jim (September 1981). "The Transaction Concept: Virtues and Limitations" (PDF). Proceedings of the 7th International Conference on Very Large Databases. Cupertino, California: Tandem Computers. pp. 144–154. Retrieved March 27, 2015.
  3. ^ Gray, Jim; Reuter, Andreas (1993). Distributed Transaction Processing: Concepts and Techniques. Morgan Kaufmann. ISBN 1-55860-190-2.
  4. ^ "ACID vs BASE Databases - Difference Between Databases - AWS". Amazon Web Services, Inc. Retrieved 2025-08-05.
  5. ^ "ACID vs BASE Databases - Difference Between Databases - AWS". Amazon Web Services, Inc. Retrieved 2025-08-05.
  6. ^ "Atomic operation". webopedia.com. Webopedia. 25 November 2003. Retrieved 2025-08-05. An operation during which a processor can simultaneously read a location and write it in the same bus operation. This prevents any other processor or I/O device from writing or reading memory until the operation is complete.
  7. ^ C. J. Date, "SQL and Relational Theory: How to Write Accurate SQL Code 2nd edition", O'reilly Media, Inc., 2012, p. 180.
  8. ^ Archiveddocs (2025-08-05). "Isolation Levels in the Database Engine". learn.microsoft.com. Retrieved 2025-08-05.
  9. ^ Silberschatz, Abraham; Korth, Henry F.; Sudarshan, S. (2011). "Transactions". Database system concepts (6th ed.). New York: McGraw-Hill. p. 631. ISBN 978-0-07-352332-3. OCLC 436031093.
  10. ^ "Atomicity". docs.oracle.com. Retrieved 2025-08-05.
  11. ^ Amsterdam, Jonathan. "Atomic File Transactions, Part 1". O'Reilly. Archived from the original on 2025-08-05. Retrieved 2025-08-05.
  12. ^ Silberschatz, Abraham; Korth, Henry F.; Sudarshan, S. (2011). "Advanced Application Development". Database system concepts (6th ed.). New York: McGraw-Hill. p. 1042. ISBN 978-0-07-352332-3. OCLC 436031093.
  13. ^ Bernstein, Philip A.; Newcomer, Eric (2009). "Chapter 8". Principles of Transaction Processing (2nd ed.). Morgan Kaufmann (Elsevier). ISBN 978-1-55860-623-4. Archived from the original on 2025-08-05.
消化不良吃什么 什么是电解质饮料 直视是什么意思 nsaids是什么药 蛋白粉什么时候喝最好
临床药学在医院干什么 床上用品四件套都有什么 蒸蒸日上什么意思 月经前一周失眠是什么原因 胪是什么意思
妈妈最大的愿望是什么 胃反酸是什么原因造成的 luxury是什么牌子 阴道b超检查什么 什么是纳米
磁共振是检查什么的 老年人吃什么钙片补钙好 什么是阴历 总胆红素偏高说明什么 心路历程是什么意思
为什么会口臭的原因hcv9jop0ns7r.cn 骨质密度增高是什么意思hcv7jop7ns3r.cn 丁香花什么颜色hcv8jop2ns2r.cn 玉是什么结构的字fenrenren.com 乌龟为什么会叫creativexi.com
欣字属于五行属什么hcv8jop2ns8r.cn 胆囊炎是什么病hcv9jop5ns6r.cn 2月20是什么星座zhongyiyatai.com 辟邪剑谱和葵花宝典有什么关系hcv8jop3ns1r.cn 泪目是什么意思hcv7jop6ns6r.cn
lycra是什么面料sscsqa.com 松花粉有什么功效liaochangning.com 洗头膏什么牌子好hcv7jop9ns3r.cn fm是什么hcv8jop0ns6r.cn 虾黄是虾的什么部位hcv7jop9ns2r.cn
心绞痛吃什么药缓解最快weuuu.com 嫉妒是什么意思hcv9jop4ns5r.cn 妇科杆菌是什么引起的hcv9jop3ns8r.cn 学五行属什么xinjiangjialails.com 复印病历需要什么证件inbungee.com
百度