📄 auto.so
字号:
m4_comment([$Id: auto.so,v 10.4 2006/09/13 16:21:43 sue Exp $])m4_ref_title(Application Specific Logging and Recovery, Automatically generated functions,, apprec/def, apprec/config)m4_p([dnlThe XXX.src file is processed using the gen_rec.awk script included inthe dist directory of the m4_db distribution. This is an awk scriptthat is executed from with the following command line:])m4_indent([dnlawk -f gen_rec.awk \ -v source_file=m4_italic(C_FILE) \ -v header_file=m4_italic(H_FILE) \ -v template_file=m4_italic(TMP_FILE) __LT__ XXX.src])m4_p([dnlwhere m4_italic(C_FILE) is the name of the file into which to place theautomatically generated C code, m4_italic(H_FILE) is the name of thefile into which to place the automatically generated data structuresand declarations, and m4_italic(TMP_FILE) is the name of the file intowhich to place a template for the recovery routines.])m4_p([dnlBecause the gen_rec.awk script uses sources files located relative tothe m4_db dist directory, it must be run from the dist directory. Forexample, in building the m4_db logging and recovery routines forex_apprec, the following script is used to rebuild the automaticallygenerated files:])m4_indent([dnlE=../examples_c/ex_apprecm4_blankcd ../../distawk -f gen_rec.awk \ -v source_file=$E/ex_apprec_auto.c \ -v header_file=$E/ex_apprec_auto.h \ -v print_file=$E/ex_apprec_autop.c \ -v template_file=$E/ex_apprec_template __LT__ $E/ex_apprec.src])m4_p([dnlFor each log record description found in the XXX.src file, the followingstructure declarations and #defines will be created in the filem4_italic(header_file):])m4_indent([dnl#define DB_PREFIX_RECORD_TYPE /* Integer ID number */m4_blanktypedef struct _PREFIX_RECORD_TYPE_args { /* * These three fields are generated for every record. */ u_int32_t type; /* Record type used for dispatch. */m4_blank /* * Transaction handle that identifies the transaction on whose * behalf the record is being logged. */ DB_TXN *txnid;m4_blank /* * The log sequence number returned by the previous call to log_put * for this transaction. */ DB_LSN *prev_lsn;m4_blank /* * The rest of the structure contains one field for each of * the entries in the record statement. */};])m4_p([dnlThus, the auto-generated ex_apprec_mkdir_args structure looks as follows:])m4_indent([dnltypedef struct _ex_apprec_mkdir_args { u_int32_t type; DB_TXN *txnid; DB_LSN prev_lsn; DBT dirname;} ex_apprec_mkdir_args;])m4_p([dnlThe template_file will contain a template for a recovery function. Therecovery function is called on each record read from the log duringsystem recovery, transaction abort, or the application of log recordson a replication client, and is expected to redo or undo the operationsdescribed by that record. The details of the recovery function will bespecific to the record being logged and need to be written manually,but the template provides a good starting point. (Note that thetemplate assumes that the record is manipulating the internals of am4_db database and sets up database handles, page structures, and suchfor convenience. Many application-specific log records will not needthese, and may simply delete much of the template. Seeex_apprec_template and ex_apprec_rec.c for an example.)])m4_p([dnlThe template file should be copied to a source file in the application(but not the automatically generated source_file, as that will getoverwritten each time gen_rec.awk is run) and fully developed there.The recovery function takes the following parameters:])m4_indentv([dnlm4_tagbeginm4_tag(dbenv, [The environment in which recovery is running.])m4_tag(rec, [The record being recovered.])m4_tag(lsn, [The log sequence number of the record being recovered. Theprev_lsn field, automatically included in every auto-generated logrecord, should be returned through this argument. The prev_lsn fieldis used to chain log records together to allow transaction aborts;because the recovery function is the only place that a log record getsparsed, the responsibility for returning this value lies with therecovery function writer.])m4_tag(op, [dnlA parameter of type db_recops, which indicates what operation is beingrun (m4_ref(DB_TXN_ABORT), m4_ref(DB_TXN_APPLY), m4_ref(DB_TXN_BACKWARD_ROLL),m4_ref(DB_TXN_FORWARD_ROLL) or m4_ref(DB_TXN_PRINT)).])m4_tag(info, [dnlA structure passed by the dispatch function. It is used to contain alist of committed transactions and information about files that may havebeen deleted. Application-specific log records can usually simplyignore this field.])m4_tagend])m4_p([dnlIn addition to the header_file and template_file, a source_file iscreated, containing a log, read, recovery, and print function for eachrecord type.])m4_p([dnlThe log function marshalls the parameters into a buffer, and callsm4_ref(log_put) on that buffer returning 0 on success and non-zero onfailure. The log function takes the following parameters:])m4_indentv([dnlm4_tagbeginm4_tag(dbenv, [The environment in which recovery is running.])m4_tag(txnid, [dnlThe transaction identifier for the transaction handle returned bym4_ref(txn_begin).])m4_tag(lsnp, [dnlA pointer to storage for a log sequence number into which the logsequence number of the new log record will be returned.])m4_tag(syncflag, [dnlA flag indicating whether the record must be written synchronously.Valid values are 0 and m4_ref(DB_FLUSH).])m4_tag(args, [dnlThe remaining parameters to the log message are the fields describedin the XXX.src file, in order.])m4_tagend])m4_p([dnlThe read function takes a buffer and unmarshalls its contents into astructure of the appropriate type. It returns 0 on success and non-zeroon error. After the fields of the structure have been used, the pointerreturned from the read function should be freed. The read functiontakes the following parameters:])m4_indentv([dnlm4_tagbeginm4_tag(dbenv, [The environment in which recovery is running.])m4_tag(recbuf, [A buffer.])m4_tag(argp, [A pointer to a structure of the appropriate type.])m4_tagend])m4_p([dnlThe print function displays the contents of the record. The printfunction takes the same parameters as the recovery function describedpreviously. Although some of the parameters are unused by the printfunction, taking the same parameters allows a single dispatch loop todispatch to a variety of functions. The print function takes thefollowing parameters:])m4_indentv([dnlm4_tagbeginm4_tag(dbenv, [The environment in which recovery is running.])m4_tag(rec, [The record being recovered.])m4_tag(lsn, [The log sequence number of the record being recovered.])m4_tag(op, Unused.)m4_tag(info, Unused.)m4_tagend])m4_p([dnlFinally, the source file will contain a function (named XXX_init_print,where XXX is replaced by the prefix) which should be added to theinitialization part of the standalone m4_ref(db_printlog) utility codeso that utility can be used to display application-specific log records.])m4_page_footer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -