简体   繁体   中英

How do databases provide atomicity?

Let's say I have a transaction that is supposed to increase a column value by 100. I can use a simple transaction to achieve this

Begin
Update table
set col1 = col1+100
where col2=val
End

I would like to know how does database provide atomicity. let's say there is power failure after we have written to disk, but have received confirmation for the completion of transaction. We might be under the impression that write was not successful, but it was and we might end up doing the transaction. How does database guard against such scenarios?

Before writing the changes to the disk, the database first writes to a log file. This log file will be referred during the 'instance recovery' post the crash.

The logging is designed to be immediate (we use faster disks for writing logs) While the writing to data file, is done 'lazy', ie whenever the write processors are free.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM