UNIT 4-fdb
UNIT 4-fdb
UNIT 4-fdb
Concurrency control
ACID properties
• ACID properties in DBMS are necessary for
maintaining data consistency, integrity, and reliability
while performing transactions in the database.
• A transaction is a single logical unit of work that
accesses and possibly modifies the contents of a
database. Transactions access data using read-and-
write operations. To maintain consistency in a
database, before and after the transaction, certain
properties are followed. These are
called ACID properties.
Atomicity:
• Either the entire transaction takes place at once or
doesn’t happen at all.
• There is no midway i.e. transactions do not occur
partially. Each transaction is considered as one unit and
either runs to completion or is not executed at all.
• It involves the following two operations.
— Abort : If a transaction aborts, changes made to the
database are not visible.
— Commit : If a transaction commits, changes made are
visible.
• Atomicity is also known as the ‘All or nothing rule’.
Example
• Consider the following transaction T consisting
of T1 and T2 : Transfer of 100 from account X to
account Y .
If the transaction fails after
completion of T1 but before
completion of T2 .( say,
after write(X) but before write(Y) ),
then the amount has been
deducted from X but not added
to Y . This results in an inconsistent
database state. Therefore, the
transaction must be executed in its
entirety in order to ensure the
correctness of the database state.
Consistency:
• This means that integrity constraints must be
maintained so that the database is consistent before and
after the transaction. It refers to the correctness of a
database. Referring to the example above,
• The total amount before and after the transaction must
be maintained.
Total before T occurs = 500 + 200 = 700 .
Total after T occurs = 400 + 300 = 700 .
• Therefore, the database is consistent . Inconsistency
occurs in case T1 completes but T2 fails. As a result, T is
incomplete.
Isolation:
• This property ensures that multiple transactions
can occur concurrently without leading to the
inconsistency of the database state.
• Transactions occur independently without
interference.
• Changes occurring in a particular transaction
will not be visible to any other transaction until
that particular change in that transaction is
written to memory or has been committed.
Example
• Let X = 500, Y = 500.
Consider two transactions T and T”.
Suppose T has been executed till Read
(Y) and then T’’ starts. As a result,
interleaving of operations takes place
due to which T’’ reads the correct value
of X but the incorrect value of Y and
sum computed by
T’’: (X+Y = 50, 000+500=50, 500)
is thus not consistent with the sum at
end of the transaction:
T: (X+Y = 50, 000 + 450 = 50, 450) .
This results in database inconsistency,
due to a loss of 50 units.
Durability:
• This property ensures that once the
transaction has completed execution, the
updates and modifications to the database are
stored in and written to disk and they persist
even if a system failure occurs.
• These updates now become permanent and
are stored in non-volatile memory. The effects
of the transaction, thus, are never lost.
Concurrency
• First we will study isolation of transactions, ensured
by the concurrency control subsystem.
Time
S1
T1: A+=100, B-=100
T3: A=1.06*A, B=1.06*B
• Recall S2:
S2 T1: A+=100, B-=100
T3: A=1.06*A, B=1.06*B
• Why is S2 serializable?
Schedules as reads and writes
• The expression A =1.06*A in the previous schedule
means
– Read A from disk
– Set A equal to 1.06*A
– Write A to disk
• Only the read and write to disk matter to the DBMS.
– We use the notation R(A), W(A)
• So henceforth we write schedules in terms of reads and
writes to the DBMS
• This will be less intuitive but we will be able to capture
the DBMS activity better
Proving Serializability, ctd*
S2 T1: A+=100, B-=100
T3: A=1.06*A, B=1.06*B
• Why is S2 serializable?
• Why is S5 serializable?
S5 T4: R(C),W(C), R(D),
T5: R(D), R(E),W(E)
Non-conflicting Actions
• S2 and S5 have a special structure that makes it
possible to prove that they are serializable.
Let’s formalize this structure.
• Definition: Two actions are non-conflicting if
they are in different transactions and either
they access different data items or both are
reads.
– The green actions in S2 and S5 actions are
nonconflicting
• Observation: If non-conflicting actions are
commuted then the new schedule gives the
same result in the DB as the old one
Conflict serializability
• Definition: Two schedules are conflict equivalent if
– One can be transformed into the other by commuting
non-conflicting actions
• Theorem: Conflict equivalent schedules produce
the same result in the database.
– Proof: Use the preceding observation
• Definition: A schedule is conflict serializable if it is
conflict equivalent to a serializable schedule
• Theorem: every conflict serializable schedule is
serializable
– Proof: By the previous theorem, a conflict serializable
schedule produces the same result as a serializable
schedule.
Precedence graphs
• So far the only way we have to prove serializability is to
verify conflict serializability, and that is laborious. But
there is an easier way.
• Precedence graph: One node per transaction. Edge
from Ti to Tj if an action in Ti occurs before an action in
Tj and they conflict.
– Actions conflict if they act on the same data item and one
of them is a write.
• Theorem: A schedule is conflict serializable if and only
if its precedence graph is acyclic (not cyclic).
• Draw the precedence graph for the following
schedules to see if they are conflict serializable and
therefore serializable.
LO7.2: Which of these is serializable?*
S6 T1: R(A),W(A), R(B),W(B)
T2: R(A),W(A), R(B),W(B)
S7
T1: R(A), W(A)
T2: R(A), W(A), R(B)
Conflict
Serializable
Serial
-- ok ok ok