📄 faq.so
字号:
m4_comment([$Id: faq.so,v 10.11 2006/05/09 19:46:59 bostic Exp $])m4_ref_title(m4_tam Applications, Transaction FAQ, @transaction FAQ, transapp/throughput, rep/intro)m4_nlistbeginm4_nlist([dnlm4_bold([What should a transactional program do when an error occurs?])m4_p([dnlAny time an error occurs, such that a transactionally protected set ofoperations cannot complete successfully, the transaction must beaborted. While deadlock is by far the most common of these errors,there are other possibilities; for example, running out of disk spacefor the filesystem. In m4_db transactional applications, there arethree classes of error returns: "expected" errors, "unexpected butrecoverable" errors, and a single "unrecoverable" error. Expectederrors are errors like m4_ref(DB_NOTFOUND), which indicates that asearched-for key item is not present in the database. Applications maywant to explicitly test for and handle this error, or, in the case wherethe absence of a key implies the enclosing transaction should fail,simply call m4_ref(txn_abort). Unexpected but recoverable errors areerrors like m4_ref(DB_LOCK_DEADLOCK), which indicates that an operationhas been selected to resolve a deadlock, or a system error such as EIO,which likely indicates that the filesystem has no available disk space.Applications must immediately call m4_ref(txn_abort) when these returnsoccur, as it is not possible to proceed otherwise. The onlyunrecoverable error is m4_ref(DB_RUNRECOVERY), which indicates that thesystem must stop and recovery must be run.])])m4_nlist([dnlm4_bold([How can hot backups work? Can't you get an inconsistent pictureof the database when you copy it?])m4_p([dnlFirst, m4_db is based on the technique of "write-ahead logging", whichmeans that before any change is made to a database, a log record iswritten that describes the change. Further, m4_db guarantees that thelog record that describes the change will always be written to stablestorage (that is, disk) before the database page where the change wasmade is written to stable storage. Because of this guarantee, we knowthat any change made to a database will appear either in just a logfile, or both the database and a log file, but never in just thedatabase.])m4_p([dnlSecond, you can always create a consistent and correct database basedon the log files and the databases from a database environment. So,during a hot backup, we first make a copy of the databases and then acopy of the log files. The tricky part is that there may be pages inthe database that are related for which we won't get a consistentpicture during this copy. For example, let's say that we copy pages1-4 of the database, and then are swapped out. For whatever reason(perhaps because we needed to flush pages from the cache, or because ofa checkpoint), the database pages 1 and 5 are written. Then, the hotbackup process is re-scheduled, and it copies page 5. Obviously, wehave an inconsistent database snapshot, because we have a copy of page1 from before it was written by the other thread of control, and a copyof page 5 after it was written by the other thread. What makes thiswork is the order of operations in a hot backup. Because of thewrite-ahead logging guarantees, we know that any page written to thedatabase will first be referenced in the log. If we copy the databasefirst, then we can also know that any inconsistency in the database willbe described in the log files, and so we know that we can fix everythingup during recovery.])])m4_nlist([dnlm4_bold([My application has m4_ref(DB_LOCK_DEADLOCK) errors. Is thenormal, and what should I do?])m4_p([dnlIt is quite rare for a transactional application to be deadlock free.All applications should be prepared to handle deadlock returns, becauseeven if the application is deadlock free when deployed, future changesto the application or the m4_db implementation might introducedeadlocks.])m4_p([dnlPractices which reduce the chance of deadlock include:m4_bulletbeginm4_bullet([dnlNot using cursors which move backwards through the database (m4_ref(DB_PREV)),as backward scanning cursors can deadlock with page splits;])m4_bullet([dnlConfiguring m4_ref(DB_REVSPLITOFF) to turn off reverse splits inapplications which repeatedly delete and re-insert the same keys, tominimize the number of page splits as keys are re-inserted;])m4_bullet([dnlNot configuring m4_ref(DB_READ_UNCOMMITTED) as that flag requires writetransactions upgrade their locks when aborted, which can lead to deadlock.Generally, m4_ref(DB_READ_COMMITTED) or non-transactional read operationsare less prone to deadlock than m4_ref(DB_READ_UNCOMMITTED).])m4_bulletend])])m4_nlist([dnlm4_bold([How can I move a database from one transactional environmentinto another?])m4_p([dnlBecause database pages contain references to log records, databasescannot be simply moved into different database environments. To move adatabase into a different environment, dump and reload the databasebefore moving it. If the database is too large to dump and reload, thedatabase may be prepared in place using the m4_refT(dbenv_lsn_reset) orthe m4_option(r) argument to the m4_link(M4RELDIR/utility/db_load,db_load) utility.])])m4_nlist([dnlm4_bold([I'm seeing the error "log_flush: LSN past current end-of-log",what does that mean?])m4_p([dnlThe most common cause of this error is that a system administrator hasremoved all of the log files from a database environment. You shouldshut down your database environment as gracefully as possible, firstflushing the database environment cache to disk, if that's possible.Then, dump and reload your databases. If the database is too large todump and reload, the database may be reset in place using them4_refT(dbenv_lsn_reset) or the m4_option(r) argument to them4_link(M4RELDIR/utility/db_load, db_load) utility. However, if youreset the database in place, you should verify your databases beforeusing them again. (It is possible for the databases to be corrupted byrunning after all of the log files have been removed, and the longer theapplication runs, the worse it can get.)])])m4_nlistendm4_page_footer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -