๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป CS/Database

[DB/1-2.Serializability(์ง๋ ฌ์„ฑ)]

by kekeyo 2024. 3. 24.
728x90

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ํ•œ๊ฐ€?
    1. ์ดˆ๊ธฐ๊ฐ’์„ ๋ชจ๋‘ T5์—์„œ ์ฝ์Œ → O
    2. Ti ๋กœ๋ถ€ํ„ฐ ์ƒ์„ฑํ•œ Q๋ฅผ Tj ๊ฐ€ ์ฝ๋Š” ์—ฐ์‚ฐ์ด ์—†์Œ → O
    3. final write๋Š” ๋‘˜ ๋‹ค T7์—์„œ ํ•จ → O
    ⇒ S’ <T5, T6, T7>์€ View Serializable Schedule์ด๋‹ค.
  • 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 !!

๋ง์…ˆ, ๋บ„์…ˆ ์—ฐ์‚ฐ์€ ์ƒํ˜ธ ๊ตํ™˜์ด ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์ง๋ ฌ ์Šค์ผ€์ค„๊ณผ ๋™์ผํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ž„

728x90