๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“š ์ „๊ณต ๊ณต๋ถ€/DB๊ธฐ์ดˆ

[DB] Transaction processing

Transaction Concepts

Concurrent Executions

Transaction Schedule

Serializability

Recoverability

 

Single-User vs Multiuser Systems

๊ต๋Œ€ ์ˆ˜ํ–‰ : interleaved concurrency

 

Transaction : an executing program that forms a logical unit of db processing

Begin transaction - end transaction;

includes DB access operations

read-only / read-write transaction

 

read-item(X) : ๋””์Šคํฌ๋ธ”๋ก ์ฃผ์†Œ์ฐพ๊ธฐ-๋ฒ„ํผ์— ๋ณต์‚ฌ-ํ”„๋กœ๊ทธ๋žจ ๋ณ€์ˆ˜๋กœ ๋ณต์‚ฌ

write-item(X) : ๋””์Šคํฌ ์ฃผ์†Œ์ฐพ๊ธฐ-๋ฒ„ํผ์— ๋ณต์‚ฌ-์ˆ˜์ •ํ•œ ํ”„๋กœ๊ทธ๋žจ ๋ณ€์ˆ˜๋ฅผ ๋‹ค์‹œ ๋ฒ„ํผ์— ๋ณต์‚ฌ-๋””์Šคํฌ์— ์ €์žฅ

read-set : ์ฝ์€๊ฑฐ ์ง‘ํ•ฉ {X, Y, …}

write-set : ์“ด๊ฑฐ ์ง‘ํ•ฉ

 

๐Ÿ’ก Why concurrency control is needed (๋ฌธ์ œ๋“ค)

  1. Lost update : ๊ฐ™์€ ๋ณ€์ˆ˜์— ๋Œ€ํ•ด ์—ฌ๋Ÿฌ๋ฒˆ writeํ•ด์„œ ๋ฎ์–ด์“ฐ๊ธฐ๋จ
  2. Dirty Read(Temporary update) : cascading rollback : ์ปค๋ฐ‹ํ•˜์ง€์•Š์€ ์ˆ˜์ •์‚ฌํ•ญ์„ ์ฝ์Œ
  3. Incorrect summary(Inconsistency) : ํ•ฉ๊ณ„๋ฅผ ๊ตฌํ•˜๋Š” ๋„์ค‘์— ๋‚ด๋ถ€๊ฐ’์ด ๋ณ€๊ฒฝ๋จ
  4. Unrepeatable read : ๋‘๊ฐœ์˜ read ์‚ฌ์ด์— ๋‹ค๋ฅธ T’๊ฐ€ ๊ฐ’์„ ๋ณ€๊ฒฝ์‹œ์ผœ์„œ ๋‘๋ฒˆ์˜ read ๊ฐ’์ด ๋‹ค๋ฆ„

 

๐Ÿ’ก Why Recovery is needed

  • committed : DB์— ์˜๊ตฌ๊ธฐ๋ก์‹œํ‚ด
  • aborted : ํ•ด๋‹น ํŠธ๋žœ์ ์…˜์ด ๋‹ค๋ฅธ T๋‚˜ DB์— ์˜ํ–ฅ์„ ๋ผ์น˜์ง€ ์•Š๊ฒŒ ํ•จ

if) ํŠธ๋žœ์ ์…˜ ์‹คํŒจ ์‹œ ๋ชจ๋‘ ์‹คํ–‰์ทจ์†Œ → all or nothing

 

 

Transaction states and additional operations

The system log

log(DBMS journal) : ๋ชจ๋“  ํŠธ๋žœ์ ์…˜ ์—ฐ์‚ฐ์„ ์ถ”์ ํ•˜๊ธฐ ์œ„ํ•ด

log records

  1. [start_transaction, T]
  2. [write_item, T, X, old_value, new_value]
  3. [read_item, T, X]
  4. [commit, T]
  5. [abort, T]

< Desirable Properties of Transactions : ํŠธ๋žœ์ ์…˜์ด ๋ฐ์ดํ„ฐ ๋ฌด๊ฒฐ์„ฑ์„ ๋ณด์žฅํ•˜๊ธฐ ์œ„ํ•ด ๊ฐ€์ ธ์•ผํ•  ํŠน์ง• >

ACID : ์›์ž์„ฑ, ์ผ๊ด€์„ฑ, ๊ณ ๋ฆฝ์„ฑ, ์ง€์†์„ฑ

  1. Atomicity : all or nothing
  2. Consistency preservation : transformations preserve DB consistency
  3. Isolation : ๋‹ค๋ฅธ๊ฑฐ์˜ ์˜ํ–ฅ์„ ๋ฐ›์œผ๋ฉด ์•ˆ๋จ, ๋™์‹œ์„ฑ ์ œ์–ด
  4. Durability / permanency : ํ•œ๋ฒˆ ์ปค๋ฐ‹๋˜๋ฉด ์˜๊ตฌ์ €์žฅ

Schedules (Histories) of Transactions

  • ์Šค์ผ€์ค„ S๋Š” ํŠธ๋žœ์ ์…˜์˜ ์ˆœ์„œ์ด๋‹ค

Conflicting Operations in Schedule : ์ถฉ๋Œ

  1. belong to different transactions
  2. access the same DB item
  3. one of the 2 operations is a write operation : ์“ฐ๊ธฐ ์—ฐ์‚ฐ์ด ์žˆ์„๋•Œ๋งŒ ์ถฉ๋Œ ๋ฐœ์ƒ

Characterizing schedules based on recoverability : ๋ณต๊ตฌ๊ฐ€๋Šฅ์„ฑ ๊ธฐ๋ฐ˜ ์Šค์ผ€์ค„ ํŠน์„ฑํ™”

  • Recoverable : durability (๋‚ด๊ตฌ์„ฑ)
  • Nonrecoverable : commt๋œ ํŠธ๋žœ์ ์…˜์ด ๋ณต๊ตฌ ์‹œ ์ทจ์†Œ๋˜์–ด์•ผํ• ๋•Œ

(T’๊ฐ€ ์“ด ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ์€ T๊ฐ€ ๋จผ์ € ์ปค๋ฐ‹๋˜๋ฉด ์•ˆ๋จ!)

Characterizing schedules based on Serializability : ์ง๋ ฌํ™”๊ฐ€๋Šฅ์„ฑ

  • ์ง๋ ฌํ™”๊ฐ€๋Šฅํ•œ ์Šค์ผ€์ค„ : ๋™์‹œ ์‹คํ–‰์‹œ ํ•ญ์ƒ ์˜ฌ๋ฐ”๋ฅธ ๊ฒƒ์œผ๋กœ ๊ฐ„์ฃผ๋จ
    • Serial schedules : if no interleaving is permitted → correct
    • Nonserial : if interleavign is allowed → correct or wrong

์ธํ„ฐ๋ฆฌ๋น™ ์‹œ์—๋„ ๊ฒฐ๊ณผ๊ฐ€ ๊ฐ™์„ ๋•Œ

(๋ณ‘๋ ฌ์‹œํ–‰ ๊ฒฐ๊ณผ๊ฐ€ ๋”ฐ๋กœ T1→T2 ํ˜น์€ T2→T1 ์ง๋ ฌ์‹œํ–‰ํ–ˆ์„๋–„์˜ ๊ฒฐ๊ณผ์™€ ๊ฐ™์„๋•Œ)

์ด ์Šค์ผ€์ค„์ด ์ง๋ ฌํ™”๊ฐ€๋Šฅํ•˜๋‹ค = ์ด ์Šค์ผ€์ค„์ด correct ํ•˜๋‹ค

Equivalence of schedules

result equivalence : ์–ด๋–ค ๊ฐ’์ด ๋“ค์–ด์™€๋„ ๊ทธ ๊ฒฐ๊ณผ๊ฐ€ ๊ฐ™์„๋•Œ ๋‘ ์Šค์ผ€์ค„์€ ๊ฒฐ๊ณผ ๋™๋“ฑ

๋™๋“ฑ์„ฑ : ํŠธ๋žœ์ ์…˜ ์ž‘์—…์œ ํ˜•์— ๋”ฐ๋ฅธ ๊ฐ€์ • ์—†์Œ. ๊ฐ™์€ ์ˆœ์„œ๋กœ ์ ์šฉ๋˜์–ด์•ผํ•จ

  • Conflict Equivalence : ์ถฉ๋Œ ๋™๋“ฑ์„ฑ
  • View Equivalence : ๋ทฐ ๋™๋“ฑ์„ฑ

Conflict Equivalence : ์ถฉ๋Œ ๋™๋“ฑ์„ฑ

์ถฉ๋Œํ•˜๋Š” ๋‘ ์ž‘์—…์˜ ์ˆœ์„œ๊ฐ€ ๋‘ ์Šค์ผ€์ค„์—์„œ ๋™์ผํ•จ

 

Conflict Serializability : ์ถฉ๋Œ ์ง๋ ฌํ™”๊ฐ€๋Šฅ์„ฑ

: ์–ด๋–ค ์Šค์ผ€์ค„ S๊ฐ€ serial ์Šค์ผ€์ค„ S’์™€ conflict equivalentํ•˜๋ฉด S๋Š” conflict serializableํ•˜๋‹ค

Testing for conflict serializability : Precedence graph (์šฐ์„ ์ˆœ์œ„ ๊ทธ๋ž˜ํ”„)

Testing for Conflict Serializability

  • no cycles
  • finding a cycle from a graph is harder : ์‚ฌ์ดํด ์ฐพ๊ธฐ ์–ด๋ ค์›€
  • many possible linear orders : ์„ ํ˜•์ˆœ์„œ๊ฐ€ ๋„ˆ๋ฌด ๋งŽ์Œ
  • ๊ทธ๋ž˜์„œ ๋Œ€๋ถ€๋ถ„์˜ ์ƒ์šฉ DBMS๋Š” ๋ชจ๋“  ์ผ์ •์˜ ์ง๋ ฌํ™”๋ฅผ ๋ณด์žฅํ•˜๋Š” ํ”„๋กœํ† ์ฝœ์„ ์ง€ํ‚ค๋„๋ก ์„ค๊ณ„

→ Concurrency Control protocol

  1. Locking
  2. TimeStamps
  3. Multiversion CC protocols
  4. Optimistic protocols

View Equivalence : ๋ทฐ ๋™๋“ฑ์„ฑ → ์ถฉ๋Œ ๋™๋“ฑ์„ฑ๋ณด๋‹ค ๋” general

  • read ์—ฐ์‚ฐ๋งŒ ๊ณ ๋ คํ•จ
  • ๊ฐ™์€ ๊ฐ’์„ readํ•˜๋ฉด ๋™๋“ฑํ•˜๋‹ค๊ณ  ํ•œ๋‹ค
  1. S์™€ S’์— ๋™์ผํ•œ ๊ฑฐ๋ž˜์ง‘ํ•ฉ์ด ์ฐธ์—ฌ
  2. ์–ด๋–ค ์ฝ๊ธฐ์—ฐ์‚ฐ๋„ ์„œ๋กœ ๋™์ผํ•œ ๊ฐ’์„ ์ฝ์Œ
  3. ํ•œ ๊ฐ’์— ๋Œ€ํ•œ ๋งˆ์ง€๋ง‰ ์“ฐ๊ธฐ์—ฐ์‚ฐ์ด ๋™์ผํ•ด์•ผํ•จ

View Equivalance and View Serializability

the read operations can see the same ciew in both schedules

DB state should be the same at the end of both schedules

๋ทฐ ๋™๋“ฑ์„ฑ์ด ์ถฉ๋Œ ๋™๋“ฑ์„ฑ๋ณด๋‹ค ๋œ ์ œํ•œ์ ์ž„.

→ ํ•œ ์Šค์ผ€์ค„ S๊ฐ€ ์‹œ๋ฆฌ์–ผ ์Šค์ผ€์ค„ S’์™€ ๋ทฐ ๋™๋“ฑํ•˜๋‹ค๋ฉด View serializable ์Šค์ผ€์ค„์ด๋‹ค.

์ถฉ๋Œ์—†๋Š” ์ž‘์—…์€ ์žฌ์ •๋ ฌ ๊ฐ€๋Šฅ

Constrained Write Assumption : ์ œํ•œ๋œ ์“ฐ๊ธฐ

View ์ง๋ ฌ๊ฐ€๋Šฅ์„ฑ vs ์ถฉ๋Œ ์ง๋ ฌ๊ฐ€๋Šฅ์„ฑ

์ œํ•œ๋œ ์“ฐ๊ธฐ → view = conflict

์ œํ•œ๋˜์ง€ ์•Š์€ ์“ฐ๊ธฐ(blind write ์กด์žฌ) → view ≥ conflict

Testing for View serializability → NP-complete problem

Transaction Support in sql

  • a transaction begins implicitly : no Begin_Transaction statement (์•”๋ฌต์  ์‹คํ–‰)
  • ends by Commit / Rollback
  • ๋ชจ๋“  ํŠธ๋žœ์ ์…˜์€
    • SET TRANSACTION
    • access mode, diagnostic area size, the isolation level

SET TRRANSACTION statemetn in sql

  • access mode : READ ONLY or READ WRITE
  • diagnostic area size : diagnostic size n
  • Isolation level

level of consistency

  1. Read uncommitted
  2. Read committed
  3. Repeatable read
  4. Serializable