Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, and Maintainable Systems
Rate it:
Open Preview
34%
Flag icon
snapshot isolation does not prevent another user from concurrently inserting a conflicting meeting.
34%
Flag icon
Phantoms causing write skew
34%
Flag icon
However, the other four examples are different: they check for the absence of rows matching some search condition,
34%
Flag icon
can’t attach locks to anything.
34%
Flag icon
where a write in one transaction changes the result of a search query in another transaction, is called a phantom
34%
Flag icon
Materializing conflicts
34%
Flag icon
can artificially introduce a lock object into the database?
34%
Flag icon
You create rows for all possible combinations of rooms and time periods ahead of time, e.g. for the next six months.
34%
Flag icon
This approach is called materializing conflicts, because it takes a phantom and turns it into a lock conflict on a concrete set of rows that exist in the database
34%
Flag icon
it can be hard and error-prone to figure out how to materialize conflicts, and it’s ugly to let a concurrency control mechanism leak into the application data model.
34%
Flag icon
materializing conflicts should be considered a last resort if no alt...
This highlight has been truncated due to consecutive passage length restrictions.
35%
Flag icon
Serializable isolation is usually regarded as the strongest isolation level.
35%
Flag icon
But if serializable isolation is so much better than the mess of weak isolation levels, then why isn’t everyone using
35%
Flag icon
will discuss these techniques primarily in the context of single-node databases;
35%
Flag icon
The simplest way of avoiding concurrency problems is to remove the concurrency entirely:
35%
Flag icon
that a single-threaded loop for executing transactions was feasible
35%
Flag icon
RAM became cheap enough that for many use cases it is now feasible to keep the entire active dataset in memory
35%
Flag icon
transactions can execute much faster
35%
Flag icon
However, its throughput is limited to that of a single CPU core.
35%
Flag icon
a database transaction needs to wait for input from a user, the database needs to support a potentially huge number of concurrent transactions,
35%
Flag icon
and so almost all OLTP applications keep transactions short by avoiding interactively waiting for a user within a transaction.
35%
Flag icon
systems with single-threaded serial transaction processing don’t allow interactive multi-statement transactions.
35%
Flag icon
the application must submit the entire transaction code to the database ahead of time, as a stored procedure.
35%
Flag icon
Provided that all data required by a transaction is in memory, the stored procedure can execute very fast, without waiting for any network or disk I/O.
35%
Flag icon
badly written stored procedure (e.g., using a lot of memory or CPU time) in a database can cause much more trouble than equivalent badly written code in an application server.
35%
Flag icon
transactions on a single thread
35%
Flag icon
they don’t need to wait for I/O and they avoid the overhead of other concurrency control mechanisms, they can achieve quite good throughput on a single thread.
35%
Flag icon
also uses stored procedures for ...
This highlight has been truncated due to consecutive passage length restrictions.
35%
Flag icon
order to scale to multiple CPU cores, and multiple nodes, you can potentially partition your data
35%
Flag icon
In this case, you can give each CPU core its own partition,
35%
Flag icon
for any transaction that needs to access multiple partitions, the database must coordinate the transaction across all the partitions that it touches.
35%
Flag icon
Since cross-partition transactions have additional coordination overhead, they are vastly slower than single-partition transactions.
35%
Flag icon
two-phase locking (2PL).
35%
Flag icon
But as soon as anyone wants to write (modify or delete) an object, exclusive access is required:
35%
Flag icon
If transaction A has read an object and transaction B wants to write to that object, B must wait until A commits or aborts before it can continue. (This ensures that B can’t
35%
Flag icon
If transaction A has written an object and transaction B wants to read that object, B must wait until A commits o...
This highlight has been truncated due to consecutive passage length restrictions.
35%
Flag icon
(Reading an old version of the object, like in Figure 7-4, is ...
This highlight has been truncated due to consecutive passage length restrictions.
35%
Flag icon
In 2PL, writers don’t just block other writers; they also block re...
This highlight has been truncated due to consecutive passage length restrictions.
35%
Flag icon
because 2PL provides serializability,
35%
Flag icon
The lock can either be in shared mode or in exclusive mode.
35%
Flag icon
Several transactions are allowed to hold the lock in shared mode simultaneously, but if another transaction already has an exclusive lock on the object, these transactions must wait.
35%
Flag icon
acquire the lock in exclusive mode.
35%
Flag icon
No other transaction may hold the lock at the same time (either in shared...
This highlight has been truncated due to consecutive passage length restrictions.
35%
Flag icon
object, it may upgrade its shared lock to an exclusive lock.
35%
Flag icon
hold the lock
Chena Lee
What if DB crashes and lock is never, released?
35%
Flag icon
deadlock.
35%
Flag icon
The database automatically detects deadlocks between transactions and aborts one of them so that the others can make progress.
35%
Flag icon
The big downside of two-phase locking,
35%
Flag icon
is performance:
35%
Flag icon
This is partly due to the overhead of acquiring and releasing all those locks, but more importantly due to reduced concurrency.
1 10 28