ACID stands for Atomicity, Consistency, Isolation, and Durability. These properties ensure reliable processing of database transactions:
Atomicity: Transactions are all-or-nothing. Either all operations are completed, or none are.
Consistency: Transactions must lead the database from one valid state to another, maintaining data integrity.
Isolation: Transactions do not interfere with each other, even if they run concurrently.
Durability: Once a transaction is committed, its changes are permanent, even in the event of a system failure.
These properties are crucial for maintaining data integrity and reliability in databases.
2. Problem with Transaction Schedule 1
Schedule:
code
T1:
read_item(X);
X := X - N;
T2:
read_item(X);
X := X + N;
T1:
write_item(X);
read_item(Y);
T2:
write_item(X);
T1:
Y := Y + N;
write_item(Y);
Problem: Lost Update Problem
Explanation: Both transactions read and modify X without proper isolation mechanisms. If T1 and T2 execute concurrently, one transaction may overwrite changes made by the other, resulting in lost updates. The final value of X may not reflect both transactions' intended updates.
3. Problem with Transaction Schedule 2
Schedule:
code
T1:
read_item(X);
X := X - N;
write_item(X);
T2:
read_item(X);
X := X + M;
write_item(X);
T1:
read_item(Y);
rollback;
Problem: Inconsistent Read or Dirty Read
Explanation: T2 reads X after T1 has modified it but before T1 has committed. If T1 rolls back, T2 will have read an inconsistent or "dirty" value for X, which may lead to incorrect results since T2 assumes its operations are based on a valid state.
4. Problem with Transaction Schedule 3
Schedule:
code
T3:
sum := 0;
read_item(A);
sum := sum + A;
T1:
read_item(X);
X := X - N;
write_item(X);
T3:
read_item(X);
sum := sum + X;
read_item(Y);
sum := sum + Y;
T1:
read_item(Y);
Y := Y + N;
write_item(Y);
Problem: Non-Repeatable Read
Explanation: T1 modifies X and Y between reads in T3. If T3 reads X and later T1 changes it before T3 completes, the sum calculated in T3 may become inaccurate. The non-repeatable read leads to inconsistent results in the computation as T3 relies on the values that could be changed by T1.