Classes | Macros | Typedefs | Enumerations | Functions | Variables
mdbm.h File Reference
#include <fcntl.h>
#include <inttypes.h>
#include <sys/types.h>
#include <time.h>
#include <stdio.h>

Go to the source code of this file.

Classes

struct  datum
 
struct  kvpair
 
struct  mdbm_iter
 
struct  mdbm_shake_data_v3
 
struct  mdbm_fetch_info
 
struct  mdbm_page_info
 
struct  mdbm_entry_info
 
struct  mdbm_iterate_info
 
struct  mdbm_clean_data
 
struct  mdbm_stats
 
struct  mdbm_db_info
 
struct  mdbm_chunk_info
 
struct  mdbm_bucket_stat
 
struct  mdbm_stat_info
 
struct  mdbm_window_stats
 
struct  mdbm_bsops
 

Macros

#define MDBM_API_VERSION   4
 
#define mdbm_big_t   int32_t
 
#define mdbm_ubig_t   uint32_t
 
#define MDBM_KEYLEN_MAX   (1<<15)
 Maximum key size. More...
 
#define MDBM_VALLEN_MAX   (1<<24)
 Maximum key size. More...
 
#define MDBM_ITER_INIT(i)   { (i)->m_pageno = 0; (i)->m_next = -1; }
 Initializes an MDBM iterator. More...
 
#define MDBM_ITER_INITIALIZER   { 0, -1 }
 MDBM iterator static initialization. More...
 
#define MDBM_LOC_NORMAL   0
 
#define MDBM_LOC_ARENA   1
 
#define MDBM_O_RDONLY   0x00000000
 Read-only access. More...
 
#define MDBM_O_WRONLY   0x00000001
 Write-only access (deprecated in V3) More...
 
#define MDBM_O_RDWR   0x00000002
 Read and write access. More...
 
#define MDBM_O_ACCMODE   (MDBM_O_RDONLY | MDBM_O_WRONLY | MDBM_O_RDWR)
 
#define MDBM_O_ASYNC   0x00000040
 Perform asynchronous writes. More...
 
#define MDBM_O_FSYNC   0x00000080
 Sync file on close. More...
 
#define MDBM_O_CREAT   0x00000200
 Create file if it does not exist. More...
 
#define MDBM_O_TRUNC   0x00000400
 Truncate file. More...
 
#define MDBM_O_DIRECT   0x00004000
 Perform direction I/O. More...
 
#define MDBM_NO_DIRTY   0x00010000
 Do not not track clean/dirty status. More...
 
#define MDBM_SINGLE_ARCH   0x00080000
 User promises not to mix 32/64-bit access. More...
 
#define MDBM_OPEN_WINDOWED   0x00100000
 Use windowing to access db. More...
 
#define MDBM_PROTECT   0x00200000
 Protect database except when locked. More...
 
#define MDBM_DBSIZE_MB   0x00400000
 Dbsize is specific in MB. More...
 
#define MDBM_STAT_OPERATIONS   0x00800000
 collect stats for fetch, store, delete More...
 
#define MDBM_LARGE_OBJECTS   0x01000000
 Support large objects - obsolete. More...
 
#define MDBM_PARTITIONED_LOCKS   0x02000000
 Partitioned locks. More...
 
#define MDBM_RW_LOCKS   0x08000000
 Read-write locks. More...
 
#define MDBM_ANY_LOCKS   0x00020000
 Open, even if existing locks don't match flags. More...
 
#define MDBM_CREATE_V3   0x20000000
 Create a V3 db. More...
 
#define MDBM_OPEN_NOLOCK   0x80000000
 Don't lock during open. More...
 
#define MDBM_DEMAND_PAGING   0x04000000
 (v2 only) More...
 
#define MDBM_DBSIZE_MB_OLD   0x04000000
 (don't use – conflicts with above) More...
 
#define MDBM_COPY_LOCK_ALL   0x01
 
#define MDBM_SAVE_COMPRESS_TREE   0x01000000 /* compress mdbm before saving */
 Compress MDBM before saving. More...
 
#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
 
#define MDBM_FETCH_FLAG_DIRTY   0x01
 Cache entry is dirty. More...
 
#define MDBM_INSERT   0
 Insert if key does not exist; fail if exists. More...
 
#define MDBM_REPLACE   1
 Update if key exists; insert if does not exist. More...
 
#define MDBM_INSERT_DUP   2
 Insert new record (creates duplicate if key exists) More...
 
#define MDBM_MODIFY   3
 Update if key exists; fail if does not exist. More...
 
#define MDBM_STORE_MASK   0x3
 Mask for all store options. More...
 
#define MDBM_STORE_MODE(f)   ((f) & MDBM_STORE_MASK)
 Extract the store mode from an options mask. More...
 
#define MDBM_RESERVE   0x100
 Reserve space; Value not copied. More...
 
#define MDBM_CLEAN   0x200
 Mark entry as clean. More...
 
#define MDBM_CACHE_ONLY   0x400
 Do not operate on the backing store; use cache only. More...
 
#define MDBM_CACHE_REPLACE   0
 Update cache if key exists; insert if does not exist. More...
 
#define MDBM_CACHE_MODIFY   0x1000
 Update cache if key exists; do not insert if does not. More...
 
#define MDBM_CACHE_UPDATE_MODE(f)   ((f) & MDBM_CACHE_MODIFY)
 
#define MDBM_STORE_SUCCESS   0
 Returned if store succeeds. More...
 
#define MDBM_STORE_ENTRY_EXISTS   1
 Returned if MDBM_INSERT used and key exists. More...
 
#define MDBM_ENTRY_DELETED   0x1
 
#define MDBM_ENTRY_LARGE_OBJECT   0x2
 
#define MDBM_ITERATE_ENTRIES   0x01
 Iterate over page entries. More...
 
#define MDBM_ITERATE_NOLOCK   0x80
 Iterate without locking. More...
 
#define MDBM_LOCKMODE_UNKNOWN   0xFFFFFFFF
 Returned by mdbm_get_lockmode for an unknown lock mode (MDBM V2). More...
 
#define MDBM_LOCKMODE_UNKNOWN   0xFFFFFFFF
 Returned by mdbm_get_lockmode for an unknown lock mode (MDBM V2). More...
 
#define MDBM_SAVE_COMPRESS_TREE   0x01000000
 Compress MDBM before saving. More...
 
#define MDBM_CHECK_HEADER   0
 Check MDBM header for integrity. More...
 
#define MDBM_CHECK_CHUNKS   1
 Check MDBM header and chunks (page structure) More...
 
#define MDBM_CHECK_DIRECTORY   2
 Check MDBM header, chunks, and directory. More...
 
#define MDBM_CHECK_ALL   3
 Check MDBM header, chunks, directory, and data. More...
 
#define MDBM_PROT_NONE   0
 Page no access. More...
 
#define MDBM_PROT_READ   1
 Page read access. More...
 
#define MDBM_PROT_WRITE   2
 Page write access. More...
 
#define MDBM_PROT_NOACCESS   MDBM_PROT_NONE
 Page no access. More...
 
#define MDBM_PROT_ACCESS   4
 Page protection mask. More...
 
#define MDBM_CLOCK_STANDARD   0
 
#define MDBM_CLOCK_TSC   1
 
#define MDBM_STATS_BASIC   0x1
 Basic stats only. More...
 
#define MDBM_STATS_TIMED   0x2
 SLOW! Stats that call get-time functions. More...
 
#define MDBM_STAT_CB_INC   0x0
 Basic stat. More...
 
#define MDBM_STAT_CB_SET   0x1
 Basic stat. More...
 
#define MDBM_STAT_CB_ELAPSED   0x2
 Value is a time delta. More...
 
#define MDBM_STAT_CB_TIME   0x3
 Value is the stat time. More...
 
#define COMBINE_STAT_TAG(tag, flag)   (tag | (flag<<16))
 
#define MDBM_STAT_TAG_FETCH   1 /* Successful fetch stats-callback counter */
 The various stats metrics (tags): All time/latency related stats (defined below) require: mdbm_set_stats_func(db, flags|MDBM_STAT_CB_TIME, ...) More...
 
#define MDBM_STAT_TAG_STORE   2 /* Successful store stats-callback counter */
 
#define MDBM_STAT_TAG_DELETE   3 /* Successful delete stats-callback counter */
 
#define MDBM_STAT_TAG_LOCK   4 /* lock stats-callback counter (not implemented) */
 
#define MDBM_STAT_TAG_FETCH_UNCACHED   5 /* Cache-miss with cache+backingstore */
 
#define MDBM_STAT_TAG_GETPAGE   6 /* Generic access counter in windowed mode */
 
#define MDBM_STAT_TAG_GETPAGE_UNCACHED   7 /* Windowed-mode "miss" (load new page into window) */
 
#define MDBM_STAT_TAG_CACHE_EVICT   8 /* Cache evict stats-callback counter */
 
#define MDBM_STAT_TAG_CACHE_STORE   9 /* Successful cache store counter (BS only) */
 
#define MDBM_STAT_TAG_PAGE_STORE   10 /* Successful page-level store indicator */
 
#define MDBM_STAT_TAG_PAGE_DELETE   11 /* Successful page-level delete indicator */
 
#define MDBM_STAT_TAG_SYNC   12 /* Counter of mdbm_syncs and fsyncs */
 
#define MDBM_STAT_TAG_FETCH_NOT_FOUND   13 /* Fetch cannot find a key in MDBM */
 
#define MDBM_STAT_TAG_FETCH_ERROR   14 /* Error occurred during fetch */
 
#define MDBM_STAT_TAG_STORE_ERROR   15 /* Error occurred during store (e.g. MODIFY failed) */
 
#define MDBM_STAT_TAG_DELETE_FAILED   16 /* Delete failed: cannot find a key in MDBM */
 
#define MDBM_STAT_TAG_FETCH_LATENCY   COMBINE_STAT_TAG(MDBM_STAT_TAG_FETCH, MDBM_STAT_CB_ELAPSED)
 Fetch latency (expensive to collect) More...
 
#define MDBM_STAT_TAG_STORE_LATENCY   COMBINE_STAT_TAG(MDBM_STAT_TAG_STORE, MDBM_STAT_CB_ELAPSED)
 Store latency (expensive to collect) More...
 
#define MDBM_STAT_TAG_DELETE_LATENCY   COMBINE_STAT_TAG(MDBM_STAT_TAG_DELETE, MDBM_STAT_CB_ELAPSED)
 Delete latency (expensive to collect) More...
 
#define MDBM_STAT_TAG_FETCH_TIME   COMBINE_STAT_TAG(MDBM_STAT_TAG_FETCH, MDBM_STAT_CB_TIME)
 timestamp of last fetch (not yet implemented) More...
 
#define MDBM_STAT_TAG_STORE_TIME   COMBINE_STAT_TAG(MDBM_STAT_TAG_STORE, MDBM_STAT_CB_TIME)
 timestamp of last store (not yet implemented) More...
 
#define MDBM_STAT_TAG_DELETE_TIME   COMBINE_STAT_TAG(MDBM_STAT_TAG_DELETE, MDBM_STAT_CB_TIME)
 timestamp of last delete (not yet implemented) More...
 
#define MDBM_STAT_TAG_FETCH_UNCACHED_LATENCY   COMBINE_STAT_TAG(MDBM_STAT_TAG_FETCH_UNCACHED, MDBM_STAT_CB_ELAPSED)
 Cache miss latency for cache+Backingstore only (expensive to collect) More...
 
#define MDBM_STAT_TAG_GETPAGE_LATENCY   COMBINE_STAT_TAG(MDBM_STAT_TAG_GETPAGE, MDBM_STAT_CB_ELAPSED)
 access latency in windowed mode (expensive to collect) More...
 
#define MDBM_STAT_TAG_GETPAGE_UNCACHED_LATENCY   COMBINE_STAT_TAG(MDBM_STAT_TAG_GETPAGE_UNCACHED, MDBM_STAT_CB_ELAPSED)
 windowed-mode miss latency (expensive to collect) More...
 
#define MDBM_STAT_TAG_CACHE_EVICT_LATENCY   COMBINE_STAT_TAG(MDBM_STAT_TAG_CACHE_EVICT, MDBM_STAT_CB_ELAPSED)
 cache evict latency (expensive to collect) More...
 
#define MDBM_STAT_TAG_CACHE_STORE_LATENCY   COMBINE_STAT_TAG(MDBM_STAT_TAG_CACHE_STORE, MDBM_STAT_CB_ELAPSED)
 Cache store latency in Cache+backingstore mode only (expensive to collect) More...
 
#define MDBM_STAT_TAG_PAGE_STORE_VALUE   COMBINE_STAT_TAG(MDBM_STAT_TAG_PAGE_STORE, MDBM_STAT_CB_SET)
 Indicates a store occurred on a particular page. More...
 
#define MDBM_STAT_TAG_PAGE_DELETE_VALUE   COMBINE_STAT_TAG(MDBM_STAT_TAG_PAGE_DELETE, MDBM_STAT_CB_SET)
 Indicates a delete occurred on a particular page. More...
 
#define MDBM_STAT_TAG_SYNC_LATENCY   COMBINE_STAT_TAG(MDBM_STAT_TAG_SYNC, MDBM_STAT_CB_ELAPSED)
 mdbm_sync/fsync latency (expensive to collect) More...
 
#define MDBM_STAT_DELETED   0x1
 Deprecated. More...
 
#define MDBM_STAT_KEYS   0x2
 Deprecated. More...
 
#define MDBM_STAT_VALUES   0x4
 Deprecated. More...
 
#define MDBM_STAT_PAGES_ONLY   0x8
 Deprecated. More...
 
#define MDBM_STAT_NOLOCK   0x80
 Do not lock for stat operation. More...
 
#define MDBM_STAT_BUCKETS   20
 Number of buckets for stat histograms. More...
 
#define MDBM_CACHEMODE_NONE   0
 No caching behavior. More...
 
#define MDBM_CACHEMODE_LFU   1
 Entry with smallest number of accesses is evicted. More...
 
#define MDBM_CACHEMODE_LRU   2
 Entry with oldest access time is evicted. More...
 
#define MDBM_CACHEMODE_GDSF   3
 Greedy dual-size frequency (size and frequency) eviction. More...
 
#define MDBM_CACHEMODE_MAX   3
 Maximum cache mode value. More...
 
#define MDBM_CACHEMODE_EVICT_CLEAN_FIRST   0x10
 add to cachemode to evict clean items 1st More...
 
#define MDBM_CACHEMODE(m)   ((m)&3)
 Extracts cache mode. More...
 
#define MDBM_CACHEMODE_BITS   (3 | MDBM_CACHEMODE_EVICT_CLEAN_FIRST)
 Defines a mask for the cache mode, including control (eviction) bit. More...
 
#define MDBM_BSOPS_FILE   ((const mdbm_bsops_t*)-1)
 Backing store File identifier. More...
 
#define MDBM_BSOPS_MDBM   ((const mdbm_bsops_t*)-2)
 Backing store MDBM identifier. More...
 
#define MDBM_MINPAGE   128
 Size should be >= header, but this cuts off header stats, which is ok. More...
 
#define MDBM_PAGE_ALIGN   64
 
#define MDBM_MAXPAGE   ((16*1024*1024) - MDBM_PAGE_ALIGN)
 
#define MDBM_PAGESIZ   4096
 A good default. More...
 
#define MDBM_MIN_PSHIFT   7
 this must match MDBM_MINPAGE above More...
 
#define MDBM_MAX_SHIFT   ((sizeof( void * )*8)-1)
 Base # shifts on ptr size. More...
 
#define WHATSTR(X)   static const char what[] = X
 
#define MDBM_HASH_CRC32   0
 table based 32bit crc More...
 
#define MDBM_HASH_EJB   1
 from hsearch More...
 
#define MDBM_HASH_PHONG   2
 congruential hash More...
 
#define MDBM_HASH_OZ   3
 from sdbm More...
 
#define MDBM_HASH_TOREK   4
 from Berkeley db More...
 
#define MDBM_HASH_FNV   5
 Fowler/Vo/Noll hash. More...
 
#define MDBM_HASH_STL   6
 STL string hash. More...
 
#define MDBM_HASH_MD5   7
 MD5. More...
 
#define MDBM_HASH_SHA_1   8
 SHA_1. More...
 
#define MDBM_HASH_JENKINS   9
 JENKINS. More...
 
#define MDBM_HASH_HSIEH   10
 HSIEH SuperFastHash. More...
 
#define MDBM_MAX_HASH   10 /* bump up if adding more */
 
#define MDBM_DEFAULT_HASH   5 /* MDBM_HASH_FNV is best */
 Define the hash function to use on a newly created file. More...
 
#define MDBM_CONFIG_DEFAULT_HASH   MDBM_HASH_FNV
 
#define MDBM_BAD_HASH_NO(n)   ((n) < 0 || (n) > MDBM_MAX_HASH)
 
#define MDBM_HASH_MAX   MDBM_MAX_HASH
 

Typedefs

typedef struct mdbm_iter MDBM_ITER
 
typedef struct mdbm MDBM
 
typedef int(* mdbm_shake_func_v3 )(MDBM *, const datum *, const datum *, struct mdbm_shake_data_v3 *)
 
typedef struct mdbm_page_info mdbm_page_info_t
 
typedef struct mdbm_entry_info mdbm_entry_info_t
 
typedef struct mdbm_iterate_info mdbm_iterate_info_t
 
typedef int(* mdbm_iterate_func_t )(void *user, const mdbm_iterate_info_t *info, const kvpair *kv)
 
typedef int(* mdbm_clean_func )(MDBM *, const datum *, const datum *, struct mdbm_clean_data *, int *quit)
 
typedef struct mdbm_stats mdbm_stats_t
 
typedef uint64_t mdbm_counter_t
 
typedef void(* mdbm_stat_cb )(MDBM *db, int tag, int flags, uint64_t value, void *user)
 The general stats callback function definition. More...
 
typedef struct mdbm_db_info mdbm_db_info_t
 
typedef struct mdbm_chunk_info mdbm_chunk_info_t
 
typedef int(* mdbm_chunk_iterate_func_t )(void *user, const mdbm_chunk_info_t *info)
 
typedef struct mdbm_bucket_stat mdbm_bucket_stat_t
 
typedef struct mdbm_stat_info mdbm_stat_info_t
 
typedef struct mdbm_window_stats mdbm_window_stats_t
 
typedef struct mdbm_bsops mdbm_bsops_t
 
typedef uint32_t mdbm_hashval_t
 

Enumerations

enum  mdbm_stat_type { MDBM_STAT_TYPE_FETCH = 0, MDBM_STAT_TYPE_STORE = 1, MDBM_STAT_TYPE_DELETE = 2, MDBM_STAT_TYPE_MAX = MDBM_STAT_TYPE_DELETE }
 
enum  { MDBM_PTYPE_FREE = 0, MDBM_PTYPE_DATA = 1, MDBM_PTYPE_DIR = 2, MDBM_PTYPE_LOB = 3 }
 

Functions

MDBMmdbm_open (const char *file, int flags, int mode, int psize, int presize)
 Creates and/or opens a database. More...
 
void mdbm_close (MDBM *db)
 Closes the database. More...
 
void mdbm_close_fd (MDBM *db)
 Closes an MDBM's underlying file descriptor. More...
 
MDBMmdbm_dup_handle (MDBM *db, int flags)
 Duplicate an existing database handle. More...
 
int mdbm_sync (MDBM *db)
 msync's all pages to disk asynchronously. More...
 
int mdbm_fsync (MDBM *db)
 fsync's an MDBM. More...
 
int mdbm_replace_db (MDBM *db, const char *newfile)
 Atomically replaces the database currently in oldfile db with the new database in newfile. More...
 
int mdbm_replace_file (const char *oldfile, const char *newfile)
 Atomically replaces an old database in oldfile with a new database in newfile. More...
 
int mdbm_pre_split (MDBM *db, mdbm_ubig_t N)
 Forces a db to split, creating N pages. More...
 
int mdbm_fcopy (MDBM *db, int fd, int flags)
 Copies the contents of a database to an open file handle. More...
 
int mdbm_save (MDBM *db, const char *file, int flags, int mode, int compressionLevel)
 DEPRECATED!! mdbm_save is only supported for V2 MDBMs. More...
 
int mdbm_restore (MDBM *db, const char *file)
 DEPRECATED!! mdbm_restore is only supported for V2 MDBMs. More...
 
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...
 
datum mdbm_fetch (MDBM *db, datum key)
 Fetches the record specified by the key argument and returns a datum that points to the value. More...
 
int mdbm_fetch_r (MDBM *db, datum *key, datum *val, MDBM_ITER *iter)
 Fetches the record specified by the key argument. More...
 
int mdbm_fetch_buf (MDBM *db, datum *key, datum *val, datum *buf, int flags)
 Fetches and copies the record specified by the key argument. More...
 
int mdbm_fetch_dup_r (MDBM *db, datum *key, datum *val, MDBM_ITER *iter)
 Fetches the next value for a key inserted via mdbm_store_r with the MDBM_INSERT_DUP flag set. More...
 
char * mdbm_fetch_str (MDBM *db, const char *key)
 Fetches a string. More...
 
int mdbm_fetch_info (MDBM *db, datum *key, datum *val, datum *buf, struct mdbm_fetch_info *info, MDBM_ITER *iter)
 Fetches and copies the record specified by the key argument. More...
 
int mdbm_delete (MDBM *db, datum key)
 Deletes a specific record. More...
 
int mdbm_delete_r (MDBM *db, MDBM_ITER *iter)
 Deletes the record currently addressed by the iter argument. More...
 
int mdbm_delete_str (MDBM *db, const char *key)
 Deletes a string from the MDBM. More...
 
int mdbm_store (MDBM *db, datum key, datum val, int flags)
 This is a wrapper around mdbm_store_r, with a static iterator. More...
 
int mdbm_store_r (MDBM *db, datum *key, datum *val, int flags, MDBM_ITER *iter)
 Stores the record specified by the key and val parameters. More...
 
int mdbm_store_str (MDBM *db, const char *key, const char *val, int flags)
 Stores a string into the MDBM. More...
 
kvpair mdbm_first (MDBM *db)
 Returns the first key/value pair from the database. More...
 
kvpair mdbm_first_r (MDBM *db, MDBM_ITER *iter)
 Fetches the first record in an MDBM. More...
 
kvpair mdbm_next (MDBM *db)
 Returns the next key/value pair from the database. More...
 
kvpair mdbm_next_r (MDBM *db, MDBM_ITER *iter)
 Fetches the next record in an MDBM. More...
 
datum mdbm_firstkey (MDBM *db)
 Returns the first key from the database. More...
 
datum mdbm_firstkey_r (MDBM *db, MDBM_ITER *iter)
 Fetches the first key in an MDBM. More...
 
datum mdbm_nextkey (MDBM *db)
 Returns the next key pair from the database. More...
 
datum mdbm_nextkey_r (MDBM *db, MDBM_ITER *iter)
 Fetches the next key in an MDBM. More...
 
int mdbm_iterate (MDBM *db, int pagenum, mdbm_iterate_func_t func, int flags, void *user)
 Iterates through all keys starting on page pagenum and continuing through the rest of the database. More...
 
int mdbm_islocked (MDBM *db)
 Returns whether or not MDBM is locked by another process or thread (thread: V3 only). More...
 
int mdbm_isowned (MDBM *db)
 Returns whether or not MDBM is currently locked (owned) by the calling process. More...
 
uint32_t mdbm_get_lockmode (MDBM *db)
 Gets the MDBM's lock mode. More...
 
int mdbm_lock (MDBM *db)
 Locks the database for exclusive access by the caller. More...
 
int mdbm_unlock (MDBM *db)
 Unlocks the database, releasing exclusive or shared access by the caller. More...
 
int mdbm_trylock (MDBM *db)
 Attempts to exclusively lock an MDBM. More...
 
int mdbm_plock (MDBM *db, const datum *key, int flags)
 Locks a specific partition in the database for exclusive access by the caller. More...
 
int mdbm_punlock (MDBM *db, const datum *key, int flags)
 Unlocks a specific partition in the database, releasing exclusive access by the caller. More...
 
int mdbm_tryplock (MDBM *db, const datum *key, int flags)
 Tries to locks a specific partition in the database for exclusive access by the caller. More...
 
int mdbm_lock_shared (MDBM *db)
 Locks the database for shared access by readers, excluding access to writers. More...
 
int mdbm_trylock_shared (MDBM *db)
 Locks the database for shared access by readers, excluding access to writers. More...
 
int mdbm_lock_smart (MDBM *db, const datum *key, int flags)
 Perform either partition, shared or exclusive locking based on the locking-related flags supplied to mdbm_open. More...
 
int mdbm_trylock_smart (MDBM *db, const datum *key, int flags)
 Attempts to lock an MDBM based on the locking flags supplied to mdbm_open. More...
 
int mdbm_unlock_smart (MDBM *db, const datum *key, int flags)
 Unlock an MDBM based on the locking flags supplied to mdbm_open. More...
 
int mdbm_lock_reset (const char *dbfilename, int flags)
 Resets the global lock ownership state of a database. More...
 
int mdbm_delete_lockfiles (const char *dbname)
 Removes all lockfiles associated with an MDBM file. More...
 
void mdbm_compress_tree (MDBM *db)
 Compresses the existing MDBM directory. More...
 
void mdbm_truncate (MDBM *db)
 Truncates the MDBM to single empty page. More...
 
void mdbm_prune (MDBM *db, int(*prune)(MDBM *, datum, datum, void *), void *param)
 Prunes an MDBM. More...
 
void mdbm_purge (MDBM *db)
 Purges (removes) all entries from an MDBM. More...
 
int mdbm_set_cleanfunc (MDBM *db, mdbm_clean_func func, void *data)
 The specified cleaner function will be called by mdbm_clean. More...
 
int mdbm_clean (MDBM *db, int pagenum, int flags)
 Mark entries clean/re-usable in the database for the specified page. More...
 
int mdbm_check (MDBM *db, int level, int verbose)
 Checks an MDBM's integrity, and displays information on standard output. More...
 
void mdbm_chk_error (MDBM *db, int pagenum, int mapped_pagenum, int index)
 Checks integrity of an entry on a page. More...
 
int mdbm_chk_page (MDBM *db, int pagenum)
 Checks the specified page for errors. More...
 
int mdbm_chk_all_page (MDBM *db)
 Checks the database for errors. More...
 
int mdbm_protect (MDBM *db, int protect)
 Sets all database pages to protect permission. More...
 
void mdbm_dump_all_page (MDBM *db)
 Dumps information for all pages, in version-specific format, to standard output. More...
 
void mdbm_dump_page (MDBM *db, int pno)
 Dumps specified page's information, in version-specific format, to standard output. More...
 
int mdbm_get_stat_counter (MDBM *db, mdbm_stat_type type, mdbm_counter_t *value)
 Gets the number of operations performed for a stat type. More...
 
int mdbm_get_stat_time (MDBM *db, mdbm_stat_type type, time_t *value)
 Gets the last time when an type operation was performed. More...
 
void mdbm_reset_stat_operations (MDBM *db)
 Resets the stat counter and last-time performed for fetch, store, and remove operations. More...
 
int mdbm_enable_stat_operations (MDBM *db, int flags)
 Enables and disables gathering of stat counters and/or last-time performed for fetch, store, and remove operations. More...
 
int mdbm_set_stat_time_func (MDBM *db, int flags)
 Tells the MDBM library whether to use TSC (CPU TimeStamp Counters) for timing the performance of fetch, store and delete operations. More...
 
const char * mdbm_get_stat_name (int tag)
 Gets the name of a stat. More...
 
int mdbm_set_stats_func (MDBM *db, int flags, mdbm_stat_cb cb, void *user)
 Sets the callback function for a stat. More...
 
void mdbm_stat_all_page (MDBM *db)
 Prints to stdout various pieces of information, specifically: Total mapped db size, Total number of entries, ADDRESS SPACE page efficiency, ADDRESS SPACE byte efficiency, PHYSICAL MEM/DISK SPACE efficiency, Average bytes per record, Maximum B-tree level, Minimum B-tree level, Minimum free bytes on page, Minimum free bytes on page post compress. More...
 
int mdbm_get_stats (MDBM *db, mdbm_stats_t *s, size_t stats_size)
 Gets a a stats block with individual stat values. More...
 
int mdbm_get_db_info (MDBM *db, mdbm_db_info_t *info)
 Gets configuration information about a database. More...
 
int mdbm_chunk_iterate (MDBM *db, mdbm_chunk_iterate_func_t func, int flags, void *user)
 Iterates over all pages (starting at page 0). More...
 
int mdbm_get_db_stats (MDBM *db, mdbm_db_info_t *info, mdbm_stat_info_t *stats, int flags)
 Gets overall database stats. More...
 
int mdbm_get_window_stats (MDBM *db, mdbm_window_stats_t *stats, size_t s_size)
 Used to retrieve statistics about windowing usage on the associated database. More...
 
uint64_t mdbm_count_records (MDBM *db)
 Counts the number of records in an MDBM. More...
 
mdbm_ubig_t mdbm_count_pages (MDBM *db)
 Counts the number of pages used by an MDBM. More...
 
int mdbm_set_cachemode (MDBM *db, int cachemode)
 Manage the database as a cache. More...
 
int mdbm_get_cachemode (MDBM *db)
 Returns the current cache style of the database. More...
 
const char * mdbm_get_cachemode_name (int cachemode)
 Returns the cache mode as a string. More...
 
int mdbm_set_backingstore (MDBM *cachedb, const mdbm_bsops_t *bsops, void *opt, int flags)
 The backing-store support controls the in-memory cache as a read-through, write-through cache. More...
 
int mdbm_cdbdump_to_file (kvpair kv, FILE *fp)
 Export API: Use cdb_dump format to write a key/value pair to file opened with fopen. More...
 
int mdbm_cdbdump_trailer_and_close (FILE *fp)
 Export API: Finalize and close a file written in cdb_dump format and opened with fopen. More...
 
int mdbm_cdbdump_add_record (kvpair kv, uint32_t *datasize, char **bufptr, uint32_t *bufsize, uint32_t buf_offset)
 Export API: Use cdb_dump format to write a key/value pair to a malloc'd buffer. More...
 
int mdbm_dbdump_to_file (kvpair kv, FILE *fp)
 Export API: Use db_dump format to write a key/value pair to a file opened with fopen. More...
 
int mdbm_dbdump_trailer_and_close (FILE *fp)
 Export API: Finalize and close a file written in db_dump format and opened with fopen. More...
 
int mdbm_dbdump_add_record (kvpair kv, uint32_t *datasize, char **bufptr, uint32_t *bufsize, uint32_t buf_offset)
 Export API: Use db_dump format to write a key/value pair to a malloc'd buffer. More...
 
int mdbm_dbdump_export_header (MDBM *db, FILE *fp)
 Export API: Write the DBdump header to FILE. More...
 
int mdbm_dbdump_import_header (FILE *fp, int *pgsize, int *pgcount, int *large, uint32_t *lineno)
 Import API: Read the DBdump header from FILE Function will set, if available at the beginning of the file pointed to by "fp", the following parameter values: More...
 
int mdbm_dbdump_import (MDBM *db, FILE *fp, const char *input_file, int store_flag, uint32_t *lineno)
 Import API: Read data from FILE into MDBM, using DBdump format. More...
 
int mdbm_cdbdump_import (MDBM *db, FILE *fp, const char *input_file, int store_flag)
 Import API: Read data from FILE into MDBM, using Cdb format. More...
 
int mdbm_get_errno (MDBM *db)
 Returns the value of internally saved errno. More...
 
int mdbm_get_hash_value (datum key, int hashFunctionCode, uint32_t *hashValue)
 Given a hash function code, get the hash value for the given key. More...
 
mdbm_ubig_t mdbm_get_page (MDBM *db, const datum *key)
 Gets the MDBM page number for a given key. More...
 
int mdbm_preload (MDBM *db)
 Preload mdbm: Read every 4k bytes to force all pages into memory. More...
 
int mdbm_lock_pages (MDBM *db)
 mdbm_lock_pages: Locks MDBM data pages into memory. More...
 
int mdbm_unlock_pages (MDBM *db)
 mdbm_unlock_pages: Releases MDBM data pages from always staying in memory More...
 
void mdbm_lock_dump (MDBM *db)
 
typedef mdbm_ubig_t ((*mdbm_hash_t)(const uint8_t *buf, int len))
 
mdbm_ubig_t mdbm_hash (unsigned char *, int)
 
mdbm_ubig_t mdbm_hash0 (unsigned char *, int)
 
mdbm_ubig_t mdbm_hash1 (unsigned char *, int)
 
mdbm_ubig_t mdbm_hash2 (unsigned char *, int)
 
mdbm_ubig_t mdbm_hash3 (unsigned char *, int)
 
mdbm_ubig_t mdbm_hash4 (unsigned char *, int)
 
mdbm_ubig_t mdbm_hash5 (unsigned char *, int)
 
mdbm_ubig_t mdbm_hash6 (unsigned char *, int)
 

Variables

mdbm_hash_t mdbm_hash_funcs []
 

Macro Definition Documentation

#define MDBM_API_VERSION   4
#define mdbm_big_t   int32_t
#define mdbm_ubig_t   uint32_t
#define MDBM_KEYLEN_MAX   (1<<15)

Maximum key size.

#define MDBM_VALLEN_MAX   (1<<24)

Maximum key size.

#define MDBM_ITER_INIT (   i)    { (i)->m_pageno = 0; (i)->m_next = -1; }

Initializes an MDBM iterator.

Parameters
[in]iL-Value reference Usage: MDBM_ITER_INIT (MDBM_ITER *i);
#define MDBM_ITER_INITIALIZER   { 0, -1 }

MDBM iterator static initialization.

#define MDBM_LOC_NORMAL   0
#define MDBM_LOC_ARENA   1
#define MDBM_MINPAGE   128

Size should be >= header, but this cuts off header stats, which is ok.

#define MDBM_PAGE_ALIGN   64
#define MDBM_MAXPAGE   ((16*1024*1024) - MDBM_PAGE_ALIGN)
#define MDBM_PAGESIZ   4096

A good default.

Size should be >= header

#define MDBM_MIN_PSHIFT   7

this must match MDBM_MINPAGE above

#define MDBM_MAX_SHIFT   ((sizeof( void * )*8)-1)

Base # shifts on ptr size.

#define WHATSTR (   X)    static const char what[] = X
#define MDBM_HASH_CRC32   0

table based 32bit crc

#define MDBM_HASH_EJB   1

from hsearch

#define MDBM_HASH_PHONG   2

congruential hash

#define MDBM_HASH_OZ   3

from sdbm

#define MDBM_HASH_TOREK   4

from Berkeley db

#define MDBM_HASH_FNV   5

Fowler/Vo/Noll hash.

#define MDBM_HASH_STL   6

STL string hash.

#define MDBM_HASH_MD5   7

MD5.

#define MDBM_HASH_SHA_1   8

SHA_1.

#define MDBM_HASH_JENKINS   9

JENKINS.

#define MDBM_HASH_HSIEH   10

HSIEH SuperFastHash.

#define MDBM_MAX_HASH   10 /* bump up if adding more */
#define MDBM_DEFAULT_HASH   5 /* MDBM_HASH_FNV is best */

Define the hash function to use on a newly created file.

#define MDBM_CONFIG_DEFAULT_HASH   MDBM_HASH_FNV
#define MDBM_BAD_HASH_NO (   n)    ((n) < 0 || (n) > MDBM_MAX_HASH)
#define MDBM_HASH_MAX   MDBM_MAX_HASH

Typedef Documentation

typedef struct mdbm_iter MDBM_ITER
typedef struct mdbm MDBM
typedef uint32_t mdbm_hashval_t

Function Documentation

void mdbm_lock_dump ( MDBM db)
typedef mdbm_ubig_t ( (*)(const uint8_t *buf, int len)  mdbm_hash_t)
mdbm_ubig_t mdbm_hash ( unsigned char *  ,
int   
)
mdbm_ubig_t mdbm_hash0 ( unsigned char *  ,
int   
)
mdbm_ubig_t mdbm_hash1 ( unsigned char *  ,
int   
)
mdbm_ubig_t mdbm_hash2 ( unsigned char *  ,
int   
)
mdbm_ubig_t mdbm_hash3 ( unsigned char *  ,
int   
)
mdbm_ubig_t mdbm_hash4 ( unsigned char *  ,
int   
)
mdbm_ubig_t mdbm_hash5 ( unsigned char *  ,
int   
)
mdbm_ubig_t mdbm_hash6 ( unsigned char *  ,
int   
)

Variable Documentation

mdbm_hash_t mdbm_hash_funcs[]