Berkeley DB Reference Guide:
Locking Subsystem

PrevRefNext

Berkeley DB Concurrent Data Store locking conventions

The Berkeley DB Concurrent Data Store product has a simple set of conventions for locking. It provides multiple-reader/single-writer semantics, but not per-page locking or transaction recoverability. As such, it does its locking entirely in the Berkeley DB interface layer.

(Berkeley DB Concurrent Data Store product ´Â ¶ôÀ» À§ÇØ ´Ü¼øÇÑ ÄÁº¥¼Ç ¼ÂÀ» °¡Áö°í ÀÖ´Ù.ÀÌ°ÍÀº ¸ÖƼ ¸®´õ/½Ì±Û ¶óÀÌÅ͸¦ Áö¿øÇÑ´Ù.±×·¯³ª ÆäÀÌÁö´ç ¶ô°ú Æ®·£Á§¼Çº¹±¸´Â Áö¿øÇÏÁö ¾Ê´À´Ù.ÀÌ¿Í°°ÀÌ ÀÌ°ÍÀº ¹öŬ¸® µðºñ ÀÎÅÍÆäÀ̽º ·¹À̾¼­ ÀüüÀûÀ¸·Î ¶ôÀ» °Ç´Ù.)

The object it locks is the file, identified by its unique file number. The locking matrix is not one of the two standard lock modes, instead, we use a four-lock set, consisting of the following:

(ÀÌ°ÍÀÌ ¶ô½ÃÅ°´Â ¿ÀºêÁ§Æ®´Â À¯ÀϼºÀÖ´Â ÆÄÀϳѹö¿¡ ÀÇÇØ ±¸ºÐµÇ´Â ÆÄÀÏÀÌ´Ù.¶ô¸ÞÆ®¸¯½º´Â µÎ°³ÀÇ Ç¥Áضô¸ðµåÁßÀÇ Çϳª°¡ ¾Æ´Ï°í ´ë½Å ¿ì¸®´Â ´ÙÀ½ÀÇ 4°³ÀÇ ¶ô ¼ÂÀ» »ç¿ëÇÑ´Ù.)

DB_LOCK_NG
not granted (always 0)
DB_LOCK_READ
read (shared)
DB_LOCK_WRITE
write (exclusive)
DB_LOCK_IWRITE
intention-to-write (shared with NG and READ, but conflicts with WRITE and IWRITE)

The IWRITE lock is used for cursors that will be used for updating (IWRITE locks are implicitly obtained for write operations through the Berkeley DB handles, for example, DB->put or DB->del). While the cursor is reading, the IWRITE lock is held; but as soon as the cursor is about to modify the database, the IWRITE is upgraded to a WRITE lock. This upgrade blocks until all readers have exited the database. Because only one IWRITE lock is allowed at any one time, no two cursors can ever try to upgrade to a WRITE lock at the same time, and therefore deadlocks are prevented, which is essential because Berkeley DB Concurrent Data Store does not include deadlock detection and recovery.

(IWRITE ¶ôÀº ¾÷µ¥ÀÌÆ®¸¦ À§ÇØ »ç¿ëµÇ´Â Ä¿¼­¸¦ À§ÇØ»ç¿ëµÈ´Ù.(IWRITE )¶ôÀº ¹¬½ÃÀûÀ¸·Î ¹öŬ¸®µðºñÇÚµéÀ» ÅëÇÑ ¾²±â ¿ÀÆÛ·¹À̼ÇÀ» À§ÇØ °É¸®°Ô µÈ´Ù.¿¹¸¦µé¾î DB->put or DB->del).Ä¿¼­°¡ Àд µ¿¾È IWRITE lockÀº °É¸°´Ù. ±×·¯³ª Ä¿¼­°¡ µðºñ¸¦ ¼öÁ¤ÇϱâÁ÷Àü IWRITE lockÀº WRITE lockÀ¸·Î ¾÷±×·¹À̵åµÇ°í ¸®´õ°¡ µðºñ¸¦ ¶°³¯¶§±îÁö ºí¶ôµÇ°Ô µÈ´Ù.¾î¶²¼ø°£¿¡ ¿ÀÁ÷ ÇϳªÀÇ  IWRITE ¶ôÀÌ Çã¿ëµÇ±â ¶§¹®¿¡ °°Àº½Ã°£¿¡ µÎ°³ÀÇ Ä¿¼­°¡ WRITE lock À¸·Î ¾÷±×·¹À̵åµÉ ¼ö ¾ø´Ù.±×¸®°í µ¥µå¶ôÀÌ ¾ïÁ¦µÈ´Ù. ÀÌ°ÍÀº Berkeley DB Concurrent Data Store °¡ µ¥µå¶ô ŽÁö¿Í º¹±¸¸¦ Æ÷ÇÔÇÏÁö ¾Ê±â ¶§¹®¿¡ Çʼö ÀûÀÌ´Ù.

Applications that need to lock compatibly with Berkeley DB Concurrent Data Store must obey the following rules:

(Berkeley DB Concurrent Data Store ¿Í ȣȯ°¡´ÉÇÑ ¶ôÀ» ÇÊ¿ä·ÎÇÑ ¾ÖÇø®ÄÉÀ̼ÇÀº ´ÙÀ½À» µû¶ó¾ß ÇÑ´Ù.)

  1. Use only lock modes DB_LOCK_NG, DB_LOCK_READ, DB_LOCK_WRITE, DB_LOCK_IWRITE.

    (´ÙÀ½ÀÇ ¶ô¸ðµå¸¸ »ç¿ëÇÑ´Ù: DB_LOCK_NG, DB_LOCK_READ, DB_LOCK_WRITE, DB_LOCK_IWRITE. )

  2. Never attempt to acquire a WRITE lock on an object that is already locked with a READ lock.

    ( ÀÌ¹Ì ¸®µå¶ôÀÌ °É·ÁÀÖ´Â ¿ÀºêÁ§Æ®¿¡ ¾²±â¶ô¾ò±â¸¦ ½ÃµµÇÏÁö ¾Ê¾Æ¾ß ÇÑ´Ù.)


PrevRefNext

Copyright (c) 1996-2003 Sleepycat Software, Inc. - All rights reserved.