update? A doctor call system Constraint: At least one doctor should be on-call (a doctor can leave iff currently_on_call >= 2) Situation: Bob and Alice are on-call -> Bob read the current number (=2) -> Alice read the current number (=2) -> Bob left -> Alice left (anomaly) Is this a lost update?
overwrites the other’s write without incorporating its changes (so data is lost). Write skew Update not lost, but constraints fail due to concurrent commits.
detection △ - Most popular implementations of snapshot isolation don’t support the automatic detection of write skew. - Constraints that involves multiple objects △ - Few databases support - Use serializable isolation ✓ - SELECT FOR UPDATE ✓
some requirements are satisfied - Depending on the result of the first query, the application code decides how to continue - If the application decides to go ahead, it makes a write (INSERT, UPDATE, or DELETE) to the database and commits the transaction.
some requirements are satisfied - Depending on the result of the first query, the application code decides how to continue - If the application decides to go ahead, it makes a write (INSERT, UPDATE, or DELETE) to the database and commits the transaction.
some requirements are satisfied - Depending on the result of the first query, the application code decides how to continue - If the application decides to go ahead, it makes a write (INSERT, UPDATE, or DELETE) to the database and commits the transaction.
to understand - Inconsistent term usage - “repeatable read” varies from database engines - it’s difficult to tell whether it is safe to run at a particular isolation level - Some static analysis tools may help race detection - but it’s still hard because most races happen due to bad timings
faster - RAM is getting cheaper → the entire active dataset can be on memory - OLTP transactions are usually short - cf) OLAP … usually adopts snapshot isolation (typically read only)
the overhead of other concurrency control mechanisms Cons - Code running in a database is difficult to manage - debug, deploy - Badly written stored procedure can cause much more troubles
- So it prevents from write skew - Writers don’t just block other writers; they also block readers and vice versa - (cf) Snapshot Isolation … readers never block writers and writers never block readers Acquire a lock Release the lock
- some transactions are allowed simultaneously - if the object has an exclusive lock, the read should wait for it Write - Exclusive mode lock - No transactions can have a lock on the object at the same time
query is poor; - many locks - checking locks is time-consuming Index-range locking locks a greater set of objects for the fast checking of locks e.g. room 123 →room 100-150 (a greater and easy to search set)
penalty compared to snapshot isolation - Firstly execute query, and abort it when it is suspicious SSI is fairly new: it was first described in 2008 [40] and is the subject of Michael Cahill’s PhD thesis [51].
- connection between transactions is not too high e.g. counter increment - Order doesn’t matter - as long as the counter isn’t read in the same transaction,
2PL: a famous implementation of serializable isolation, usually with index-range lock - Serializable Snapshot Isolation performs well, while guarantee of serializability