트랜잭션 교착 상태

둘 또는 그 이상의 트랜잭션이 서로 끝나기를(커밋 또는 롤백) 기다리는 상황이 발생할 수 있다. 이 경우 트랜잭션이 서로 진행을 못하게 하기 때문에 교착 상태라고 부른다. 교착 상태가 발생하면 CUBRID는 트랜잭션 중 하나를 롤백시켜 교착 상태를 해결한다. 롤백되는 트랜잭션은 일반적으로 가장 적은 갱신을 수행한 것인데 보통 가장 최근에 시작된 트랜잭션이다.

시스템에 의해 트랜잭션이 롤백되자마자 그 트랜잭션이 가지고 있던 잠금이 해제되고 교착 상태에 있던 다른 트랜잭션이 진행되도록 허가된다. 교착 상태 상황은 비주기적이고 예측 불가능하다. 하지만 교착 상태의 가능성이 있는 경우에는 동일한 데이터를 동시에 갱신하고자 하는 사용자의 수가 증가한다.

예제

isolation_level = 6 (SERIALIZABLE), AUTOCOMMIT은 OFF인 상황이다.

두 사용자가 동시에 동일한 데이터를 갱신하려고 시도한다고 가정하자. 이 예제에서 User1 (T1)은 participant2 클래스를 생성하고 몇 개의 인스턴스를 삽입한다. User1 (T1)과 User2 (T2)는 participant2 클래스에 질의를 하여 동일한 결과를 얻는다.

User1 (T1)

;autocommit off
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
create class participant2(host_year integer, nation_code char(3), gold integer, silver integer, bronze integer)
insert into participant2 (host_year, nation_code, gold, silver, bronze) values (2008, ‘KOR’, 20,10,10);
insert into participant2 (host_year, nation_code, gold, silver, bronze) values (2008, ‘NED’, 12,22,18);
insert into participant2 (host_year, nation_code, gold, silver, bronze) values (2008, ‘GER’, 13,17,19);
commit work;
;xrun
select * from participant2;
;xrun
……
1 command(s) successfully processed.

User2 (T2) :

;autocommit off
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
select host_year, nation_code from participant2;
=== <Result of SELECT Command in Line 2> ===
    host_year  nation_code
===================================
         2008  'KOR'
         2008  'NED'
         2008  'GER'
3 rows selected.

다음으로 User1은 participant2 클래스에서 ‘GER’ 인스턴스를 삭제하려고 시도하지만 User2가 커밋이나 중단을 하지 않았기 때문에 할 수가 없다.  User2가 participant2 클래스에 인스턴스를 삽입하려고 시도하지만 User2 역시 User1이 커밋이나 중단을 하지 않았기 때문에 할 수가 없다. 시스템은 이 교착 상태를 User1의 트랜잭션을 중단하여 해결한다.

User1 (T1):

delete from participant2 where host_year=2008 and nation_code = ’GER’;
;xrun
------- <T2가 ;xrun 실행 후 T1은 트랜잭션을 중단함>
In line 1, column 1,
ERROR: Your transaction (index 2, brightes@cdbs006.cub|27967) has been unilaterally aborted by the system.
0 command(s) successfully processed.

User2 (T2)

insert into participant2 (host_year, nation_code, gold, silver, bronze) values (2008, ‘AUS’, 13,17,19);
;xrun