Why and how is the term atomic used for ACID properties of database or atomic operations in Git commit?

233 views Asked by At

Atomic operations mean: either they succeed as whole, or they fail without any changes. They won't fail in between. How is this meaning/context related with the word "atomic"?

2

There are 2 answers

1
David Z On BEST ANSWER

"Atomic" comes from a Latin word for "indivisible", and thus atomic operations are those which (supposedly) cannot be divided. Either you get the whole thing or none of it. It's not possible for part of the operation to happen, at least not as far as the future state of the system is concerned.

See also this question on English SE.

3
jbu On

All your changes and all your changed files make it into the commit, then the commit gets added to the history as a single unit. If there is a single failure at all, the entire commit operation fails meaning none of your changes and none of your files are added into any would-be-commit; nothing is added to the revision history.

BTW, where are you reading about atomic git operations?

Regarding HOW it is atomic - I can't say for sure and I could be speaking out of my ass, but file systems (ntfs and ext3) are generally transactional and support atomic disk operations. Each commit does a hash of all its contents (the trees and blobs underneath). Then, the git plumbing can look into .git/objects and find that hash. If the hash is there, it will fail. If the hash slot is empty, it can proceed and use the underlying file system to provide transactional and atomic guarantees.