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

📄 inc.so

📁 berkeley db 4.6.21的源码。berkeley db是一个简单的数据库管理系统
💻 SO
字号:
m4_comment([$Id: inc.so,v 1.17 2006/08/31 15:26:59 ubell Exp $])m4_ref_title(m4_tam Applications,    Isolation,, transapp/atomicity, transapp/read)m4_p([dnlThe third reason listed for using transactions was m4_italic(isolation).Consider an application suite in which multiple threads of control(multiple processes or threads in one or more processes) are changingthe values associated with a key in one or more databases.  Specifically,they are taking the current value, incrementing it, and then storing itback into the database.])m4_p([dnlSuch an application requires isolation.  Because we want to change a valuein the database, we must make sure that after we read it, no other threadof control modifies it.  For example, assume that both thread #1 andthread #2 are doing similar operations in the database, where thread #1is incrementing records by 3, and thread #2 is incrementing records by5.  We want to increment the record by a total of 8.  If the operationsinterleave in the right (well, wrong) order, that is not what willhappen:])m4_indent([dnlthread [#]1  m4_bold(read) record: the value is 2thread [#]2  m4_bold(read) record: the value is 2thread [#]2  m4_bold(write) record + 5 back into the database (new value 7)thread [#]1  m4_bold(write) record + 3 back into the database (new value 5)])m4_p([dnlAs you can see, instead of incrementing the record by a total of 8,we've incremented it only by 3 because thread #1 overwrote thread #2'schange.  By wrapping the operations in transactions, we ensure that thiscannot happen.  In a transaction, when the first thread reads therecord, locks are acquired that will not be released until thetransaction finishes, guaranteeing that all writerswill block, waiting for the first thread's transaction to complete (orto be aborted).])m4_p([dnlHere is an example function that does transaction-protected incrementson database records to ensure isolation:])include(ref/transapp/inc.cs)m4_p([dnlThe m4_ref(DB_RMW) flag in the m4_ref(dbh_get) call specifies a write lockshould be acquired on the key/data pair, instead of the more obvious readlock.  We do this because the application expects to write the key/datapair in a subsequent operation, and the transaction is much more likely todeadlock if we first obtain a read lock and subsequently a write lock, thanif we obtain the write lock initially.])m4_page_footer

⌨️ 快捷键说明

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