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

📄 config.so

📁 berkeley db 4.6.21的源码。berkeley db是一个简单的数据库管理系统
💻 SO
字号:
m4_comment([$Id: config.so,v 10.4 2002/06/05 21:09:14 bostic Exp $])m4_ref_title(Application Specific Logging and Recovery,    Application configuration,,    apprec/auto, program/appsignals)m4_p([dnlThe application should include a dispatch function that dispatches toappropriate printing and/or recovery functions based on the log recordtype and the operation code.  The dispatch function should take the samearguments as the recovery function, and should call the appropriaterecovery and/or printing functions based on the log record type and theoperation code.  For example, the ex_apprec dispatch function is asfollows:])m4_indent([dnlintapprec_dispatch(dbenv, dbt, lsn, op)	DB_ENV *dbenv;	DBT *dbt;	DB_LSN *lsn;	db_recops op;{	u_int32_t rectype;	/* Pull the record type out of the log record. */	memcpy(&rectype, dbt-__GT__data, sizeof(rectype));	switch (rectype) {	case DB_ex_apprec_mkdir:		return (ex_apprec_mkdir_recover(dbenv, dbt, lsn, op, NULL));	default:		/*		 * We've hit an unexpected, allegedly user-defined record		 * type.		 */		dbenv-__GT__errx(dbenv, "Unexpected log record type encountered");		return (EINVAL);	}}])m4_p([dnlApplications use this dispatch function and the automatically generatedfunctions as follows:])m4_nlistbeginm4_nlist([dnlWhen the application starts, call the m4_ref(dbenv_set_app_dispatch)with your dispatch function.])m4_nlist([dnlIssue a m4_ref(txn_begin) call before any operations you want to betransaction-protected.])m4_nlist([dnlBefore accessing any data, issue the appropriate lock call to lock thedata (either for reading or writing).])m4_nlist([dnlBefore modifying any data that is transaction-protected, issue a callto the appropriate log function.])m4_nlist([dnlCall m4_ref(txn_commit) to save all the changes, or call m4_ref(txn_abort)to cancel all of the modifications.])m4_nlistendm4_p([dnlThe recovery functions are called in the three following cases:])m4_nlistbeginm4_nlist([dnlDuring recovery after application or system failure, with op set tom4_ref(DB_TXN_FORWARD_ROLL) or m4_ref(DB_TXN_BACKWARD_ROLL).])m4_nlist([dnlDuring transaction abort, with op set to m4_ref(DB_TXN_ABORT).])m4_nlist([dnlOn a replicated client to apply updates from the master, with op set tom4_ref(DB_TXN_APPLY).])m4_nlistendm4_p([dnlFor each log record type you declare, you must write the appropriatefunction to undo and redo the modifications.  The shell of thesefunctions will be generated for you automatically, but you must fill inthe details.])m4_p([dnlYour code must be able to detect whether the described modificationshave been applied to the data.  The function will be called with the"op" parameter set to m4_ref(DB_TXN_ABORT) when a transaction that wrotethe log record aborts, with m4_ref(DB_TXN_FORWARD_ROLL) andm4_ref(DB_TXN_BACKWARD_ROLL) during recovery, and with m4_ref(DB_TXN_APPLY)on a replicated client.])m4_p([dnlThe actions for m4_ref(DB_TXN_ABORT) and m4_ref(DB_TXN_BACKWARD_ROLL)should generally be the same, and the actions form4_ref(DB_TXN_FORWARD_ROLL) and m4_ref(DB_TXN_APPLY) should generallybe the same.  However, if the application is using m4_db replicationand another thread of control may be performing read operations whilelog records are applied on a replication client, the recovery functionshould perform appropriate locking during m4_ref(DB_TXN_APPLY)operations.  In this case, the recovery function may encounter deadlockswhen issuing locking calls.  The application should run with thedeadlock detector, and the recovery function should simply returnm4_ref(DB_LOCK_DEADLOCK) if a deadlock is detected and a lockingoperation fails with that error.])m4_p([dnlThe m4_ref(DB_TXN_PRINT) operation should print the log record,typically using the auto-generated print function; it is not used inthe m4_db library, but may be useful for debugging, as in them4_ref(db_printlog) utility.  Applications may safely ignore thisoperation code, they may handle printing from the recovery function, orthey may dispatch directly to the auto-generated print function.])m4_p([dnlOne common way to determine whether operations need to be undone orredone is the use of log sequence numbers (LSNs).  For example, eachaccess method database page contains the LSN of the most recent logrecord that describes a modification to the page.  When the accessmethod changes a page, it writes a log record describing the change andincluding the LSN that was on the page before the change.  This LSN isreferred to as the previous LSN.  The recovery functions read the pagedescribed by a log record, and compare the LSN on the page to the LSNthey were passed.])m4_p([dnlIf the page LSN is less than the passed LSN and the operation is anundo, no action is necessary (because the modifications have not beenwritten to the page).  If the page LSN is the same as the previous LSNand the operation is a redo, the actions described are reapplied to thepage.  If the page LSN is equal to the passed LSN and the operation isan undo, the actions are removed from the page; if the page LSN isgreater than the passed LSN and the operation is a redo, no furtheraction is necessary.  If the action is a redo and the LSN on the pageis less than the previous LSN in the log record, it is an error becauseit could happen only if some previous log record was not processed.])m4_p([dnlExamples of other recovery functions can be found in the m4_db libraryrecovery functions (found in files named XXX_rec.c) and in theapplication-specific recovery example (specifically, ex_apprec_rec.c).])m4_p([dnlFinally, applications need to ensure that any data modifications theyhave made, that were part of a committed transaction, must be writtento stable storage before calling the m4_refT(txn_checkpoint).  This isto allow the periodic removal of database environment log files.])m4_page_footer

⌨️ 快捷键说明

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