81 #define MDBM_API_VERSION 4
85 #include <sys/types.h>
153 #define mdbm_big_t int32_t
154 #define mdbm_ubig_t uint32_t
158 #define ubig uint64_t
161 #define ubig uint32_t
178 #define MDBM_KEYLEN_MAX (1<<15)
179 #define MDBM_VALLEN_MAX (1<<24)
193 #define MDBM_ITER_INIT(i) { (i)->m_pageno = 0; (i)->m_next = -1; }
195 #define MDBM_ITER_INITIALIZER { 0, -1 }
197 #define MDBM_LOC_NORMAL 0
198 #define MDBM_LOC_ARENA 1
213 #define MDBM_O_RDONLY 0x00000000
214 #define MDBM_O_WRONLY 0x00000001
215 #define MDBM_O_RDWR 0x00000002
216 #define MDBM_O_ACCMODE (MDBM_O_RDONLY | MDBM_O_WRONLY | MDBM_O_RDWR)
219 #define MDBM_O_CREAT 0x00000040
220 #define MDBM_O_TRUNC 0x00000200
221 #define MDBM_O_FSYNC 0x00001000
222 #define MDBM_O_ASYNC 0x00002000
224 #define MDBM_O_ASYNC 0x00000040
225 #define MDBM_O_FSYNC 0x00000080
226 #define MDBM_O_CREAT 0x00000200
227 #define MDBM_O_TRUNC 0x00000400
229 #define MDBM_O_DIRECT 0x00004000
231 #define MDBM_NO_DIRTY 0x00010000
232 #define MDBM_SINGLE_ARCH 0x00080000
233 #define MDBM_OPEN_WINDOWED 0x00100000
234 #define MDBM_PROTECT 0x00200000
235 #define MDBM_DBSIZE_MB 0x00400000
236 #define MDBM_STAT_OPERATIONS 0x00800000
237 #define MDBM_LARGE_OBJECTS 0x01000000
238 #define MDBM_PARTITIONED_LOCKS 0x02000000
239 #define MDBM_RW_LOCKS 0x08000000
240 #define MDBM_ANY_LOCKS 0x00020000
242 #define MDBM_CREATE_V3 0x20000000
244 #define MDBM_OPEN_NOLOCK 0x80000000
246 #define MDBM_DEMAND_PAGING 0x04000000
247 #define MDBM_DBSIZE_MB_OLD 0x04000000
252 #if MDBM_O_RDONLY != O_RDONLY
253 #error must have MDBM_O_RDONLY == O_RDONLY
255 #if MDBM_O_WRONLY != O_WRONLY
256 #error must have MDBM_O_WRONLY == O_WRONLY
258 #if MDBM_O_RDWR != O_RDWR
259 #error must have MDBM_O_RDWR == O_RDWR
261 #if MDBM_O_ACCMODE != O_ACCMODE
262 #error must have MDBM_O_ACCMODE == O_ACCMODE
264 #if MDBM_O_CREAT != O_CREAT
265 #error must have MDBM_O_CREAT == O_CREAT
267 #if MDBM_O_TRUNC != O_TRUNC
268 #error must have MDBM_O_TRUNC == O_TRUNC
270 #if MDBM_O_ASYNC != O_ASYNC
271 #error must have MDBM_O_ASYNC == O_ASYNC
273 #if MDBM_O_FSYNC != O_FSYNC
276 #error must have MDBM_O_FSYNC == O_FSYNC
341 extern MDBM*
mdbm_open(
const char *file,
int flags,
int mode,
int psize,
int presize);
461 #define MDBM_COPY_LOCK_ALL 0x01
481 #define MDBM_SAVE_COMPRESS_TREE 0x01000000
503 extern int mdbm_save(
MDBM *db,
const char *file,
int flags,
int mode,
int compressionLevel);
631 #define MDBM_ALIGN_8_BITS 0x0
632 #define MDBM_ALIGN_16_BITS 0x1
633 #define MDBM_ALIGN_32_BITS 0x3
634 #define MDBM_ALIGN_64_BITS 0x7
780 #define _MDBM_MAGIC 0x01023962
781 #define _MDBM_MAGIC_NEW 0x01023963
782 #define _MDBM_MAGIC_NEW2 0x01023964
784 #define MDBM_MAGIC _MDBM_MAGIC_NEW2
940 extern int mdbm_fetch_buf(MDBM *db, datum *key, datum *val, datum *buf,
int flags);
978 #define MDBM_FETCH_FLAG_DIRTY 0x01
1016 extern int mdbm_fetch_info(MDBM *db, datum *key, datum *val, datum *buf,
1059 #define MDBM_INSERT 0
1060 #define MDBM_REPLACE 1
1061 #define MDBM_INSERT_DUP 2
1062 #define MDBM_MODIFY 3
1063 #define MDBM_STORE_MASK 0x3
1066 #define MDBM_STORE_MODE(f) ((f) & MDBM_STORE_MASK)
1068 #define MDBM_RESERVE 0x100
1069 #define MDBM_CLEAN 0x200
1070 #define MDBM_CACHE_ONLY 0x400
1072 #define MDBM_CACHE_REPLACE 0
1073 #define MDBM_CACHE_MODIFY 0x1000
1074 #define MDBM_CACHE_UPDATE_MODE(f) ((f) & MDBM_CACHE_MODIFY)
1076 #define MDBM_STORE_SUCCESS 0
1077 #define MDBM_STORE_ENTRY_EXISTS 1
1140 extern int mdbm_store(MDBM *db, datum key, datum val,
int flags);
1175 extern int mdbm_store_str(MDBM *db,
const char *key,
const char *val,
int flags);
1271 #define MDBM_ENTRY_DELETED 0x1
1272 #define MDBM_ENTRY_LARGE_OBJECT 0x2
1321 #define MDBM_ITERATE_ENTRIES 0x01
1322 #define MDBM_ITERATE_NOLOCK 0x80
1378 #define MDBM_LOCKMODE_UNKNOWN 0xFFFFFFFF
1445 extern int mdbm_plock(MDBM *db,
const datum *key,
int flags);
1447 #define MDBM_LOCKMODE_UNKNOWN 0xFFFFFFFF
1464 extern int mdbm_punlock(MDBM *db,
const datum *key,
int flags);
1480 extern int mdbm_tryplock(MDBM *db,
const datum *key,
int flags);
1602 #define MDBM_SAVE_COMPRESS_TREE 0x01000000
1644 extern void mdbm_prune(MDBM* db,
int (*prune)(MDBM *, datum, datum,
void *),
void *param);
1727 extern int mdbm_clean(MDBM* db,
int pagenum,
int flags);
1739 #define MDBM_CHECK_HEADER 0
1740 #define MDBM_CHECK_CHUNKS 1
1741 #define MDBM_CHECK_DIRECTORY 2
1742 #define MDBM_CHECK_ALL 3
1754 extern int mdbm_check(MDBM* db,
int level,
int verbose);
1766 extern void mdbm_chk_error(MDBM* db,
int pagenum,
int mapped_pagenum,
int index);
1808 #define MDBM_PROT_NONE 0
1809 #define MDBM_PROT_READ 1
1810 #define MDBM_PROT_WRITE 2
1812 #define MDBM_PROT_NOACCESS MDBM_PROT_NONE
1813 #define MDBM_PROT_ACCESS 4
1992 #define MDBM_CLOCK_STANDARD 0
1993 #define MDBM_CLOCK_TSC 1
2013 #define MDBM_STATS_BASIC 0x1
2014 #define MDBM_STATS_TIMED 0x2
2017 #define MDBM_STAT_CB_INC 0x0
2018 #define MDBM_STAT_CB_SET 0x1
2019 #define MDBM_STAT_CB_ELAPSED 0x2
2020 #define MDBM_STAT_CB_TIME 0x3
2023 #define COMBINE_STAT_TAG(tag, flag) (tag | (flag<<16))
2031 #define MDBM_STAT_TAG_FETCH 1
2032 #define MDBM_STAT_TAG_STORE 2
2033 #define MDBM_STAT_TAG_DELETE 3
2034 #define MDBM_STAT_TAG_LOCK 4
2035 #define MDBM_STAT_TAG_FETCH_UNCACHED 5
2036 #define MDBM_STAT_TAG_GETPAGE 6
2037 #define MDBM_STAT_TAG_GETPAGE_UNCACHED 7
2038 #define MDBM_STAT_TAG_CACHE_EVICT 8
2039 #define MDBM_STAT_TAG_CACHE_STORE 9
2040 #define MDBM_STAT_TAG_PAGE_STORE 10
2041 #define MDBM_STAT_TAG_PAGE_DELETE 11
2042 #define MDBM_STAT_TAG_SYNC 12
2043 #define MDBM_STAT_TAG_FETCH_NOT_FOUND 13
2044 #define MDBM_STAT_TAG_FETCH_ERROR 14
2045 #define MDBM_STAT_TAG_STORE_ERROR 15
2046 #define MDBM_STAT_TAG_DELETE_FAILED 16
2050 #define MDBM_STAT_TAG_FETCH_LATENCY COMBINE_STAT_TAG(MDBM_STAT_TAG_FETCH, MDBM_STAT_CB_ELAPSED)
2053 #define MDBM_STAT_TAG_STORE_LATENCY COMBINE_STAT_TAG(MDBM_STAT_TAG_STORE, MDBM_STAT_CB_ELAPSED)
2056 #define MDBM_STAT_TAG_DELETE_LATENCY COMBINE_STAT_TAG(MDBM_STAT_TAG_DELETE, MDBM_STAT_CB_ELAPSED)
2059 #define MDBM_STAT_TAG_FETCH_TIME COMBINE_STAT_TAG(MDBM_STAT_TAG_FETCH, MDBM_STAT_CB_TIME)
2062 #define MDBM_STAT_TAG_STORE_TIME COMBINE_STAT_TAG(MDBM_STAT_TAG_STORE, MDBM_STAT_CB_TIME)
2065 #define MDBM_STAT_TAG_DELETE_TIME COMBINE_STAT_TAG(MDBM_STAT_TAG_DELETE, MDBM_STAT_CB_TIME)
2068 #define MDBM_STAT_TAG_FETCH_UNCACHED_LATENCY \
2069 COMBINE_STAT_TAG(MDBM_STAT_TAG_FETCH_UNCACHED, MDBM_STAT_CB_ELAPSED)
2072 #define MDBM_STAT_TAG_GETPAGE_LATENCY COMBINE_STAT_TAG(MDBM_STAT_TAG_GETPAGE, MDBM_STAT_CB_ELAPSED)
2075 #define MDBM_STAT_TAG_GETPAGE_UNCACHED_LATENCY \
2076 COMBINE_STAT_TAG(MDBM_STAT_TAG_GETPAGE_UNCACHED, MDBM_STAT_CB_ELAPSED)
2079 #define MDBM_STAT_TAG_CACHE_EVICT_LATENCY \
2080 COMBINE_STAT_TAG(MDBM_STAT_TAG_CACHE_EVICT, MDBM_STAT_CB_ELAPSED)
2083 #define MDBM_STAT_TAG_CACHE_STORE_LATENCY \
2084 COMBINE_STAT_TAG(MDBM_STAT_TAG_CACHE_STORE, MDBM_STAT_CB_ELAPSED)
2088 #define MDBM_STAT_TAG_PAGE_STORE_VALUE COMBINE_STAT_TAG(MDBM_STAT_TAG_PAGE_STORE, MDBM_STAT_CB_SET)
2092 #define MDBM_STAT_TAG_PAGE_DELETE_VALUE \
2093 COMBINE_STAT_TAG(MDBM_STAT_TAG_PAGE_DELETE, MDBM_STAT_CB_SET)
2096 #define MDBM_STAT_TAG_SYNC_LATENCY COMBINE_STAT_TAG(MDBM_STAT_TAG_SYNC, MDBM_STAT_CB_ELAPSED)
2109 typedef void (*
mdbm_stat_cb)(MDBM* db,
int tag,
int flags, uint64_t value,
void* user);
2228 #define MDBM_STAT_DELETED 0x1
2229 #define MDBM_STAT_KEYS 0x2
2230 #define MDBM_STAT_VALUES 0x4
2231 #define MDBM_STAT_PAGES_ONLY 0x8
2232 #define MDBM_STAT_NOLOCK 0x80
2234 #define MDBM_STAT_BUCKETS 20
2357 #define MDBM_CACHEMODE_NONE 0
2358 #define MDBM_CACHEMODE_LFU 1
2359 #define MDBM_CACHEMODE_LRU 2
2360 #define MDBM_CACHEMODE_GDSF 3
2361 #define MDBM_CACHEMODE_MAX 3
2363 #define MDBM_CACHEMODE_EVICT_CLEAN_FIRST 0x10
2365 #define MDBM_CACHEMODE(m) ((m)&3)
2367 #define MDBM_CACHEMODE_BITS (3 | MDBM_CACHEMODE_EVICT_CLEAN_FIRST)
2432 void* (*bs_init)(MDBM* db,
const char* filename,
void* opt,
int flags);
2434 int (*
bs_lock)(
void* data,
const datum* key,
int flags);
2436 int (*
bs_fetch)(
void* data,
const datum* key, datum* val, datum* buf,
int flags);
2437 int (*
bs_store)(
void* data,
const datum* key,
const datum* val,
int flags);
2439 void* (*bs_dup)(MDBM* db, MDBM* newdb,
void* data);
2442 #define MDBM_BSOPS_FILE ((const mdbm_bsops_t*)-1)
2443 #define MDBM_BSOPS_MDBM ((const mdbm_bsops_t*)-2)
2540 uint32_t *bufsize, uint32_t buf_offset);
2581 char **bufptr, uint32_t *bufsize, uint32_t buf_offset);
2621 mdbm_dbdump_import(MDBM *db, FILE *fp,
const char *input_file,
int store_flag, uint32_t *lineno);
2633 extern int mdbm_cdbdump_import(MDBM *db, FILE *fp,
const char *input_file,
int store_flag);
2740 #define MDBM_MINPAGE 128
2741 #define MDBM_PAGE_ALIGN 64
2745 #define MDBM_MAXPAGE ((16*1024*1024) - MDBM_PAGE_ALIGN)
2747 #define MDBM_PAGESIZ 4096
2748 #define MDBM_MIN_PSHIFT 7
2749 #define MDBM_MAX_SHIFT ((sizeof( void * )*8)-1)
2759 # define WHATSTR(X) pid_t getpid(void)
2761 # define WHATSTR(X) static const char what[] = X
2768 # define MD5Init MD5_Init
2769 # define MD5Final MD5_Final
2770 # define MD5Update MD5_Update
2775 typedef mdbm_ubig_t ((* mdbm_hash_t)(
const uint8_t *buf,
int len));
2781 #define MDBM_HASH_CRC32 0
2782 #define MDBM_HASH_EJB 1
2783 #define MDBM_HASH_PHONG 2
2784 #define MDBM_HASH_OZ 3
2785 #define MDBM_HASH_TOREK 4
2786 #define MDBM_HASH_FNV 5
2787 #define MDBM_HASH_STL 6
2788 #define MDBM_HASH_MD5 7
2789 #define MDBM_HASH_SHA_1 8
2790 #define MDBM_HASH_JENKINS 9
2791 #define MDBM_HASH_HSIEH 10
2792 #define MDBM_MAX_HASH 10
2795 #ifndef MDBM_DEFAULT_HASH
2796 # define MDBM_DEFAULT_HASH 5
2799 #define MDBM_CONFIG_DEFAULT_HASH MDBM_HASH_FNV
2802 #define MDBM_BAD_HASH_NO(n) ((n) < 0 || (n) > MDBM_MAX_HASH)
2810 #define MDBM_HASH_MAX MDBM_MAX_HASH