2๏ธโฃ Serializability
Correct Execution
Two widely accepted criteria
- Conflict serializable
- View serializable
→ ๋ ๊ฐ ์ค ํ๋๋ง์ด๋ผ๋ ๋ง์กฑํ๋ฉด correct execution
(* serial execution of transaction is always correct)
Nonserializable Execution
๋น์์ฐจ์ ์ธ ์ฐ์ฐ์ ๋ฌธ์ ์
1. dirty read
: Rollback์ผ๋ก ์ธํด A๋ ์ฒ์ ์ํ๋ก → T2์ A๋ ์๋ชป๋ ๊ฐ์ ์ฝ๊ณ ์๋ ๊ฒ์
2. lost update
: Effect (update) of T2 is lost
์ต์ข ์ ์ผ๋ก๋ T1์์ A+50ํ ๊ฐ์ด write๋จ (T2์ฐ์ฐ์ด ์ฌ๋ผ์ง → lost update)
3. unrepeatable read
: ํ transaction์์ updateํ ๋ด์ฉ์ด ์์ผ๋ฉด readํ ๋ฐ์ดํฐ๊ฐ ๊ฐ์์ผ ํจ. ๊ทผ๋ฐ T2์ ์ฐ์ฐ์ผ๋ก ์ธํด T1์์ readํ ๋ฐ์ดํฐ๊ฐ ๋ณํจ
⇒ “Serializable”ํ๊ฒ scheduleํ๋ฉด ํญ์ Correct(Consistent)ํ ๊ฒฐ๊ณผ
Schedules (Histories)
: A sequence of instructions that specify the chronological order in which instructions of concurrent transactions are executed
Schedule 1 && Schedule 2
: ์ง๋ ฌ ์ค์ผ์ค
Schedule : T1 → T2 // T2 → T1
serial schedule ⇒ consistentํ ๊ฒฐ๊ณผ
ํธ๋์ญ์ ์ , ํ A+B์ ๊ฐ ๋ณํ x
Schedule 3
: not a serial schedule, but it is equivalent to Schedule 1
ํธ๋์ญ์ ์ , ํ A+B์ ๊ฐ ๋ณํ x
Schedule 4
: ์ฌ๋ฐ๋ฅธ ์ค์ผ์ค X
ํธ๋์ญ์ ์ํ ํ, A+B ๊ฐ ๋ณํ O
Serializability
Serial Schedule์ ๊ฒฐ๊ณผ์ ๋์ผ → Serializable Schedule
(Transaction ์ n๊ฐ์ผ ๋ Serializable schedule์ n!์ ๊ฒฐ๊ณผ ์ค ์ ์ด๋ ํ๋์ ๊ฒฐ๊ณผ ๋์ผํด์ผ)
๋์ผํจ์ ํ๋จํ๋ ๊ธฐ์ค?
- Conflict Serializability
- View Serializability
Conflicting Instructions
์ถฉ๋์ฐ์ฐ
- Instructions and $I_j$ of transactions $T_i$ and $T_j$ respectively, conflict if and only if there exists some item Q accessed by both $I_i$ and $I_j$ , and at least one of these instructions is write(Q)
- ๋์ผํ ๋ฐ์ดํฐ์ ๋ํ ๋ ๊ฐ ์ฐ์ฐ ์ค์์ ์ต์ํ ํ ๊ฐ์ ์ฐ์ฐ์ด write์ด๋ฉด ๋ ๊ฐ์ ์ฐ์ฐ์ ์ถฉ๋
- ์ถฉ๋ ์ฐ์ฐ์ ๊ณ ๋ คํ ๋, ๋์ผํ ๋ฐ์ดํฐ์ ๋ํ ์ฐ์ฐ์ ๊ณ ๋ ค
Conflict Serializable Schedule
- If a schedule S can be transformed into a schedule S’ by a series of swaps of non-conflicting instructions, we say that S and S’ are conflict equivalent
- We say that a schedule S is conflict serializable if it is conflict equivalent to a serial schedule
∴ non-conflict ์ฐ์ฐ ์์๋ฅผ ๋ฐ๊พธ์ด์ serial schedule๊ณผ ๊ฒฐ๊ณผ ๋์ผํ๋ฉด Conflict Serializable Schedule (consist ๋ณด์ฅ)
T1 | T2 |
r(A) | |
r(B) |
T1 | T2 |
r(A) | |
r(A) |
๋ ๊ฒฝ์ฐ ๋ค non conflict ์ฐ์ฐ -> ์์๋ฅผ ๋ฐ๊ฟ ์ ์์
Conflict Serializability Example 1
- ์ค์ผ์ค 5์ T2์ w(A)๋ T1์ r(B), w(B)๋ ๋น์ถฉ๋ → ์์ ๊ตํ ๊ฐ๋ฅ
- ์ค์ผ์ค 5์ T2์ r(A)๋ T1์ r(B), w(B)๋ ๋น์ถฉ๋ → ์์ ๊ตํ ๊ฐ๋ฅ
→ ๊ฒฐ๊ณผ์ ์ผ๋ก ์ค์ผ์ค 6(serial schedule)๊ณผ ๊ฐ์ ์ค์ผ์ค์ด ๋์ค๊ฒ ๋จ.
∴ ์ค์ผ์ค 5๋ conflict serializable schedule
Conflict Serializability Example 2
- r(Q), w(Q)๋ ์ถฉ๋ → ์์ ๊ตํ ๋ถ๊ฐ๋ฅ
- <T3, T4> ๋๋ <T4, T3>์ serial schedule๋ก ๊ตํ ๋ถ๊ฐ๋ฅ
⇒ schedule 7 is not conflict serializable
View Serializability Definition
๋ทฐ ์ง๋ ฌ ๊ฐ๋ฅ ์ค์ผ์ค์ ์ ์ (๋ค์ 3๊ฐ๋ฅผ ๋ชจ๋ ๋ง์กฑํด์ผ.)
- S๊ฐ ์ฝ์ Q์ initial value๊ณผ S’์ด ์ฝ์ Q์ initial value ์ด ๊ฐ์์ผํ๋ค.
- ๋ง์ฝ S์ T1์ด T2๋ก๋ถํฐ ์์ฑ๋(write) Q๋ฅผ read ํ๋ค๋ฉด, S’ ์์๋ T1์ T2๋ก๋ถํฐ ์์ฑ๋ Q๊ฐ์ ์ฝ์ด์ผ ํจ
- ์ฆ, S์์ Ti ๊ฐ ๋จผ์ write(Q) , Tj ๊ฐ ํ์ read(Q) ๋ฅผ ํ๋ค๋ฉด S’ ์์๋ ์ด์์๋ฅผ ์ง์ผ์ผ ํ๋ค.
- ์ด๋ ํ ์ค์ผ์ฅด์ด final write(Q)๋ฅผ ํ๋ค๋ฉด (๋์คํฌ์ ์ ์ฅ) ๋ค๋ฅธ ์ค์ผ์ฅด ๋ํ final write(Q) ๋ฅผ ํด์ผํจ
- View equivalence is also based purely on reads and writes alone
View Serializability Example
- S’์ <T5, T6, T7>์ด๋ผ๊ณ ๊ฐ์
- View Serializableํ๊ฐ?
- ์ด๊ธฐ๊ฐ์ ๋ชจ๋ T5์์ ์ฝ์ → O
- Ti ๋ก๋ถํฐ ์์ฑํ Q๋ฅผ Tj ๊ฐ ์ฝ๋ ์ฐ์ฐ์ด ์์ → O
- final write๋ ๋ ๋ค T7์์ ํจ → O
- Conflict Serializableํ๊ฐ?
- serialํ๊ฒ ๋ฐ๊พธ๋ ค๋ฉด T5์ w(Q), T6์ w(Q)์ ์์๋ฅผ ๋ฐ๊ฟ์ผ.
- ์ด ๋ ๊ฐ๋ฅผ ๊ตํํ๋ ๊ฒ์ ์ถฉ๋์ฐ์ฐ์ด๋ฏ๋ก ์ถฉ๋ ์ง๋ ฌ๊ฐ๋ฅ ์ค์ผ์ค์ ์๋
⇒ Schedule 8 is view-serializable but not conflict serializable.
์ด์ ๊ฐ์ด conflict serializable ํ์ง ์์ง๋ง view serializable ํ ์ค์ผ์ค์ ๋ชจ๋ blind writes ๋ฅผ ๊ฐ์ง๊ณ ์์.
(* blind write : ์ฝ๋ ์ฐ์ฐ์ด ์ด์ ์ ์คํ๋์ง ์์ ์ฑ ๋ฐ์ดํฐ๋ฅผ ์ด๋ค.)
Conflict Serializability vs. View Serializability
Other Notions of Serializability
- not conflict serializable
- not view serializable → final write ๋์ผ X
- but the same as <T1, T2>
- Commutable operators only !!
๋ง์ , ๋บ์ ์ฐ์ฐ์ ์ํธ ๊ตํ์ด ๋๊ธฐ ๋๋ฌธ์ ์ง๋ ฌ ์ค์ผ์ค๊ณผ ๋์ผํ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์
'๐ฉ๐ปโ๐ป CS > Database' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[DB/2-1. Lock-based Protocols] (1) | 2024.03.30 |
---|---|
[DB/1-4. Recoverability(ํ๋ณต ๊ฐ๋ฅ)] (0) | 2024.03.27 |
[DB/1-3.ย How to Test Serializability] (0) | 2024.03.27 |
[DB/1-1. Transaction(ํธ๋์ญ์ )] (0) | 2024.03.18 |