📄 envopen.so
字号:
m4_comment([$Id: envopen.so,v 11.14 2003/10/18 19:16:12 bostic Exp $])m4_ref_title(Upgrading m4_db Applications, Release 3.0: environment open/close/unlink,, upgrade.3.0/intro, upgrade.3.0/func)m4_p([dnlThe hardest part of upgrading your application from a 2.X code base tothe 3.0 release is translating the m4_db environment open, close andremove calls.])m4_p([dnlThere were two logical changes in this part of the m4_db interface.First, in m4_db 3.0, there are no longer separate structures thatrepresent each subsystem (for example, DB_LOCKTAB or DB_TXNMGR) and anoverall m4_ref(DbEnv) environment structure. Instead there is only them4_ref(DbEnv) structure. This means that m4_ref(DbEnv) referencesshould be passed around by your application instead of passing aroundDB_LOCKTAB or DB_TXNMGR references. This is likely to be a simplechange for most applications as few applications use the lock_XXX,log_XXX, memp_XXX or txn_XXX interfaces to create m4_db environments.])m4_p([dnlThe second change is that there are no longer separate open, close, andunlink interfaces to the m4_db subsystems. For example, in previousreleases, it was possible to open a lock subsystem either usingdb_appinit or using the lock_open call. In the 3.0 release the XXX_openinterfaces to the subsystems have been removed, and subsystems must nowbe opened using the 3.0 replacement for the db_appinit call.])m4_p([dnlTo upgrade your application, first find each place your application opens,closes and/or removes a m4_db environment. This will be code of the form:])m4_indent([dnldb_appinit, db_appexitlock_open, lock_close, lock_unlinklog_open, log_close, log_unlinkmemp_open, memp_close, memp_unlinktxn_open, txn_close, txn_unlink])m4_p([dnlEach of these groups of calls should be replaced with calls to:])m4_indent([dnlm4_ref(dbenv_create), m4_ref(dbenv_open), m4_ref(dbenv_close),m4_ref(dbenv_remove)])m4_p([dnlThe m4_ref(dbenv_create) call and the call to the m4_ref(dbenv_open)method replace the db_appinit, lock_open, log_open, memp_open and txn_opencalls. The m4_ref(dbenv_close) method replaces the db_appexit,lock_close, log_close, memp_close and txn_close calls. Them4_ref(dbenv_remove) call replaces the lock_unlink, log_unlink,memp_unlink and txn_unlink calls.])m4_p([dnlHere's an example creating a m4_db environment using the 2.X interface:])m4_indent([dnl/* * db_init -- * Initialize the environment. */DB_ENV *db_init(home) char *home;{ DB_ENV *dbenv;m4_blank if ((dbenv = (DB_ENV *)calloc(sizeof(DB_ENV), 1)) == NULL) return (errno);m4_blank if ((errno = db_appinit(home, NULL, dbenv, DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_USE_ENVIRON)) == 0) return (dbenv);m4_blank free(dbenv); return (NULL);}])m4_p([dnlIn the m4_db 3.0 release, this code would be written as:])m4_indent([dnl/* * db_init -- * Initialize the environment. */intdb_init(home, dbenvp) char *home; DB_ENV **dbenvp;{ int ret; DB_ENV *dbenv;m4_blank if ((ret = db_env_create(&dbenv, 0)) != 0) return (ret);m4_blank if ((ret = dbenv-__GT__open(dbenv, home, NULL, DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_USE_ENVIRON, 0)) == 0) { *dbenvp = dbenv; return (0); }m4_blank (void)dbenv-__GT__close(dbenv, 0); return (ret);}])m4_p([dnlAs you can see, the arguments to db_appinit and to m4_ref(dbenv_open) arelargely the same. There is some minor re-organization: the mapping isthat arguments #1, 2, 3, and 4 to db_appinit become arguments #2, 3, 1and 4 to m4_ref(dbenv_open). There is one additional argument tom4_ref(dbenv_open), argument #5. For backward compatibility with the 2.Xm4_db releases, simply set that argument to 0.])m4_p([dnlIt is only slightly more complex to translate calls to XXX_open to them4_ref(dbenv_open) method. Here's an example of creating a lock regionusing the 2.X interface:])m4_indent([dnllock_open(dir, DB_CREATE, 0664, dbenv, ®ionp);])m4_p([dnlIn the m4_db 3.0 release, this code would be written as:])m4_indent([dnlif ((ret = db_env_create(&dbenv, 0)) != 0) return (ret);m4_blankif ((ret = dbenv-__GT__open(dbenv, dir, NULL, DB_CREATE | DB_INIT_LOCK, 0664)) == 0) { *dbenvp = dbenv; return (0);}])m4_p([dnlNote that in this example, you no longer need the DB_LOCKTAB structurereference that was required in m4_db 2.X releases.])m4_p([dnlThe final issue with upgrading the db_appinit call is the DB_MPOOL_PRIVATEoption previously provided for the db_appinit call. If your applicationis using this flag, it should almost certainly use the newm4_ref(DB_PRIVATE) flag to the m4_refT(dbenv_open). Regardless, youshould carefully consider this change before converting to use them4_ref(DB_PRIVATE) flag.])m4_p([dnlTranslating db_appexit or XXX_close calls to m4_ref(dbenv_close) is equallysimple. Instead of taking a reference to a per-subsystem structure suchas DB_LOCKTAB or DB_TXNMGR, all calls take a reference to a m4_ref(DbEnv)structure. The calling sequence is otherwise unchanged. Note that asthe application no longer allocates the memory for the DB_ENV structure,application code to discard it after the call to db_appexit() is no longerneeded.])m4_p([dnlTranslating XXX_unlink calls to m4_ref(dbenv_remove) is slightly more complex.As with m4_ref(dbenv_close), the call takes a reference to a m4_ref(DbEnv)structure instead of a per-subsystem structure. The calling sequence isslightly different, however. Here is an example of removing a lock regionusing the 2.X interface:])m4_indent([dnlDB_ENV *dbenv;m4_blankret = lock_unlink(dir, 1, dbenv);])m4_p([dnlIn the m4_db 3.0 release, this code fragment would be written as:])m4_indent([dnlDB_ENV *dbenv;m4_blankret = dbenv-__GT__remove(dbenv, dir, NULL, DB_FORCE);])m4_p([dnlThe additional argument to the m4_ref(dbenv_remove) function is aconfiguration argument similar to that previously taken by db_appinit andnow taken by the m4_ref(dbenv_open) method. For backward compatibilitythis new argument should simply be set to NULL. The force argument toXXX_unlink is now a flag value that is set by m4_or it them4_ref(dbenv_remove) flag argument.])m4_page_footer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -