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

📄 intro.so

📁 berkeley db 4.6.21的源码。berkeley db是一个简单的数据库管理系统
💻 SO
字号:
m4_comment([$Id: intro.so,v 10.33 2006/11/13 18:05:00 bostic Exp $])m4_ref_title(m4_cam Applications,    Concurrent Data Store introduction,    @Concurrent Data Store, env/faq, cam/fail)m4_p([dnlIt is often desirable to have concurrent read-write access to a databasewhen there is no need for full recoverability or transaction semantics.For this class of applications, m4_db provides interfaces supportingdeadlock-free, multiple-reader/single writer access to the database.This means that at any instant in time, there may be either multiplereaders accessing data or a single writer modifying data.  Theapplication is entirely unaware of which is happening, and m4_dbimplements the necessary locking and blocking to ensure this behavior.])m4_p([dnlTo create m4_cam applications, you must first initialize an environmentby calling m4_ref(dbenv_open).  You must specify the m4_ref(DB_INIT_CDB)and m4_ref(DB_INIT_MPOOL) flags to that method.  It is an error tospecify any of the other m4_ref(dbenv_open) subsystem or recoveryconfiguration flags, for example, m4_ref(DB_INIT_LOCK),m4_ref(DB_INIT_TXN), or m4_ref(DB_RECOVER).  All databases must, ofcourse, be created in this environment by using the m4_ref(dbh_create)function or m4_refcxx(Db) constructor, and specifying the environmentas an argument.])m4_p([dnlm4_db performs appropriate locking so that safe enforcement of thedeadlock-free, multiple-reader/single-writer semantic is transparent tothe application.  However, a basic understanding of m4_cam lockingbehavior is helpful when writing m4_cam applications.])m4_p([dnlm4_camavoids deadlocks without the need for a deadlock detector by performingall locking on an entire database at once (or on an entire environmentin the case of the m4_ref(DB_CDB_ALLDB) flag), and by ensuring that atany given time only one thread of control is allowed to simultaneouslyhold a read (shared) lock and attempt to acquire a write (exclusive)lock.])m4_p([dnlAll open m4_db cursors hold a read lock, which serves as a guaranteethat the database will not change beneath them;  likewise, allnon-cursor m4_ref(dbh_get) operations temporarily acquire and releasea read lock that is held during the actual traversal of the database.Because read locks will not conflict with each other, any number ofcursors in any number of threads of control may be open simultaneously,and any number of m4_ref(dbh_get) operations may be concurrently inprogress.])m4_p([dnlTo enforce the rule that only one thread of control at a time canattempt to upgrade a read lock to a write lock, however, m4_db mustforbid multiple cursors from attempting to write concurrently.  This isdone using the m4_ref(DB_WRITECURSOR) flag to the m4_refT(dbh_cursor).This is the only difference between access method calls in m4_cam andin the other m4_db products.  The m4_ref(DB_WRITECURSOR) flag causes thenewly created cursor to be a "write" cursor; that is, a cursor capableof performing writes as well as reads.  Only cursors thus created arepermitted to perform write operations (either deletes or puts), and onlyone such cursor can exist at any given time.])m4_p([dnlAny attempt to create a second write cursor or to perform a non-cursorwrite operation while a write cursor is open will block until that writecursor is closed.  Read cursors may open and perform reads without blockingwhile a write cursor is extant.  However, any attempts to actually performa write, either using the write cursor or directly using them4_ref(dbh_put) or m4_ref(dbh_del) methods, will block until all read cursorsare closed.  This is how the multiple-reader/single-writer semantic isenforced, and prevents reads from seeing an inconsistent database statethat may be an intermediate stage of a write operation.])m4_p([dnlBy default, m4_cam does locking on a per-database basis.  For thisreason, using cursors to access multiple databases in different ordersin different threads or processes, or leaving cursors open on onedatabase while accessing another database, can cause an application tohang.  If this behavior is a requirement for the application, m4_dbshould be configured to do locking on an environment-wide basis.  Seethe m4_ref(DB_CDB_ALLDB) flag of the m4_ref(dbenv_set_flags) functionfor more information.])m4_p([dnlWith these behaviors, m4_db can guarantee deadlock-free concurrentdatabase access, so that multiple threads of control are free to performreads and writes without needing to handle synchronization themselvesor having to run a deadlock detector.  m4_db has no direct knowledge ofwhich cursors belong to which threads, so some care must be taken toensure that applications do not inadvertently block themselves, causingthe application to hang and be unable to proceed.])m4_p([dnlAs a consequence of the m4_cam locking model, the following sequencesof operations will cause a thread to block itself indefinitely:])m4_nlistbeginm4_nlist([dnlKeeping a cursor open while issuing a m4_ref(dbh_put) or m4_ref(dbh_del)access method call.])m4_nlist([dnlAttempting to open a write cursor while another cursor is already beingheld open by the same thread of control.  Note that it is correctoperation for one thread of control to attempt to open a write cursoror to perform a non-cursor write (m4_ref(dbh_put) or m4_ref(dbh_del))while a write cursor is already active in another thread.  It is only aproblem if these things are done within a single thread of control --in which case that thread will block and never be able to release thelock that is blocking it.])m4_nlist([dnlNot testing m4_db error return codes (if any cursor operation returnsan unexpected error, that cursor must still be closed).])m4_nlistendm4_p([dnlIf the application needs to open multiple cursors in a single thread toperform an operation, it can indicate to m4_db that the cursor locksshould not block each other by creating a m4_cam m4_bold(group), usingm4_ref(cdsgroup_begin).  This creates a locker ID that is shared by allcursors opened in the group.])m4_p([dnlm4_cam groups use a m4_ref(DbTxn) handle to indicate the shared lockerID to m4_db calls, and call m4_ref(txn_commit) to end the group.  Thisis a convenient way to pass the locked ID to the calls where it isneeded, but should not be confused with the real transactional semanticsprovided by m4_tam.  In particular, m4_cam groups do not provide anyabort or recovery facilities, and have no impact on durability ofoperations.])m4_page_footer

⌨️ 快捷键说明

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