- Transaction processing systems (트랜잭션 처리 시스템)
대규모 Database와 수 백명의 동시 사용자가 Database Transaction을 실행하는 System
E.g., 항공 예약, 은행 업무, 신용 카드 처리, etc...- Transaction
Database에서 수행되는 여러 작업을 하나의 논리적 단위로 수행하는 것
Correctness
andConsistency
를 보장해야 한다.
BEGIN_TRANSACTION
: Transaction execution의 beginning를 나타낸다.READ or WRITE
: Database items에 read or write operationEND_TRANSACTION
: Transaction execution의 종료를 나타낸다. commited
or aborted.
COMMIT_TRANSACTION
: Transaction의 성공적인 종료 신호ROLL_BACK(or ABORT)
: Transaction이 정상적으로 종료되지 않음의 신호(rollback)
- Partially commited
- Why?
- For fast response to user
- DBMS는 각 트랜잭션 단위가 아닌 disk의 변경 사항을 한 번에 반영한다.
- 일부의 Concurrency control protocols : 추가적으로 가능한 commit을 확인한다.
- 일부의 Recovery protocols : 실패사항과 database에 끼치는 영향을 확인한다.
Failed
: checks 중 하나가 실패하거나, Transaction이 abort된 경우
- Partially commited → Abort → Failed
- EX) Deadlock
- Failed or aborted transaaction이 재시작된다. (by user or automatically)
Terminated
: Transaction이 system을 떠남
Committed
Àborted
Failures : classified as transaction, system, and media failures
1) A computer failure
2) A transaction or system error
3) Local error or exception conditions detected by the transaction
4) Concurrency control enforcement
5) Disk failure
6) Physical problems and catastrophe
The DBMS must keep sufficient information to recover quickly from Types 1-4 failures (more common than the others).
DBMS에서 장애로부터 복구하기 위해 유지된다.
append-only
파일이 저장된다. Log buffer
: 로그를 기록하는 데 사용되는 주 기억 장치 버퍼 중 하나(또는 여러 개)Types of "Log Records"
1. [start_transaction, T]
2. [read_item, T, X]
3. [write_item, T, X, old_value, new_value]
4. [commit, T]
5. [abort, T]
T
: a unique transaction identifier generated automatically
System crashes가 발생하면 log를 확인하고
ARIES
와 같은 recovery technique를 사용하여 consistent한 database로 복구할 수 있다.
UNDO
operations : Restore X to old_valueWRITE
operations의 영향을 역추적해서 작성한 내용을 복원한다.REDO
operations : Updates X to new_valueARIES
에서는 `forward
àction을 수행하는 데 사용Transaction의 모든 operations이 성공적으로 완료되고, log에 모두 기록된다면
T는committed
되었다고 한다.
REDO
한다.start_transaction
레코드가 있는 경우, recovery process 중에 database에 그들의 영향을 Undo
한다. (rollback)Transaction이라면 무조건 충족해야하는 특성
Transaction이 안전하게 수행된다는 것을 보장하기 위한 성질
Atomicity
: Recovery subsystem이 책임 (By DBMS)Consistency
: programmer가 책임 (By programmer)
Isolation
: concurrency control subsystem에 의한 시행 (By lock manager)
Durability
: recovery subsystem이 책임 (By DBMS)
A schedule
S
ofn
(concurrent) transactionsT1, T2, ..., Tn
- Transactions의 operations의 순서
- 서로 다른 Transaction의 작업(Read/Write)는
S
에서Serial(직렬)
혹은Interleaved(교차)
될 수 있다.
- Example of a schedule (S) of “interleaving” two transactions, T1 and T2:
S: r1(X); w2(X); w1(X); r1(Y); w2(X); w1(Y);
- Total ordering of operations in
S
- `
S
에 두 개의 operation 중 하나의 Operation은 반드시 다른 operation 전에 발생해야 한다.- Partial ordering of operations in
S
- 특정 작업 간의 시간 순서가 시스템에 의해 결정되지 않은 경우 사용된다.
Schedule S
가 serial(직렬)
이라면 S
에 있는 모든 Transcation에 대한 모든 Opertaion이 Interleaving(교차)
없이 연속적으로 실행된다.
nonserial
라고 부른다.모든 serial schedule은 Correct하다.
concurrency(동시성)
을 금지한다.Solution
Serial schedule과 거의 비슷하게 동작하는 schedule을 사용한다.
Schedule에서 두 개의 작업이 충돌한다는 것은 다음을 의미한다. (세 가지 조건이 모두 충족되어야 한다.)
- 두 개의 작업이 서로 다른 transaction에 속한다.
- 작업들이 동일한 Item X에 접근한다.
- 적어도 하나의 작업이
write_item(X)
다.
또한, 두 개의 작업의 순서가 변경되었을 때, 결과가 다르게 나오는 경우도 충돌한다.
Two Types of conflict
read-write
write-write
이러한 충동을 방지하기 위해, Concurrency Control technique으로 correctness를 보장해야 한다.
다음과 같이 동시에 실행될 수 있는 Transaction을 고려하자
Serial
하기 때문에 순서를 변경 시켜도 결과는 동일하다.
Nonserial
하기 때문에 T1과 T2의 작업 간에 교차가 일어난다.
Nonserial
은 순서에 따라 결과가 달라졌지만,Serializable
은 순서를 변경시켜도 결과가 동일하다.
Lost update (갱신 손실)
두 개의 Transaction이 같은 Database item에 접근해서 Interleaving하게 작업을 수행할 때 몇 database item은 Incorrect하다.
T1이 write한 값에 T2가 해당 값을 다시 써서 값이 덮어쓰여졌다. (Overwrite)
이로써 T1이 작성한 Item X는 Lost
The Dirty read (or temporary update)
problem
T2에서는 T1에서 write하고 abort된 dirty data를 read한다. ->
Dirty read
X의 Value가Òld_value
로 복구되어야 한다.
The Incorrect summary problem
(called phantom read
)
T3는 A, ... , Y의 값의 누적합을 구한다.
T1에서 T3가 구하고자 하는 값을 변경하는 경우 결과 값이 달라진다.
Unrepetable read
problem
이러한 문제들을 해결하기 위해
nonserial
하지만, serializable schedule을 생성하기 위해 좋은 concurrency control이 필요하다.
Use concurrency control (CC) protocols
Two-phase locking(2PL)
: most common techniqueLock
을 건다.Deadlock
예방은 보장하지 못한다.Not Following 2PL
Following 2PL
The types oof concurrency control protocols
Begin_Transaction
statement가 없다.COMMIT | ROLLBACK
ISOLATION LEVEL <isolation>
Isolation Level
READ UNCOMMITTED | READ COMMITTED (by default in Oracle)
REPEATABLE READ | SERIALIZABLE (by default in most DBMSes)
트랜잭션이
SERIALIZABLE
보다 낮은 Level을 가질 경우 다음 문제가 발생할 수 있다.
Dirty read(오손 읽기)
Nonrepeatable read(반복 불가능)
Phantoms(유령 데이터)
READ COMMITTED
: 트랜잭션 성능 향상
SERIALIZABLE
: Concurrency Control 가능
Reference
Database System Concepts | Abraham Silberschatz
데이터베이스 시스템 7th edition
dirty read는 오손도손 읽기입니다.