Part 4 of 5 · 2 min read
What happens once a dangerous structure is found
One of the involved transactions is aborted before it can commit, preserving serializability.
What happens once a dangerous structure is found
Think of the referee's assistant spotting the suspicious pattern. The assistant steps in right before either ruling is finalized and announced, requiring one of the two plays to be reviewed again from scratch.
In plain words: when a dangerous structure is detected involving a transaction that is about to commit, that transaction is aborted instead, typically to be retried by the application. This is similar in spirit to optimistic concurrency control's validation phase, covered three pages ago, in that the check happens close to commit time rather than through upfront locking, but it specifically targets the cross-transaction read-write patterns that plain snapshot isolation and plain optimistic concurrency control would otherwise both miss.
A worked example. In the doctors scenario, serializable snapshot isolation would detect the dangerous structure as transaction B attempts to commit after transaction A, and abort transaction B, forcing the application to retry it, by which point A's commit would already be visible and B's retry would correctly see only one doctor available.
The key lines. No new SQL; aborting the detected transaction and signaling the application to retry is the database's automatic response to a found dangerous structure.
Dangerous-structure abort
A dangerous-structure abort is the database's response to detecting a dangerous structure: aborting one of the involved transactions before it commits, preserving serializability at the cost of a retry.
Example: the referee's assistant halting one ruling right before it is finalized, requiring a fresh review, mirrors a dangerous-structure abort.
Remember this
Serializable snapshot isolation keeps MVCC's reader-writer non-blocking benefit for the common case, only paying a cost, an abort and retry, specifically when a dangerous structure is actually detected. This makes it a popular way to get true serializability without reverting to the upfront blocking of two-phase locking.
Quick notes
- Plain snapshot isolation has no mechanism for checking cross-transaction read-write interactions for safety.
- A dangerous structure is the specific read-write pattern between transactions that signals a potential violation like write skew.
- Read-write tracking detects a dangerous structure without acquiring locks upfront.
- A transaction involved in a detected dangerous structure is aborted before it can commit, and typically retried.
- Serializable snapshot isolation keeps most of MVCC's non-blocking benefit, paying a cost only when a violation is actually detected.