Transaction : Local unit of DB processing

Transaction processing systems : systems with large DB and hundreds of concurrent users

 

1. Introduction to Transaction Processing

Single-user DBMS Multi-user DBMS
유저 한명만 사용가능
ex) home computer
 여러 사람들이 사용가능
Transaction을 통해 충돌 해결 및 동시 처리 기능 제공

Interleaved processing Parallel processing
Singularization & Serializable
Equivalent 결과를 가짐
실제로 동시에 처리

 

Transaction

DB 처리의 logical unit임

Transaction statement의 시작과 끝이 존재함

Read-only transaction과 Read-write transaction이 존재함

 

DB items

DB item은 granularity라는 데이터 크기를 가짐

Record, Disk block, Attribute value of record 등의 단위가 가능함

Transcation은 이런 item granularity에 관계 없이 처리가 진행됨

 

Read/Write Operation

read_item(X) disk block address를 찾음
memory buffer로 복사해옴
write_item(X) disk block address를 찾음
memory buffer로 복사해옴
업데이트된 내용을 다시 disk에 반영

 

DBMS buffer

Disk보다 빠르기 때문에 사용함

LRU 등의 cache 업데이트 전략을 사용함

 

2. Concurrency Control

여러 사용자가 DB를 동시에 사용하면서, interleaved하게 DB의 item을 접근할 경우 문제가 발생할 수 있음

 

The Lost Update problem

Case1. Overwritten

Case2. Read wrong data

Case3. 다른 곳에서 업데이트된 값을 사용(원래 값을 원했음)

Unrepeatable Read problem도 같은 맥락임.

Read를 했는데 값이 다른 경우(다른 transaction에서 write하고 반영했기 때문)

 

3. Recovery

Transaction이 fail되는 경우 복구 과정이 필요함

System log로 모든 transaction 과정과 시간을 기록해두고, recovery가 필요한 경우에 system log를 보고 복구를 진행함

빠른 복구를 위해서 충분한 log를 가지고 있어야 함

 

Transaction ans System

  • Begin Transaction
  • READ or WRITE
  • End Transaction
  • Commit Transaction
  • Rollback(or Abort)

 

4. System Log

Transaction operation을 저장해둠

Sequential, append-only file

Failure에 영향을 받지 않음

Log buffer가 존재함(가득차면 디스크 공간 사용)

Log file은 주기적으로 백업됨(디스크 사망 방지)

Undo & Redo로 복구를 진행함

 

5. Commit Point of Transaction

Transaction이 완성된 시점이다.

Transaction의 결과가 Log에 저장된다.

System failure가 발생하면, 시작되었지만 commit되지 못한 transaction을 찾아서 다시 실행할 수 있다.

Transaction이 commit되기 전에 log buffer를 disk에 저장한다.

 

DBMS Specific Buffer Replacement Policies

  • Page로 관리한다. 모든 버퍼가 가득차면 특정 버퍼를 교체한다.
  • Domain으로 관리한다. 자주 접근하는 data는 Index page로 관리한다. 그 외에는 Data file pages, Log file pages가 존재한다.
  • Hot set method, 교체되지 않는 page를 따로 관리한다.
  • DBMIN method, 특정 DB operation에 맞는 page 접근 패턴을 미리 정해놓는 방법이다.

 

Desirable Properties of Transactions

ACID 특성을 가지는 것이 좋은 transaction이다.

  • Atomicity (단일성)
  • Consistency preservation (일관성)
  • Isolation (독립적 수행)
  • Durability or permanency (수행 결과의 영구적 반영)

 

6. Scheduling based on Recoverability

2 operation conflict에 의한 문제를 해결하기 위함이다.

read-write & write-write conflict이 있다.

잘못 scheduling하는 경우 starvation이 발생할 수 있다.

Recovery가 가능하도록 스케쥴링한다.

즉 commit된 transaction은 다시 roll back할 필요가 없다.

Write transaction이 commit되지 않으면, 뒤의 transaction 중 같은 data에 접근하는 것은 실행하지 않는다.

before image를 저장해둔다.

 

7. Scheduling based on Serializability(equivalence)

Serializable하게 스케쥴링하기도 한다.(무조건 하나씩 진행)

(a)(b) Serializable (c)(d) Non serializable

Concurrency를 효과적으로 관리하지 못하는 단점이 있다. 이는 현재는 쓰이지 않는 방법이며, 대신 equivalent한 serial 스케쥴링 기법을 사용하고 있다. 

 

*Transaction Support in SQL

명확한 Begin_transaction은 없지만, End_transaction은 명시한다.

COMMIT이거나 ROLLBACK이다.

READ ONLY이거나 READ WRITE 두 종류의 transaction이 있다.

Isolation Level option을 가지고 있다.