⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 am_conv.so

📁 berkeley db 4.6.21的源码。berkeley db是一个简单的数据库管理系统
💻 SO
字号:
m4_comment([$Id: am_conv.so,v 10.24 2003/04/02 16:15:32 bostic Exp $])m4_ref_title(Locking Subsystem, m4_tam locking conventions,    m4_tam @locking conventions, lock/cam_conv, lock/nondb)m4_p([dnlAll m4_db access methods follow the same conventions for lockingdatabase objects.  Applications that do their own locking and also dolocking via the access methods must be careful to adhere to theseconventions.])m4_p([dnlWhenever a m4_db database is opened, the m4_ref(Db) handle is assigneda unique locker ID.  Unless transactions are specified, that ID is usedas the locker for all calls that the m4_db methods make to the locksubsystem.  In order to lock a file,  pages in the file, or records inthe file, we must create a unique ID that can be used as the object tobe locked in calls to the lock manager.  Under normal operation, thatobject is a 28-byte value created by the concatenation of a unique fileidentifier, a page or record number, and an object type (page or record).])m4_p([dnlIn a transaction-protected environment, database create and deleteoperations are recoverable and single-threaded.  This single-threadingis achieved using a single lock for the entire environment that must beacquired before beginning a create or delete operation.  In this case,the object on which m4_db will lock is a 4-byte unsigned integer witha value of 0.])m4_p([dnlIf applications are using the lock subsystem directly while they arealso using locking via the access methods, they must take care not toinadvertently lock objects that happen to be equal to the unique fileIDs used to lock files.  This is most easily accomplished by using alock object with a length different from the values used by m4_db.])m4_p([dnlAll the access methods other than Queue use standard read/write locksin a simple multiple-reader/single writer page-locking scheme.  Anoperation that returns data (for example, m4_ref(dbh_get) orm4_ref(dbc_get)) obtains a read lock on all the pages accessed whilelocating the requested record.   When an update operation is requested(for example, m4_ref(dbh_put) or m4_ref(dbc_del)), the page containingthe updated (or new) data is write-locked.  As read-modify-write cyclesare quite common and are deadlock-prone under normal circumstances, them4_db interfaces allow the application to specify the m4_ref(DB_RMW)flag, which causes operations to immediately obtain a write lock, eventhough they are only reading the data.  Although this may reduceconcurrency somewhat, it reduces the probability of deadlock.  In thepresence of transactions, page locks are held until transaction commit.])m4_p([dnlThe Queue access method does not hold long-term page locks.  Instead,page locks are held only long enough to locate records or to changemetadata on a page, and record locks are held for the appropriateduration.  In the presence of transactions, record locks are held untiltransaction commit.  For m4_db operations, record locks are held untiloperation completion; for m4_ref(Dbc) operations, record locks are helduntil subsequent records are returned or the cursor is closed.])m4_p([dnlUnder non-transaction operations, the access methods do not normallyhold locks across calls to the m4_db interfaces.  The one exception tothis rule is when cursors are used.  Because cursors maintain a positionin a file, they must hold locks across calls; in fact, they will holda lock until the cursor is closed.])m4_p([dnlIn this mode, the assignment of locker IDs to m4_ref(Db) and cursorhandles is complicated.  If the m4_ref(DB_THREAD) option was specifiedwhen the m4_ref(Db) handle was opened, each use of a m4_ref(Db) has itsown unique locker ID, and each cursor is assigned its own unique lockerID when it is created, so m4_ref(Db) handle and cursor operations canall conflict with one another.  (This is because when  m4_db handlesmay be shared by multiple threads of control the m4_db library cannotidentify which operations are performed by which threads of control,and it must ensure that two different threads of control are notsimultaneously modifying the same data structure.  By assigning eachm4_ref(Db) handle and cursor its own locker, two threads of controlsharing a handle cannot inadvertently interfere with each other.)])m4_p([dnlThis has important implications.  If a single thread of control openstwo cursors, uses a combination of cursor and non-cursor operations, orbegins two separate transactions, the operations are performed on behalfof different lockers.  Conflicts that arise between these differentlockers may not cause actual deadlocks, but can, in fact, permanentlyblock the thread of control.  For example, assume that an applicationcreates a cursor and uses it to read record A.  Now, assume a secondcursor is opened, and the application attempts to write record A usingthe second cursor.  Unfortunately, the first cursor has a read lock, sothe second cursor cannot obtain its write lock.  However, that read lockis held by the same thread of control, so the read lock can never bereleased if we block waiting for the write lock.  This might appear tobe a deadlock from the application's perspective, but m4_db cannotidentify it as such because it has no knowledge of which lockers belongto which threads of control.  For this reason, application designersare encouraged to close cursors as soon as they are done with them.])m4_p([dnlIf the m4_ref(DB_THREAD) option was not specified when the m4_ref(Db)handle was opened, all uses of the m4_ref(Db) handle and all cursorscreated using that handle will use the same locker ID for alloperations.  In this case, if a single thread of control opens twocursors or uses a combination of cursor and non-cursor operations, theseoperations are performed on behalf of the same locker, and so cannotdeadlock or block the thread of control.])m4_p([dnlComplicated operations that require multiple cursors (or combinationsof cursor and non-cursor operations) can be performed in two ways.First, they may be performed within a transaction, in which case alloperations lock on behalf of the designated transaction.  Second, theymay be performed using a local m4_ref(Db) handle, although, asm4_ref(dbh_open) operations are relatively slow, this may not be a goodidea.  Finally, the m4_ref(dbc_dup) function duplicates a cursor, usingthe same locker ID as the originating cursor.  There is no way toachieve this duplication functionality through the m4_ref(Db) handlecalls, but any m4_ref(Db) call can be implemented by one or more callsthrough a cursor.])m4_p([dnlWhen the access methods use transactions, many of these problems disappear.The transaction ID is used as the locker ID for all operations performedon behalf of the transaction.  This means that the application may openmultiple cursors on behalf of the same transaction and these cursors willall share a common locker ID.  This is safe because transactions cannotspan threads of control, so the library knows that two cursors in the sametransaction cannot modify the database concurrently.])m4_page_footer

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -