NNAAMMEE DbMpoolFile - shared memory buffer pool SSYYNNOOPPSSIISS ##iinncclluuddee <> ssttaattiicc iinntt DDbbMMppoooollFFiillee::::ooppeenn((DDbbMMppooooll **mmpp,, cchhaarr **ffiillee,, uu__iinntt3322__tt ffllaaggss,, iinntt mmooddee,, ssiizzee__tt ppaaggeessiizzee,, DDbbMMppoooollFFiinnffoo **ffiinnffoopp,, DDbbMMppoooollFFiillee ****mmppff));; iinntt DDbbMMppoooollFFiillee::::cclloossee(());; iinntt DDbbMMppoooollFFiillee::::ggeett((ddbb__ppggnnoo__tt **ppggnnooaaddddrr,, uu__iinntt3322__tt ffllaaggss,, vvooiidd ****ppaaggeepp));; iinntt DDbbMMppoooollFFiillee::::ppuutt((vvooiidd **ppggaaddddrr,, uu__iinntt3322__tt ffllaaggss));; iinntt DDbbMMppoooollFFiillee::::sseett((vvooiidd **ppggaaddddrr,, uu__iinntt3322__tt ffllaaggss));; iinntt DDbbMMppoooollFFiillee::::ssyynncc(());; DDEESSCCRRIIPPTTIIOONN The DB library is a family of classes that provides a mod- ular programming interface to transactions and record-ori- ented file access. The library includes support for transactions, locking, logging and file page caching, as well as various indexed access methods. Many of the classes (e.g., the file page caching class) are useful independent of the other DB classes, although some classes are explicitly based on other classes (e.g., transactions and logging). For a general description of the DB pack- age, see _d_b___i_n_t_r_o(3). This manual page describes the specific details of the per-file memory pool interface. The _D_b_M_p_o_o_l(3) and _D_b_M_p_o_o_l_F_i_l_e(3) classes are the library interface intended to provide general-purpose, page-ori- ented buffer management of one or more files. While designed to work with the other Db functions, these func- tions are also useful for more general purposes. The mem- ory pools (_D_b_M_p_o_o_l_:_:'s) are referred to in this document as simply ``pools''. Pools may be shared between pro- cesses. Pools are usually filled by pages from one or more files (_D_b_M_p_o_o_l_F_i_l_e's). Pages in the pool are replaced in LRU (least-recently-used) order, with each new page replacing the page that has been unused the longest. Pages retrieved from the pool using _D_b_M_p_o_o_l_F_i_l_e_:_:_g_e_t are ``pinned'' in the pool, by default, until they are returned to the pool's control using the _D_b_M_p_o_o_l_F_i_l_e_:_:_p_u_t method. _D_b_M_p_o_o_l_F_i_l_e_:_:_o_p_e_n The _D_b_M_p_o_o_l_F_i_l_e_:_:_o_p_e_n method opens a file in the pool specified by the _D_b_M_p_o_o_l argument, copying the DbMpoolFile pointer representing it into the memory location refer- enced by _m_p_f. The _f_i_l_e argument is the name of the file to be opened. If _f_i_l_e is NULL, a private file is created that cannot be shared with any other process (although it may be shared with other threads). The _f_l_a_g_s and _m_o_d_e arguments specify how files will be opened and/or created when they don't already exist. The flags value is specified by oorr'ing together one or more of the following values: DB_CREATE Create any underlying files, as necessary. If the files do not already exist and the DB_CREATE flag is not specified, the call will fail. DB_NOMMAP Always copy this file into the local cache instead of mapping it into process memory (see the description of the _m_p___m_m_a_p_s_i_z_e field of the DbEnv object for fur- ther information). DB_RDONLY Open any underlying files for reading only. Any attempt to write the file using the pool functions will fail, regardless of the actual permissions of the file. All files created by the method _D_b_M_p_o_o_l_F_i_l_e_:_:_o_p_e_n are cre- ated with mode _m_o_d_e (as described in _c_h_m_o_d(2)) and modi- fied by the process' umask value at the time of creation (see _u_m_a_s_k(2)). The group ownership of created files is based on the system and directory defaults, and is not further specified by DB. The _p_a_g_e_s_i_z_e argument is the size, in bytes, of the unit of transfer between the application and the pool, although it is not necessarily the unit of transfer between the pool and the source file. Files opened in the pool may be further configured based on the _f_i_n_f_o_p argument to _m_e_m_p___f_o_p_e_n, which is a pointer to a structure of type DB_MPOOL_FINFO (typedef'd in ). No references to the _f_i_n_f_o_p structure are main- tained by DB, so it may be discarded when the _m_e_m_p___f_o_p_e_n function returns. In order to ensure compatibility with future releases of DB, all fields of the DB_MPOOL_FINFO structure that are not explicitly set should be initial- ized to 0 before the first time the structure is used. Do this by declaring the structure external or static, or by calling the C library routine _b_z_e_r_o(3) or _m_e_m_s_e_t(3). The fields of the DB_MPOOL_FINFO structure used by _D_b_M_- _p_o_o_l_F_i_l_e_:_:_o_p_e_n are described below. If _f_i_n_f_o_p is NULL or any of its fields are set to their default value, defaults appropriate for the system are used. int ftype; The _f_t_y_p_e field should be the same as a _f_t_y_p_e argu- ment previously specified to the _D_b_M_p_o_o_l_:_:_d_b___r_e_g_i_s_t_e_r method, unless no input or output processing of the file's pages are necessary, in which case it should be 0. (See the description of the _D_b_M_p_o_o_l_:_:_d_b___r_e_g_i_s_- _t_e_r method for more information.) DBT *pgcookie; The _p_g_c_o_o_k_i_e argument contains the byte string that is passed to the _p_g_i_n and _p_g_o_u_t functions for this file, if any. If no _p_g_i_n or _p_g_o_u_t functions are specified, the _p_g_c_o_o_k_i_e field should be NULL. (See the description of the _D_b_M_p_o_o_l_:_:_d_b___r_e_g_i_s_t_e_r method for more information.) u_int8_t *fileid; The _f_i_l_e_i_d field is a unique identifier for the file. The mpool functions must be able to uniquely identify files in order that multiple processes sharing a file will correctly share its underlying pages. Normally, the _f_i_l_e_i_d field should be NULL and the mpool func- tions will use the file's device and inode numbers (see _s_t_a_t(2)) for this purpose. On some filesystems, (e.g., FAT or NFS) file device and inode numbers are not necessarily unique across system reboots. AAppppllii-- ccaattiioonnss wwaannttiinngg ttoo mmaaiinnttaaiinn aa sshhaarreedd mmeemmoorryy bbuuffffeerr ppooooll aaccrroossss ssyysstteemm rreebboooottss,, wwhheerree tthhee ppooooll ccoonnttaaiinnss ppaaggeess ffrroomm ffiilleess ssttoorreedd oonn ssuucchh ffiilleessyysstteemmss,, mmuusstt ssppeecciiffyy aa uunniiqquuee ffiillee iiddeennttiiffiieerr ttoo tthhee _D_b_M_- _p_o_o_l_F_i_l_e_:_:_o_p_e_n call and each process opening or reg- istering the file must provide the same unique iden- tifier. If the _f_i_l_e_i_d field is non-NULL, it must reference a DB_FILE_ID_LEN (as defined in ) length array of bytes that will be used to uniquely identify the file. This should not be necessary for most applications. Specifically, it is not necessary if the memory pool is re-instantiated after each sys- tem reboot, the application is using the Db access methods instead of calling the pool functions explic- itly, or the files in the memory pool are stored on filesystems where the file device and inode numbers do not change across system reboots. int32_t lsn_offset; The _l_s_n___o_f_f_s_e_t argument is the zero-based byte offset in the page of the page's log sequence number (LSN), or -1 if no LSN offset is specified. (See the description of the _D_b_M_p_o_o_l_:_:_s_y_n_c method for more information.) u_int32_t clear_len; The _c_l_e_a_r___l_e_n field is the number of initial bytes in a page that should be set to zero when the page is created as a result of the DB_MPOOL_CREATE or DB_MPOOL_NEW flags being specified to _D_b_M_- _p_o_o_l_F_i_l_e_:_:_g_e_t. If _f_i_n_f_o_p is NULL or _c_l_e_a_r___l_e_n is 0, the entire page is cleared. The _D_b_M_p_o_o_l_F_i_l_e_:_:_o_p_e_n method throws a _D_b_E_x_c_e_p_t_i_o_n(3) or returns the value of _e_r_r_n_o on failure and 0 on success. _D_b_M_p_o_o_l_F_i_l_e_:_:_c_l_o_s_e The _D_b_M_p_o_o_l_F_i_l_e_:_:_c_l_o_s_e method closes the source file indi- cated by the DbMpoolFile object. This method does not imply a call to _D_b_M_p_o_o_l_F_i_l_e_:_:_s_y_n_c, i.e. no pages are writ- ten to the source file as as a result of calling _D_b_M_- _p_o_o_l_F_i_l_e_:_:_c_l_o_s_e. In addition, if the _f_i_l_e argument to _D_b_M_p_o_o_l_F_i_l_e_:_:_o_p_e_n was NULL, any underlying files created for this DbMpoolFile will be removed. The _D_b_M_p_o_o_l_F_i_l_e_:_:_c_l_o_s_e method throws a _D_b_E_x_c_e_p_t_i_o_n(3) or returns the value of _e_r_r_n_o on failure and 0 on success. _D_b_M_p_o_o_l_F_i_l_e_:_:_g_e_t The _D_b_M_p_o_o_l_F_i_l_e_:_:_g_e_t method copies a pointer to the page with the page number specified by _p_g_n_o_a_d_d_r, from the source file specified by the DbMpoolFile object into the memory location referenced by _p_a_g_e_p. If the page does not exist or cannot be retrieved, _D_b_M_p_o_o_l_F_i_l_e_:_:_g_e_t will fail. The returned page is size_t type aligned. PPaaggee nnuummbbeerrss bbeeggiinn aatt 00,, ee..gg..,, tthhee ffiirrsstt ppaaggee iinn tthhee ffiillee iiss ppaaggee nnuummbbeerr 00,, nnoott ppaaggee nnuummbbeerr 11.. The _f_l_a_g_s argument is specified by oorr'ing together one or more of the following values: DB_MPOOL_CREATE If the specified page does not exist, create it. In this case, the _p_g_i_n method, if specified, is called. DB_MPOOL_LAST Return the last page of the source file and copy its page number to the location referenced by _p_g_n_o_a_d_d_r. DB_MPOOL_NEW Create a new page in the file and copy its page num- ber to the location referenced by _p_g_n_o_a_d_d_r. In this case, the _p_g_i_n method, if specified, is not called. The DB_MPOOL_CREATE, DB_MPOOL_LAST and DB_MPOOL_NEW flags are mutually exclusive. Created pages have all their bytes set to 0, unless other- wise specified when the file was opened. All pages returned by _D_b_M_p_o_o_l_F_i_l_e_:_:_g_e_t will be retained (i.e. ``pinned'') in the pool until a subsequent call to _D_b_M_p_o_o_l_F_i_l_e_:_:_p_u_t. The _D_b_M_p_o_o_l_F_i_l_e_:_:_g_e_t method throws a _D_b_E_x_c_e_p_t_i_o_n(3) or returns the value of _e_r_r_n_o on failure and 0 on success. _D_b_M_p_o_o_l_F_i_l_e_:_:_p_u_t The _D_b_M_p_o_o_l_F_i_l_e_:_:_p_u_t method indicates that the page refer- enced by _p_g_a_d_d_r can be evicted from the pool. _P_g_a_d_d_r must be an address previously returned by _D_b_M_p_o_o_l_F_i_l_e_:_:_g_e_t. The _f_l_a_g_s argument is specified by oorr'ing together one or more of the following values: DB_MPOOL_CLEAN Clear any previously set modification information (i.e., don't bother writing the page back to the source file). DB_MPOOL_DIRTY The page has been modified and must be written to the source file before being evicted from the pool. DB_MPOOL_DISCARD The page is unlikely to be useful in the near future, and should be discarded before other pages in the pool. The DB_MPOOL_CLEAN and DB_MPOOL_DIRTY flags are mutually exclusive. The _D_b_M_p_o_o_l_F_i_l_e_:_:_p_u_t method throws a _D_b_E_x_c_e_p_t_i_o_n(3) or returns the value of _e_r_r_n_o on failure and 0 on success. _D_b_M_p_o_o_l_F_i_l_e_:_:_s_e_t The _D_b_M_p_o_o_l_F_i_l_e_:_:_s_e_t method sets the flags associated with the page referenced by _p_g_a_d_d_r without unpinning it from the pool. _P_g_a_d_d_r must be an address previously returned by _D_b_M_p_o_o_l_F_i_l_e_:_:_g_e_t. The _f_l_a_g_s argument to _D_b_M_p_o_o_l_F_i_l_e_:_:_s_e_t is specified by oorr'ing together one or more of the values specified as flags for the _D_b_M_- _p_o_o_l_F_i_l_e_:_:_p_u_t call. The _D_b_M_p_o_o_l_F_i_l_e_:_:_s_e_t method throws a _D_b_E_x_c_e_p_t_i_o_n(3) or returns the value of _e_r_r_n_o on failure and 0 on success. _D_b_M_p_o_o_l_F_i_l_e_:_:_s_y_n_c The _D_b_M_p_o_o_l_F_i_l_e_:_:_s_y_n_c method writes all pages associated with the DbMpoolFile object that were marked as modified using _D_b_M_p_o_o_l_F_i_l_e_:_:_p_u_t or _D_b_M_p_o_o_l_F_i_l_e_:_:_s_e_t, back to the source file. If any of the modified pages are also pinned (i.e., currently referenced by this or another process) _D_b_M_p_o_o_l_F_i_l_e_:_:_s_y_n_c will ignore them. The _D_b_M_p_o_o_l_F_i_l_e_:_:_s_y_n_c method throws a _D_b_E_x_c_e_p_t_i_o_n(3) or returns the value of _e_r_r_n_o on failure, 0 on success, and DB_INCOMPLETE if there were pages which were modified but which _D_b_M_p_o_o_l_F_i_l_e_:_:_s_y_n_c was unable to write. EERRRROORRSS Methods marked as returning _e_r_r_n_o will, by default, throw an exception that encapsulates the error information. The default error behavior can be changed, see _D_b_E_x_c_e_p_t_i_o_n(3). The _D_b_M_p_o_o_l_F_i_l_e_:_:_o_p_e_n method may fail and throw a _D_b_E_x_c_e_p_- _t_i_o_n(3) or return _e_r_r_n_o for any of the errors specified for the following DB and library functions: DBmemp->pgin(3), DBmemp->pgout(3), DbLog::compare(3), DbLog::flush(3), close(2), fcntl(2), fflush(3), fsync(2), lseek(2), mal- loc(3), memcmp(3), memcpy(3), memset(3), mmap(2), open(2), sigfillset(3), sigprocmask(2), stat(2), strcpy(3), strdup(3), strerror(3), strlen(3), time(3), unlink(2), and write(2). In addition, the _D_b_M_p_o_o_l_F_i_l_e_:_:_o_p_e_n method may fail and throw a _D_b_E_x_c_e_p_t_i_o_n(3) or return _e_r_r_n_o for the following conditions: [EINVAL] An invalid flag value or parameter was specified. The file has already been entered into the pool, and the _p_a_g_e_s_i_z_e value is not the same as when the file was entered into the pool, or the length of the file is not zero or a multiple of the _p_a_g_e_s_i_z_e. The DB_RDONLY flag was specified for an in-memory pool. The _D_b_M_p_o_o_l_F_i_l_e_:_:_c_l_o_s_e method may fail and throw a _D_b_E_x_- _c_e_p_t_i_o_n(3) or return _e_r_r_n_o for any of the errors specified for the following DB and library functions: close(2), fcntl(2), fflush(3), munmap(2), and strerror(3). The _D_b_M_p_o_o_l_F_i_l_e_:_:_g_e_t method may fail and throw a _D_b_E_x_c_e_p_- _t_i_o_n(3) or return _e_r_r_n_o for any of the errors specified for the following DB and library functions: DBmemp->pgin(3), DBmemp->pgout(3), DbLog::compare(3), DbLog::flush(3), close(2), fcntl(2), fflush(3), fsync(2), lseek(2), mal- loc(3), memcmp(3), memcpy(3), memset(3), mmap(2), open(2), read(2), sigfillset(3), sigprocmask(2), stat(2), str- cpy(3), strdup(3), strerror(3), strlen(3), time(3), unlink(2), and write(2). In addition, the _D_b_M_p_o_o_l_F_i_l_e_:_:_g_e_t method may fail and throw a _D_b_E_x_c_e_p_t_i_o_n(3) or return _e_r_r_n_o for the following conditions: [EAGAIN] The page reference count has overflowed. (This should never happen unless there's a bug in the application.) [EINVAL] An invalid flag value or parameter was specified. The DB_MPOOL_NEW flag was set and the source file was not opened for writing. The requested page does not exist and DB_MPOOL_CREATE was not set. More than one of DB_MPOOL_CREATE, DB_MPOOL_LAST and DB_MPOOL_NEW was set. [ENOMEM] The cache is full and no more pages will fit in the pool. The _D_b_M_p_o_o_l_F_i_l_e_:_:_p_u_t method may fail and throw a _D_b_E_x_c_e_p_- _t_i_o_n(3) or return _e_r_r_n_o for any of the errors specified for the following DB and library functions: DBmemp->pgin(3), DBmemp->pgout(3), DbLog::compare(3), DbLog::flush(3), close(2), fcntl(2), fflush(3), fsync(2), lseek(2), mal- loc(3), memcmp(3), memcpy(3), memset(3), mmap(2), open(2), sigfillset(3), sigprocmask(2), stat(2), strcpy(3), strdup(3), strerror(3), strlen(3), time(3), unlink(2), and write(2). In addition, the _D_b_M_p_o_o_l_F_i_l_e_:_:_p_u_t method may fail and throw a _D_b_E_x_c_e_p_t_i_o_n(3) or return _e_r_r_n_o for the following conditions: [EACCES] The DB_MPOOL_DIRTY flag was set and the source file was not opened for writing. [EINVAL] An invalid flag value or parameter was specified. The _p_g_a_d_d_r parameter does not reference a page returned by _D_b_M_p_o_o_l_F_i_l_e_:_:_g_e_t. More than one of DB_MPOOL_CLEAN and DB_MPOOL_DIRTY was set. The _D_b_M_p_o_o_l_F_i_l_e_:_:_s_e_t method may fail and throw a _D_b_E_x_c_e_p_- _t_i_o_n(3) or return _e_r_r_n_o for any of the errors specified for the following DB and library functions: fcntl(2), and fflush(3). In addition, the _D_b_M_p_o_o_l_F_i_l_e_:_:_s_e_t method may fail and throw a _D_b_E_x_c_e_p_t_i_o_n(3) or return _e_r_r_n_o for the following conditions: [EINVAL] An invalid flag value or parameter was specified. The _D_b_M_p_o_o_l_F_i_l_e_:_:_s_y_n_c method may fail and throw a _D_b_E_x_c_e_p_- _t_i_o_n(3) or return _e_r_r_n_o for any of the errors specified for the following DB and library functions: DBmemp->pgin(3), DBmemp->pgout(3), DbLog::compare(3), DbLog::flush(3), close(2), fcntl(2), fflush(3), fsync(2), lseek(2), mal- loc(3), memcpy(3), memset(3), open(2), qsort(3), real- loc(3), sigfillset(3), sigprocmask(2), stat(2), strcpy(3), strdup(3), strerror(3), strlen(3), unlink(2), and write(2). SSEEEE AALLSSOO _d_b___a_r_c_h_i_v_e(1), _d_b___c_h_e_c_k_p_o_i_n_t(1), _d_b___d_e_a_d_l_o_c_k(1), _d_b___d_u_m_p(1), _d_b___l_o_a_d(1), _d_b___r_e_c_o_v_e_r(1), _d_b___s_t_a_t(1), _d_b___i_n_t_r_o(3), _d_b___i_n_t_e_r_n_a_l(3), _d_b___t_h_r_e_a_d(3), _D_b(3), _D_b_c(3), _D_b_E_n_v(3), _D_b_E_x_c_e_p_t_i_o_n(3), _D_b_I_n_f_o(3), _D_b_L_o_c_k(3), _D_b_L_o_c_k_T_a_b(3), _D_b_L_o_g(3), _D_b_L_s_n(3), _D_b_M_p_o_o_l(3), _D_b_M_p_o_o_l_F_i_l_e(3), _D_b_t(3), _D_b_T_x_n(3), _D_b_T_x_n_M_g_r(3)