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

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

[DB] ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ณต๊ตฌ

728x90

Recovery Techniques

 

Recovery Concept

  • recent consistent state : no errors in db, no inconsistencies in db
  • systme log
  1. Catastrophic failure (์น˜๋ช…์  ์žฅ์• ) → backed up, redoing
  2. Noncatastrophic failure (๋น„์žฌํ•ด์  ์žฅ์• ) → undoing, redo, deferred update&immediate update

Caching(Buffering) of disk blocks

  • ํšจ์œจ์„ฑ์„ ์œ„ํ•ด์„œ ์บ์‹œ ์‚ฌ์šฉ
  • DBMS cache
  • < disk page ์ •๋ณด, ๋ฒ„ํผ ์œ„์น˜, … >

Buffer replacement : ๋ฒ„ํผ ๊ต์ฒด( flush )

  • dirty bit : ๋ฒ„ํผ๊ฐ€ ์ˆ˜์ •๋˜์—ˆ๋Š”์ง€ ์—ฌ๋ถ€
  • pin-unpin bit : ๋””์Šคํฌ์— ์•„์ง ๋‹ค์‹œ์“ธ์ˆ˜์—†์„๋•Œ, ์บ์‹œ์˜ ํŽ˜์ด์ง€ ๊ณ ์ •

Two main strategies for flushing a modified buffer back to disk (์ˆ˜์ • ๋ฒ„ํผ๋ฅผ ๋””์Šคํฌ์— ๋‹ค์‹œ ๋˜๋Œ๋ ค๋†“์„๋•Œ)

  1. in-place updating : ์›๋ž˜ ์žˆ๋˜๊ณณ์œผ๋กœ
  2. shadowing : ์ƒˆ๋กœ์šด ๋ธ”๋Ÿญ์œผ๋กœ
    • BFIM : before image
    • AFIM : after image

Steal : ์ปค๋ฐ‹ ์ „์—๋„ ๋””์Šคํฌ๋กœ ์ˆ˜์ • ์บ์‹œ๋ฅผ ๋‚ด๋ณด๋‚ผ ์ˆ˜ ์žˆ์Œ, ์ค‘๊ฐ„์— ๋ฒ„ํผ ๊ณต๊ฐ„ ํ™•๋ณด๊ฐ€ ๊ฐ€๋Šฅํ•˜์—ฌ ๋ฉ”๋ชจ๋ฆฌ ํ™œ์šฉ์ด ์œ ์—ฐํ•จ

No-steal : ์ปค๋ฐ‹ ์ „์— ์บ์‹œ๋ฅผ ๋‚ด๋ณด๋‚ด๋Š” ๊ฒƒ์„ ๋น„ํ—ˆ์šฉ.

Force : ์ปค๋ฐ‹ ์‹œ DB์— ๊ฐ•์ œ๋ฐ˜์˜

No-force : ๊ฐ•์ œ X. ์ถ”๊ฐ€์ ์ธ saving ๊ฐ€๋Šฅ, ์ž์ฃผ ์—…๋ฐ์ดํŠธ๋˜๋Š” ๋‚ด์šฉ์˜ ๊ฒฝ์šฐ ์—…๋Žƒํ• ๋•Œ๋งˆ๋‹ค ๋””์Šคํฌ์— ์ถœ๋ ฅ ํ›„ ๋‹ค์‹œ ๊ฐ€์ ธ์˜ฌ ํ•„์š”๊ฐ€ ์—†๋‹ค.

Deffered update = no steal, no force

Write-ahead logging

  • When in-place updating is used, ๋ณต๊ตฌ๋ฅผ ์œ„ํ•œ log ์‚ฌ์šฉ ํ•„์ˆ˜

Log entry

  • REDO type log entry : AFIM is needed to redo (์žฌ์ž‘์—…)
  • UNDO type log entry : BFIM is needed to undo (์•„์˜ˆ ์—†๋˜์ผ๋กœ ์ž‘์—…)

Log is simply a sequential (append-only) disk file

  • last log buffer์—์„œ log record๋กœ
  • write-ahead logging approach

๋ฐ์ดํ„ฐ๋ธ”๋Ÿญ์ด ๋ฉ”์ธ ๋ฉ”๋ชจ๋ฆฌ ๋ฒ„ํผ์—์„œ ๋””์Šคํฌ๋กœ ๋‹ค์‹œ ์“ธ ์ˆ˜ ์žˆ๊ธฐ ์ „์— ๋””์Šคํฌ์— ๊ธฐ๋ก๋˜์–ด์•ผํ•จ

Write ahead logging(WAL) protocol

  1. log ์—”ํŠธ๋ฆฌ๊ฐ€ ๋ชจ๋‘ ๋””์Šคํฌ์— ์“ฐ์ผ๋•Œ๊นŒ์ง€ ๋ฎ์–ด์“ฐ๊ธฐ ๋ถˆ๊ฐ€๋Šฅ
  2. ์ปค๋ฐ‹ ์—ฐ์‚ฐ์„ ๋ชจ๋“  log ๊ธฐ๋ก ์ „๊นŒ์ง€๋Š” ์™„๋ฃŒ๋˜์ง€ ์•Š์Œ (log ๋ง๊ณ  ๊ทธ๋ƒฅ data๋Š” no-force์ผ๋•Œ๋Š” ๊ธฐ๋ก ์•ˆํ•ด๋„ ๋จ)

์–ด๋–ค ์‹œ์ ์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋‚˜๋„ ๋ณต๊ตฌ ๊ฐ€๋Šฅํ•จ

 

Transaction Rollback and Cascading Rollback : ๊ณ„๋‹จ์‹ ๋กค๋ฐฑ

์‹ค์ œ๋กœ๋Š” ๊ณ„๋‹จ์‹ ๋กค๋ฐฑ ์‚ฌ์šฉใ„ดใ„ด

read๋Š” ๋กœ๊ทธ์— ๊ธฐ๋ก์•ˆํ•ด๋„ ๋จ

 

no undo/redo recovery based on deferred update : ์ง€์—ฐ ์—…๋ฐ์ดํŠธ

  • ๋ถ€๋ถ„์ปค๋ฐ‹ ๋ ๋•Œ๊นŒ์ง€ ์ง€์—ฐ๋จ.
  • no force, no steal
  • no old value → undo ํ•„์š”์—†์–ด์„œ
  • log record : [operation, trans-id, data, new value]

A typical deferred update protocol as follows

  1. ์ปค๋ฐ‹์ง€์ ๊นŒ์ง€ ๋””์Šคํฌ์˜ DB ๋ณ€๊ฒฝ ๋ถˆ๊ฐ€๋Šฅ.
    1. ์ปค๋ฐ‹ํ•  ๋•Œ ๊นŒ์ง€ ๋ชจ๋“  ๋ฒ„ํผ๋ฅผ ๊ณ ์ •ํ•ด๋†”์•ผํ•˜ใ…๋ฏ€๋กœ(๋„๋‚œ๋ฐฉ์ง€ ์ •์ฑ…)
  2. ๋ชจ๋“  Redo ์œ ํ˜• ๋กœ๊ทธํ•ญ๋ชฉ์ด ๋กœ๊ทธ์— ๊ธฐ๋ก๋˜๊ณ  ๋กœ๊ทธ ๋ฒ„ํผ๊ฐ€ ๋””์Šคํฌ์— ๊ฐ•์ œ๊ธฐ๋ก๋ ๋•Œ๊นŒ์ง€ ์ปค๋ฐ‹์ง€์ ์— ๋„์ฐฉX.

Recovery from Failure

์ปค๋ฐ‹ ํ›„ ์—๋Ÿฌ : Redo

์ปค๋ฐ‹ ์ „ ์—๋Ÿฌ : no action (just restart)

 

Immediated update : force, steal : ์ฆ‰์‹œ ์—…๋ฐ์ดํŠธ

uncommitted update

์ปค๋ฐ‹ ์ „ ์ƒํƒœ๋„ ๋ณต๊ตฌ ํ•„์š” ⇒ old value, new Value

Recovery from Failure

์ปค๋ฐ‹ ํ›„ ์—๋Ÿฌ : Redo

์ปค๋ฐ‹ ์ „ ์—๋Ÿฌ : Undo (์‹คํ–‰์ทจ์†Œ)

 

Checkpoint : ๋ณต๊ตฌ๊ฐ€ ํ•„์š”์—†๋Š” ์ง€์ 

  • ๋กœ๊ทธ ๊ธฐ๋ก, ๋ฐ์ดํ„ฐ ๊ธฐ๋ก ํ›„ checkpoint

Taking a checkpoint consists of the following actinos :

  1. ์ž ์‹œ ์ค‘๋‹จ
  2. ๋ชจ๋“  ๋‚ด์šฉ์„ ๋””์Šคํฌ๋กœ force write
  3. ์ฒดํฌํฌ์ธํŠธ ๊ธฐ๋ก
  4. ์žฌ์‹œ๋™

Shadow paging

page : ๊ณ ์ •๊ธธ์ด ๋””์Šคํฌ ๋ธ”๋Ÿญ

DB partitioned into pages

current page table / shadow page table

shadow paging scheme : to update page i,

  1. read i
  2. update i
  3. write i to newly allocated page space
  4. change current page table

shadow page table is never changed over the duration of the transaction

if T is successful, current page table becomes the shadow page table

if T is failed, discard the current page table, ์„€๋„์šฐ ํ…Œ์ด๋ธ”์ด current๊ฐ€ ๋จ

need no log

need no undo

 

Shadow paging ์žฅ๋‹จ์ 

์žฅ์  : log based์— ๋น„ํ•ด์„œ ์˜ค๋ฒ„ํ—ค๋“œ๊ฐ€ ์—†๊ณ , ๋ณต๊ตฌ๊ฐ€ ๋น ๋ฅด๊ณ , no undo/redo

๋‹จ์  : ๋ฐ์ดํ„ฐ ์กฐ๊ฐํ™”, old page๋ฅผ ๋ณ„๋„๋กœ ๋ชจ์Œ

 

Recovery in Multidatabase systems

  • multi DB transaction may require access to multiple db
  • ์›์ž์„ฑ์„ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•ด, two level recovery mechanism์ด ํ•„์š”ํ•จ
    1. global recovery manager (coordinator)
    2. local recovery managers

coordinator usually follows a protocol, Two-phase commit protocol. (2๋‹จ๊ณ„ ์ปค๋ฐ‹๊ทœ์•ฝ)

2PLP-CC, 2PLP-R

 

2PCP

atomicity : T commits or aborts at all sites

participant : a site at which T has executed

 

assume (์ถ”์ •)

T is initiated at S(i) → TC(i) at S(i) is a transaction coordinator

( TC = transaction coordinator )

728x90