Classes | Macros | Typedefs | Functions
Configuration Group

The Configuration Group contains the API the gets/sets the underlying configuration of an MDBM. More...

Classes

struct  mdbm_shake_data_v3
 

Macros

#define MDBM_ALIGN_8_BITS   0x0
 1-Byte data alignment More...
 
#define MDBM_ALIGN_16_BITS   0x1
 2-Byte data alignment More...
 
#define MDBM_ALIGN_32_BITS   0x3
 4-Byte data alignment More...
 
#define MDBM_ALIGN_64_BITS   0x7
 8-Byte data alignment More...
 
#define _MDBM_MAGIC   0x01023962
 V2 file identifier. More...
 
#define _MDBM_MAGIC_NEW   0x01023963
 V2 file identifier with large objects. More...
 
#define _MDBM_MAGIC_NEW2   0x01023964
 V3 file identifier. More...
 
#define MDBM_MAGIC   _MDBM_MAGIC_NEW2
 

Typedefs

typedef int(* mdbm_shake_func_v3 )(MDBM *, const datum *, const datum *, struct mdbm_shake_data_v3 *)
 

Functions

void mdbm_stat_header (MDBM *db)
 Prints to stdout various pieces of information, specifically: page size, page count, hash function, running with or without locking. More...
 
int mdbm_get_hash (MDBM *db)
 Gets the MDBM's hash function identifier. More...
 
int mdbm_sethash (MDBM *db, int hashid)
 Sets the hashing function for a given MDBM. More...
 
int mdbm_setspillsize (MDBM *db, int size)
 Sets the size of item data value which will be put on the large-object heap rather than inline. More...
 
int mdbm_get_alignment (MDBM *db)
 Gets the MDBM's record byte-alignment. More...
 
int mdbm_set_alignment (MDBM *db, int align)
 Sets a database's byte-size alignment for keys and values within a page. More...
 
uint64_t mdbm_get_limit_size (MDBM *db)
 Gets the MDBM's size limit. More...
 
int mdbm_limit_size_v3 (MDBM *db, mdbm_ubig_t max_page, mdbm_shake_func_v3 shake, void *user)
 Limits the size of a V3 database to a maximum number of pages. More...
 
int mdbm_limit_dir_size (MDBM *db, int pages)
 Limits the internal page directory size to a number of pages. More...
 
uint32_t mdbm_get_version (MDBM *db)
 Gets the on-disk format version number of an MDBM. More...
 
uint64_t mdbm_get_size (MDBM *db)
 Gets the current MDBM's size. More...
 
int mdbm_get_page_size (MDBM *db)
 Get the MDBM's page size. More...
 
int mdbm_get_magic_number (MDBM *db, uint32_t *magic)
 Gets the magic number from an MDBM. More...
 
int mdbm_set_window_size (MDBM *db, size_t wsize)
 Sets the window size for an MDBM. More...
 

Detailed Description

The Configuration Group contains the API the gets/sets the underlying configuration of an MDBM.

Most of the commands that set the configuration must be done at MDBM-creation time.

Macro Definition Documentation

#define MDBM_ALIGN_8_BITS   0x0

1-Byte data alignment

#define MDBM_ALIGN_16_BITS   0x1

2-Byte data alignment

#define MDBM_ALIGN_32_BITS   0x3

4-Byte data alignment

#define MDBM_ALIGN_64_BITS   0x7

8-Byte data alignment

#define _MDBM_MAGIC   0x01023962

V2 file identifier.

#define _MDBM_MAGIC_NEW   0x01023963

V2 file identifier with large objects.

#define _MDBM_MAGIC_NEW2   0x01023964

V3 file identifier.

#define MDBM_MAGIC   _MDBM_MAGIC_NEW2

Typedef Documentation

typedef int(* mdbm_shake_func_v3)(MDBM *, const datum *, const datum *, struct mdbm_shake_data_v3 *)

Function Documentation

void mdbm_stat_header ( MDBM db)

Prints to stdout various pieces of information, specifically: page size, page count, hash function, running with or without locking.

NOTE: There is only a V2 implementation. V3 not currently supported.

Parameters
[in,out]dbDatabase handle
int mdbm_get_hash ( MDBM db)

Gets the MDBM's hash function identifier.

Parameters
[in,out]dbDatabase handle
Returns
Hash function identifier
Return values
MDBM_HASH_CRC32- Table based 32bit CRC
MDBM_HASH_EJB- From hsearch
MDBM_HASH_PHONG- Congruential hash
MDBM_HASH_OZ- From sdbm
MDBM_HASH_TOREK- From BerkeleyDB
MDBM_HASH_FNV- Fowler/Vo/Noll hash (DEFAULT)
MDBM_HASH_STL- STL string hash
MDBM_HASH_MD5- MD5
MDBM_HASH_SHA_1- SHA_1
MDBM_HASH_JENKINS- Jenkins string
MDBM_HASH_HSIEH- Hsieh SuperFast
int mdbm_sethash ( MDBM db,
int  hashid 
)

Sets the hashing function for a given MDBM.

The hash function must be set before storing anything to the db (this is not enforced, but entries stored before the hash change will become inaccessible if the hash function is changed).

NOTE: setting the hash must be be done at creation time, or when there is no data in an MDBM. Changing the hash function when there is existing data will result in not being able access that data in the future.

Parameters
[in,out]dbDatabase handle
[in]hashidNumeric identifier for new hash function.
Returns
Set hash status
Return values
0Error, invalid hashid
1Success

Available Hash IDs are:

  • MDBM_HASH_CRC32 - Table based 32bit CRC
  • MDBM_HASH_EJB - From hsearch
  • MDBM_HASH_PHONG - Congruential hash
  • MDBM_HASH_OZ - From sdbm
  • MDBM_HASH_TOREK - From BerkeleyDB
  • MDBM_HASH_FNV - Fowler/Vo/Noll hash (DEFAULT)
  • MDBM_HASH_STL - STL string hash
  • MDBM_HASH_MD5 - MD5
  • MDBM_HASH_SHA_1 - SHA_1
  • MDBM_HASH_JENKINS - Jenkins string
  • MDBM_HASH_HSIEH - Hsieh SuperFast
int mdbm_setspillsize ( MDBM db,
int  size 
)

Sets the size of item data value which will be put on the large-object heap rather than inline.

The spill size can be changed at any point after the db has been created. However, it's a recommended practice to set the spill size at creation time.

NOTE: The database has to be opened with the MDBM_LARGE_OBJECTS flag for spillsize to take effect.

Parameters
[in,out]dbDatabase handle
[in]sizeNew large-object threshold size
Returns
Set spill size status
Return values
-1Error, and errno is set
0Success
int mdbm_get_alignment ( MDBM db)

Gets the MDBM's record byte-alignment.

Parameters
[in,out]dbDatabase handle
Returns
Alignment mask.
Return values
0- 8-bit alignment
1- 16-bit alignment
3- 32-bit alignment
7- 64-bit alignment
int mdbm_set_alignment ( MDBM db,
int  align 
)

Sets a database's byte-size alignment for keys and values within a page.

This feature is useful for hardware/memory architectures that incur a performance penalty for unaligned accesses. Later (2006+) i386 and x86 architectures do not need special byte alignment, and should use the default of 8-bit alignment.

NOTE: setting the byte alignment must be be done at MDBM-creation time, or when there is no data in an MDBM. Changing the byte alignment when there is existing data will result in in undefined behavior and probably a crash.

Parameters
[in,out]dbDatabase handle
[in]alignAlignment mask
Returns
Alignment status
Return values
-1Error, and errno is set
0Success
uint64_t mdbm_get_limit_size ( MDBM db)

Gets the MDBM's size limit.

Returns the limit set for the size of the db using the mdbm_limit_size_v3 routine.

Parameters
[in,out]dbDatabase handle
Returns
database size limit
Return values
0No limit is set
Totalnumber of bytes for maximum database size, including header and directory
int mdbm_limit_size_v3 ( MDBM db,
mdbm_ubig_t  max_page,
mdbm_shake_func_v3  shake,
void *  user 
)

Limits the size of a V3 database to a maximum number of pages.

This function causes the MDBM to shake whenever a full page would cause the db to grow beyond the specified max number of pages. The limit size for an MDBM may be increased over time, but is may never be decreased.

Parameters
[in,out]dbDatabase handle
[in]max_pageMaximum number of data pages
[in]shakeShake function.
[in]userPointer to user data that will be passed to the shake function
Returns
Limit size status
Return values
-1Error, and errno is set
0Success
int mdbm_limit_dir_size ( MDBM db,
int  pages 
)

Limits the internal page directory size to a number of pages.

The number of pages is rounded up to a power of 2.

Parameters
[in,out]dbDatabase handle
[in]pagesNumber of data pages
Returns
Limit dir size status
Return values
-1Error, and errno is set
0Success
uint32_t mdbm_get_version ( MDBM db)

Gets the on-disk format version number of an MDBM.

Parameters
[in,out]dbDatabase handle
Returns
On-disk file format version number
Return values
2- MDBM V2
3- MDBM V3
uint64_t mdbm_get_size ( MDBM db)

Gets the current MDBM's size.

Parameters
[in,out]dbDatabase handle
Returns
Size of database in bytes.
int mdbm_get_page_size ( MDBM db)

Get the MDBM's page size.

Parameters
[in,out]dbDatabase handle
Returns
Number of bytes in a database page
int mdbm_get_magic_number ( MDBM db,
uint32_t *  magic 
)

Gets the magic number from an MDBM.

Parameters
[in,out]dbDatabase handle
[out]magicMDBM magic number (internal version identifier)
Returns
Magic number status
Return values
-3Cannot read all of the magic number
-2File is truncated (empty)
-1Cannot read file
0Magic number returned in magic
int mdbm_set_window_size ( MDBM db,
size_t  wsize 
)

Sets the window size for an MDBM.

Windowing is typically used for a very large data store where only part of it will be mapped to memory. In windowing mode, pages are accessed through a "window" to the database.

In order to use windowing mode, the page size must be a multiple of the system page size (4K on most systems). The system page size can be retrieved by calling getpagesize or sysconf(_SC_PAGESIZE).

NOTE: It is best if the minimum window size chosen is: (4*max-large-object-size + n*8*pagesize)

NOTE: API exists in MDBM V3 only, and using mdbm_set_window_size requires opening MDBM with MDBM_O_RDWR.

Parameters
[in,out]dbDatabase handle for windowed access, typically a backing store database
[in]wsizeWindow size which must be at least 4X the page size used for the database. 0 means to remove windowing
Returns
Set window status
Return values
-1Error, and errno is set
0Success