I'm interested in how database transactions "commonly" are implemented in a database system, like for instance MySQL.
Assuming the actual writing of data to the physical database storage isn't an atomic operation (speaking in terms of clockcycles now), shouldn't I be able to corrupt a transaction by for instance ripping the power cable at some carefully chosen moment?
If the database system is carefully written, there should be no point in time where power outage can corrupt data, and when power outage occurs, no committed data should ever be lost.
The rdbms writes data first to a transaction log before actually updating the data. After a crash, it replays the log, copying any pending changes from the log into the database, and rolling back any transactions which have not been completed in the log. Commit is reported as successful only after the hard disk has reported a completed write operation to the log.
Databases follow the ACID properties. No matter when something explodes, there's a way to at the very least roll-back to a known correct state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With