잠금 모드의 종류와 호환성

CUBRID는 트랜잭션이 수행하고자 하는 연산의 종류에 따라 획득하고자 하는 잠금 모드를 결정하며, 다른 트랜잭션에 의해 이미 선점된 잠금 모드의 종류에 따라 잠금 공유 여부를 결정한다. 이와 같은 잠금에 대한 결정은 시스템이 자동으로 수행하며, 사용자에 의한 수동 지정은 허용되지 않는다. CUBRID의 잠금 정보를 확인하기 위해서는 cubrid lockdb db_name 명령어를 사용하며, 자세한 내용은 잠금(lock) 상태 확인을 참고한다.

위에서 설명한 잠금들의 호환 관계(lock compatibility)를 정리하면 아래의 표와 같다. 호환된다는 것은 잠금 유지자(lock holder)가 객체 X에 대해 획득한 잠금과 중복하여 잠금 요청자(lock requester)가 잠금을 획득할 수 있다는 의미다. 한편, N/A는 해당 사항이 없음을 의미한다.

잠금 호환성

 

잠금 유지자(lock holder)

NULL_LOCK

IS_LOCK

S_LOCK

IX_LOCK

SIX_LOCK

U_LOCK

X_LOCK

잠금 요청자
(lock requester)

NULL_LOCK

TRUE

TRUE

TRUE

TRUE

TRUE

TRUE

TRUE

IS_LOCK

TRUE

TRUE

TRUE

TRUE

TRUE

N/A

FALSE

S_LOCK

TRUE

TRUE

TRUE

FALSE

FALSE

FALSE

FALSE

IX_LOCK

TRUE

TRUE

FALSE

TRUE

FALSE

N/A

FALSE

SIX_LOCK

TRUE

TRUE

FALSE

FALSE

FALSE

N/A

FALSE

U_LOCK

TRUE

N/A

TRUE

N/A

N/A

FALSE

FALSE

X_LOCK

TRUE

FALSE

FALSE

FALSE

FALSE

FALSE

FALSE

예제

session 1

session 2

;autocommit off

AUTOCOMMIT IS OFF

set transaction isolation level 4

;xr

Isolation level set to:

REPEATABLE READ SCHEMA, READ COMMITTED INSTANCES.

 

1 command(s) successfully processed.

;autocommit off

AUTOCOMMIT IS OFF

set transaction isolation level 4

;xr

Isolation level set to:

REPEATABLE READ SCHEMA, READ COMMITTED INSTANCES.

 

1 command(s) successfully processed.

 

/*

C:\CUBRID>cubrid lockdb demodb

 

*** Lock Table Dump ***

 

Object Lock Table:

        Current number of objects which are locked    = 0

        Maximum number of objects which can be locked = 10000

*/

select nation_code, gold from participant where nation_code='USA';

;xr

 

=== <Result of SELECT Command> ===

 nation_code                  gold

======================================

'USA'                          36

'USA'                          37

'USA'                          44

'USA'                          37

'USA'                          36

 

5 rows selected.

 

1 command(s) successfully processed.

 

/*

C:\CUBRID>cubrid lockdb demodb

*** Lock Table Dump ***

 

Object type: Root class.

LOCK HOLDERS:

    Tran_index =   2, Granted_mode =  IS_LOCK, Count =   1, Nsubgranules =  1

 

Object type: Class = participant.

LOCK HOLDERS:

    Tran_index =   2, Granted_mode =  IS_LOCK, Count =   2, Nsubgranules =  0

*/

 

 

update participant set gold = 11 where nation_code = 'USA' ;

;xr

 

5 rows affected.

select nation_code, gold from participant where nation_code='USA';

 

;xr

 

/* no results until transaction 2 releases a lock

 

C:\CUBRID>cubrid lockdb demodb

*** Lock Table Dump ***

 

Object type: Instance of class ( 0|   551|   7) = participant.

LOCK HOLDERS:

    Tran_index =   3, Granted_mode =   X_LOCK, Count =   2

 

 

Object type: Root class.

LOCK HOLDERS:

    Tran_index =   3, Granted_mode =  IX_LOCK, Count =   1, Nsubgranules =  3

NON_2PL_RELEASED:

    Tran_index =   2, Non_2_phase_lock =  IS_LOCK

 

 

Object type: Class = participant.

LOCK HOLDERS:

    Tran_index =   3, Granted_mode =  IX_LOCK, Count =   3, Nsubgranules =  5

    Tran_index =   2, Granted_mode =  IS_LOCK, Count =   2, Nsubgranules =  0

*/

 

 

;commit work

 

Current transaction has been committed.

=== <Result of SELECT Command> ===

nation_code                  gold

=================================

'USA'                          11           

'USA'                          11           

'USA'                          11           

'USA'                          11           

'USA'                          11           

 

5 rows selected.

 

1 command(s) successfully processed.

 

/*

C:\CUBRID>cubrid lockdb demodb

 

Object type: Root class.

LOCK HOLDERS:

    Tran_index =   2, Granted_mode =  IS_LOCK, Count =   1, Nsubgranules =  1

 

Object type: Class = participant.

LOCK HOLDERS:

    Tran_index =   2, Granted_mode =  IS_LOCK, Count =   3, Nsubgranules =  0

*/

 

;commit work

 

Current transaction has been committed.

 

/*

C:\CUBRID>cubrid lockdb demodb

 

Object Lock Table:

        Current number of objects which are locked    = 0

        Maximum number of objects which can be locked = 10000

*/