Typedefs | Functions
mdbm_handle_pool.h File Reference
#include <mdbm.h>

Go to the source code of this file.

Typedefs

typedef struct mdbm_pool_s mdbm_pool_t
 

Functions

int mdbm_pool_parse_pool_size (const char *value)
 Parse and return the configured pool size for the this process. More...
 
void mdbm_pool_verify_pool_size (int *vals, int count)
 Verifies and returns updated values for number of handles in the pool. More...
 
mdbm_pool_tmdbm_pool_create_pool (MDBM *db, int size)
 Create a pool of mdbm handles. More...
 
int mdbm_pool_destroy_pool (mdbm_pool_t *pool)
 Delete a mdbm handle pool. More...
 
MDBMmdbm_pool_acquire_handle (mdbm_pool_t *pool)
 Acquire an MDBM handle for database operations. More...
 
int mdbm_pool_release_handle (mdbm_pool_t *pool, MDBM *db)
 Release MDBM handle back to the pool. More...
 
MDBMmdbm_pool_acquire_excl_handle (mdbm_pool_t *pool)
 Acquire an exclusive MDBM handle for database operations. More...
 
int mdbm_pool_release_excl_handle (mdbm_pool_t *pool, MDBM *db)
 Release an exclusive MDBM handle. More...
 

Typedef Documentation

typedef struct mdbm_pool_s mdbm_pool_t

Function Documentation

int mdbm_pool_parse_pool_size ( const char *  value)

Parse and return the configured pool size for the this process.

Parameters
valueconfiguration setting value. The format of the value is comma (,) separated list name=value pairs where name is the application basename (e.g. yapache, yjava_daemon) and the value is the number of handles in the pool.
Returns
Number of configured number of mdbm handles for the pool
void mdbm_pool_verify_pool_size ( int *  vals,
int  count 
)

Verifies and returns updated values for number of handles in the pool.

The maximum useful size of handles is affected by both the maximum allowed number of open files (NOFILE) and the maximum number of processes (NPROC):

NOFILE limit: Each mdbm handle requires two open file entries (one for the db file and one for the lock file). Thus, if ynetdblib sees that the number of requested mdbm handles exceeds 3/4 of the maximum allowed number of open files ( determined by getrlimit(RLIMIT_NOFILE, ...), it will scale back accordingly.

NPROC limit: Since each thread requires only one mdbm handle, and not all threads need to open ynetdblib mdbm files, there is no good reason to support having as many handles as the maximum number of processes. Thus, if ynetdblib sees that the number of requested mdbm handles exceeds 3/4 of the maximum allowed number of processes (determined by getrlimit(RLIMIT_NPROC, ...) it will scale back accordingly.

Parameters
valsinteger array that includes the values to be checked. If the value is larger than the system limit as described above, the array is updated to reflect the new value
countthe number of integers in the vals array
mdbm_pool_t* mdbm_pool_create_pool ( MDBM db,
int  size 
)

Create a pool of mdbm handles.

Parameters
dbMDBM handle that will be duplicated
sizenumber of duplicated handles
Returns
pointer to newly created pool object. This object must destroyed using mdbm_pool_destroy_pool function.
int mdbm_pool_destroy_pool ( mdbm_pool_t pool)

Delete a mdbm handle pool.

Parameters
poolpointer to a pool object that was returned from calling mdbm_pool_create_pool function
Returns
1 if successful or 0 for failure.
MDBM* mdbm_pool_acquire_handle ( mdbm_pool_t pool)

Acquire an MDBM handle for database operations.

If there are no available handles in the pool, the function will block until there is one available.

Parameters
poolpointer to a pool object that was returned from calling mdbm_pool_create_pool function
Returns
pointer to MDBM handle or NULL for failure. The MDBM handle must be returned to the pool with the mdbm_pool_release_handle function
int mdbm_pool_release_handle ( mdbm_pool_t pool,
MDBM db 
)

Release MDBM handle back to the pool.

Parameters
poolpointer to a pool object that was returned from calling mdbm_pool_create_pool function
dbpointer to the MDBM handle to be released back to the pool. This pointer must have been acquired from the mdbm_pool_acquire_handle call.
Returns
1 if successful or 0 for failure.
MDBM* mdbm_pool_acquire_excl_handle ( mdbm_pool_t pool)

Acquire an exclusive MDBM handle for database operations.

The original MDBM handle that was used for duplication is returned to the caller. The function guarnatees that all of the duplicated MDBM handles are in the pool and nobody is using them.

Parameters
poolpointer to a pool object that was returned from calling mdbm_pool_create_pool function
Returns
pointer to MDBM handle or NULL for failure. The MDBM handle must be returned to the pool with the mdbm_pool_release_handle function
int mdbm_pool_release_excl_handle ( mdbm_pool_t pool,
MDBM db 
)

Release an exclusive MDBM handle.

Parameters
poolpointer to a pool object that was returned from calling mdbm_pool_create_pool function
dbpointer to the exclusive MDBM handle to be released. This pointer must have been acquired from the mdbm_pool_acquire_excl_handle call.
Returns
1 if successful or 0 for failure.