1 /* back-bdb.h - bdb back-end header file */
4 * Copyright 2000-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
17 /* #define BDB_HIER 1 */
19 #define DN_BASE_PREFIX SLAP_INDEX_EQUALITY_PREFIX
20 #define DN_ONE_PREFIX '%'
21 #define DN_SUBTREE_PREFIX '@'
23 #define DBTzero(t) (memset((t), 0, sizeof(DBT)))
24 #define DBT2bv(t,bv) ((bv)->bv_val = (t)->data, \
25 (bv)->bv_len = (t)->size)
26 #define bv2DBT(bv,t) ((t)->data = (bv)->bv_val, \
27 (t)->size = (bv)->bv_len )
29 #define BDB_TXN_RETRIES 16
31 #define BDB_MAX_ADD_LOOP 30
34 #define BDB_TMP_SUBDIR LDAP_DIRSEP "tmp"
35 #define BDB_LG_SUBDIR LDAP_DIRSEP "log"
36 #define BDB_DATA_SUBDIR LDAP_DIRSEP "data"
39 #define BDB_SUFFIX ".bdb"
40 #define BDB_ID2ENTRY 0
42 #define BDB_ID2PARENT 1
48 /* The bdb on-disk entry format is pretty space-inefficient. Average
49 * sized user entries are 3-4K each. You need at least two entries to
50 * fit into a single database page, more is better. 64K is BDB's
51 * upper bound. Smaller pages are better for concurrency.
53 #ifndef BDB_ID2ENTRY_PAGESIZE
54 #define BDB_ID2ENTRY_PAGESIZE 16384
58 #define BDB_PAGESIZE 4096 /* BDB's original default */
61 #define DEFAULT_CACHE_SIZE 1000
63 /* The default search IDL stack cache depth */
64 #define DEFAULT_SEARCH_STACK_DEPTH 16
66 /* for the IDL cache */
67 #define SLAP_IDL_CACHE 1
70 typedef struct bdb_idl_cache_entry_s {
72 ldap_pvt_thread_rdwr_t idl_entry_rwlock;
75 struct bdb_idl_cache_entry_s* idl_lru_prev;
76 struct bdb_idl_cache_entry_s* idl_lru_next;
77 } bdb_idl_cache_entry_t;
80 /* for the in-core cache of entries */
81 typedef struct bdb_cache {
86 Entry *c_lruhead; /* lru - add accessed entries here */
87 Entry *c_lrutail; /* lru - rem lru entries from here */
88 ldap_pvt_thread_rdwr_t c_rwlock;
89 ldap_pvt_thread_mutex_t lru_mutex;
92 #define CACHE_READ_LOCK 0
93 #define CACHE_WRITE_LOCK 1
95 #define BDB_INDICES 128
105 /* DB_ENV parameters */
106 /* The DB_ENV can be tuned via DB_CONFIG */
108 u_int32_t bi_dbenv_xflags; /* extra flags */
112 struct bdb_db_info **bi_databases;
113 ldap_pvt_thread_mutex_t bi_database_mutex;
114 int bi_db_opflags; /* db-specific flags */
116 slap_mask_t bi_defaultmask;
119 void *bi_search_stack;
120 int bi_search_stack_depth;
123 ldap_pvt_thread_rdwr_t bi_tree_rdwr;
128 u_int32_t bi_txn_cp_min;
129 u_int32_t bi_txn_cp_kbyte;
134 ldap_pvt_thread_mutex_t bi_lastid_mutex;
135 #ifdef LDAP_CLIENT_UPDATE
136 LDAP_LIST_HEAD(pl, slap_op) psearch_list;
138 #ifdef SLAP_IDL_CACHE
139 int bi_idl_cache_max_size;
140 int bi_idl_cache_size;
141 Avlnode *bi_idl_tree;
142 bdb_idl_cache_entry_t *bi_idl_lru_head;
143 bdb_idl_cache_entry_t *bi_idl_lru_tail;
144 ldap_pvt_thread_mutex_t bi_idl_tree_mutex;
148 #define bi_id2entry bi_databases[BDB_ID2ENTRY]
150 #define bi_id2parent bi_databases[BDB_ID2PARENT]
152 #define bi_dn2id bi_databases[BDB_DN2ID]
161 #define DB_OPEN(db, file, name, type, flags, mode) \
162 (db)->open(db, file, name, type, flags, mode)
164 #if DB_VERSION_MAJOR < 4
165 #define LOCK_DETECT(env,f,t,a) lock_detect(env, f, t, a)
166 #define LOCK_GET(env,i,f,o,m,l) lock_get(env, i, f, o, m, l)
167 #define LOCK_PUT(env,l) lock_put(env, l)
168 #define TXN_CHECKPOINT(env,k,m,f) txn_checkpoint(env, k, m, f)
169 #define TXN_BEGIN(env,p,t,f) txn_begin((env), p, t, f)
170 #define TXN_PREPARE(txn,gid) txn_prepare((txn), (gid))
171 #define TXN_COMMIT(txn,f) txn_commit((txn), (f))
172 #define TXN_ABORT(txn) txn_abort((txn))
173 #define TXN_ID(txn) txn_id(txn)
174 #define XLOCK_ID(env, locker) lock_id(env, locker)
175 #define XLOCK_ID_FREE(env, locker) lock_id_free(env, locker)
177 #define LOCK_DETECT(env,f,t,a) (env)->lock_detect(env, f, t, a)
178 #define LOCK_GET(env,i,f,o,m,l) (env)->lock_get(env, i, f, o, m, l)
179 #define LOCK_PUT(env,l) (env)->lock_put(env, l)
180 #define TXN_CHECKPOINT(env,k,m,f) (env)->txn_checkpoint(env, k, m, f)
181 #define TXN_BEGIN(env,p,t,f) (env)->txn_begin((env), p, t, f)
182 #define TXN_PREPARE(txn,g) (txn)->prepare((txn), (g))
183 #define TXN_COMMIT(txn,f) (txn)->commit((txn), (f))
184 #define TXN_ABORT(txn) (txn)->abort((txn))
185 #define TXN_ID(txn) (txn)->id(txn)
186 #define XLOCK_ID(env, locker) (env)->lock_id(env, locker)
187 #define XLOCK_ID_FREE(env, locker) (env)->lock_id_free(env, locker)
189 /* BDB 4.1.17 adds txn arg to db->open */
190 #if DB_VERSION_MINOR > 1 || DB_VERSION_PATCH >= 17
192 #define DB_OPEN(db, file, name, type, flags, mode) \
193 (db)->open(db, NULL, file, name, type, (flags)|DB_AUTO_COMMIT, mode)
196 #define BDB_REUSE_LOCKERS
198 #ifdef BDB_REUSE_LOCKERS
199 #define LOCK_ID_FREE(env, locker)
200 #define LOCK_ID(env, locker) bdb_locker_id(op, env, locker)
202 #define LOCK_ID_FREE(env, locker) XLOCK_ID_FREE(env, locker)
203 #define LOCK_ID(env, locker) XLOCK_ID(env, locker)
210 #include "proto-bdb.h"
212 #endif /* _BACK_BDB_H_ */