I'm trying to learn more about database transactions, I found the ACID rule of thumb for writing transactions and thought of a few questions.
The ACID rule of thumb:
A transaction must be:
- Atomic - it is one unit of work and does not dependent on previous and
following transactions.
- Consistent - data is either committed or roll back, no
“in-between” case where something has
been updated and something hasn’t.
- Isolated - no transaction sees the intermediate results of the current
transaction.
- Durable - the values persist if the data had been committed even if
the system crashes right after.
I was wondering how they work under the hood, so I can better understand the factors that need to be considered when writing such a transaction. I guess the specific details will vary between the database implementations that are avaliable, but certain rules will always be in place.
- How does the database handle concurrent transactions whilst still supporting the Atomic rule?
- Is there a queue of transactions that is processed in order?
- How is a lengthy transaction that is holding up all others handled?
- Are updates to tables done in memory so if a crash does occur before commit, there is no alteration to the database?
- Or are there some intermediate tables that are updated to survive such a crash?
- Whilst a transaction is in progress, is all read and write access to the affected tables prevented?
- Or would the database allow writes but the transaction would overwrite all changes upon commit?
question from:
https://stackoverflow.com/questions/3466632/database-transactions-how-do-they-work 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…