1 /* back-bdb.h - bdb back-end header file */
4 * Copyright 2000-2003 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
36 #define BDB_TMP_SUBDIR "tmp"
37 #define BDB_LG_SUBDIR "log"
38 #define BDB_DATA_SUBDIR "data"
41 #define BDB_SUFFIX ".bdb"
42 #define BDB_ID2ENTRY 0
44 #define BDB_ID2PARENT 1
50 /* The bdb on-disk entry format is pretty space-inefficient. Average
51 * sized user entries are 3-4K each. You need at least two entries to
52 * fit into a single database page, more is better. 64K is BDB's
53 * upper bound. Smaller pages are better for concurrency.
55 #ifndef BDB_ID2ENTRY_PAGESIZE
56 #define BDB_ID2ENTRY_PAGESIZE 16384
60 #define BDB_PAGESIZE 4096 /* BDB's original default */
63 #define DEFAULT_CACHE_SIZE 1000
65 /* The default search IDL stack cache depth */
66 #define DEFAULT_SEARCH_STACK_DEPTH 16
68 /* The minimum we can function with */
69 #define MINIMUM_SEARCH_STACK_DEPTH 8
71 /* for the IDL cache */
72 #define SLAP_IDL_CACHE 1
75 typedef struct bdb_idl_cache_entry_s {
77 ldap_pvt_thread_rdwr_t idl_entry_rwlock;
80 struct bdb_idl_cache_entry_s* idl_lru_prev;
81 struct bdb_idl_cache_entry_s* idl_lru_next;
82 } bdb_idl_cache_entry_t;
85 /* BDB backend specific entry info */
86 typedef struct bdb_entry_info {
87 struct bdb_entry_info *bei_parent;
91 #define CACHE_ENTRY_DELETED 1
92 #define CACHE_ENTRY_NO_KIDS 2
95 * remaining fields require backend cache lock to access
97 struct berval bei_nrdn;
98 struct berval bei_rdn;
101 ldap_pvt_thread_mutex_t bei_kids_mutex;
103 struct bdb_entry_info *bei_lrunext; /* for cache lru list */
104 struct bdb_entry_info *bei_lruprev;
107 #define BEI(e) ((EntryInfo *) ((e)->e_private))
109 /* for the in-core cache of entries */
110 typedef struct bdb_cache {
115 EntryInfo *c_lruhead; /* lru - add accessed entries here */
116 EntryInfo *c_lrutail; /* lru - rem lru entries from here */
117 ldap_pvt_thread_rdwr_t c_rwlock;
118 ldap_pvt_thread_mutex_t lru_mutex;
121 #define CACHE_READ_LOCK 0
122 #define CACHE_WRITE_LOCK 1
124 #define BDB_INDICES 128
134 /* DB_ENV parameters */
135 /* The DB_ENV can be tuned via DB_CONFIG */
137 u_int32_t bi_dbenv_xflags; /* extra flags */
141 struct bdb_db_info **bi_databases;
142 int bi_db_opflags; /* db-specific flags */
144 slap_mask_t bi_defaultmask;
147 void *bi_search_stack;
148 int bi_search_stack_depth;
151 ldap_pvt_thread_rdwr_t bi_tree_rdwr;
156 u_int32_t bi_txn_cp_min;
157 u_int32_t bi_txn_cp_kbyte;
163 ldap_pvt_thread_mutex_t bi_lastid_mutex;
164 #if defined(LDAP_CLIENT_UPDATE) || defined(LDAP_SYNC)
165 LDAP_LIST_HEAD(pl, slap_op) bi_psearch_list;
167 #ifdef SLAP_IDL_CACHE
168 int bi_idl_cache_max_size;
169 int bi_idl_cache_size;
170 Avlnode *bi_idl_tree;
171 bdb_idl_cache_entry_t *bi_idl_lru_head;
172 bdb_idl_cache_entry_t *bi_idl_lru_tail;
173 ldap_pvt_thread_rdwr_t bi_idl_tree_rwlock;
174 ldap_pvt_thread_mutex_t bi_idl_tree_lrulock;
178 #define bi_id2entry bi_databases[BDB_ID2ENTRY]
179 #define bi_dn2id bi_databases[BDB_DN2ID]
184 DB_LOCK boi_lock; /* used when no txn */
186 u_int32_t boi_locker;
190 #define DB_OPEN(db, txn, file, name, type, flags, mode) \
191 (db)->open(db, file, name, type, flags, mode)
193 #if DB_VERSION_MAJOR < 4
194 #define LOCK_DETECT(env,f,t,a) lock_detect(env, f, t, a)
195 #define LOCK_GET(env,i,f,o,m,l) lock_get(env, i, f, o, m, l)
196 #define LOCK_PUT(env,l) lock_put(env, l)
197 #define TXN_CHECKPOINT(env,k,m,f) txn_checkpoint(env, k, m, f)
198 #define TXN_BEGIN(env,p,t,f) txn_begin((env), p, t, f)
199 #define TXN_PREPARE(txn,gid) txn_prepare((txn), (gid))
200 #define TXN_COMMIT(txn,f) txn_commit((txn), (f))
201 #define TXN_ABORT(txn) txn_abort((txn))
202 #define TXN_ID(txn) txn_id(txn)
203 #define XLOCK_ID(env, locker) lock_id(env, locker)
204 #define XLOCK_ID_FREE(env, locker) lock_id_free(env, locker)
206 #define LOCK_DETECT(env,f,t,a) (env)->lock_detect(env, f, t, a)
207 #define LOCK_GET(env,i,f,o,m,l) (env)->lock_get(env, i, f, o, m, l)
208 #define LOCK_PUT(env,l) (env)->lock_put(env, l)
209 #define TXN_CHECKPOINT(env,k,m,f) (env)->txn_checkpoint(env, k, m, f)
210 #define TXN_BEGIN(env,p,t,f) (env)->txn_begin((env), p, t, f)
211 #define TXN_PREPARE(txn,g) (txn)->prepare((txn), (g))
212 #define TXN_COMMIT(txn,f) (txn)->commit((txn), (f))
213 #define TXN_ABORT(txn) (txn)->abort((txn))
214 #define TXN_ID(txn) (txn)->id(txn)
215 #define XLOCK_ID(env, locker) (env)->lock_id(env, locker)
216 #define XLOCK_ID_FREE(env, locker) (env)->lock_id_free(env, locker)
218 /* BDB 4.1.17 adds txn arg to db->open */
219 #if DB_VERSION_MINOR > 1 || DB_VERSION_PATCH >= 17
221 #define DB_OPEN(db, txn, file, name, type, flags, mode) \
222 (db)->open(db, txn, file, name, type, flags, mode)
225 #define BDB_REUSE_LOCKERS
227 #ifdef BDB_REUSE_LOCKERS
228 #define LOCK_ID_FREE(env, locker)
229 #define LOCK_ID(env, locker) bdb_locker_id(op, env, locker)
231 #define LOCK_ID_FREE(env, locker) XLOCK_ID_FREE(env, locker)
232 #define LOCK_ID(env, locker) XLOCK_ID(env, locker)
239 #include "proto-bdb.h"
241 #endif /* _BACK_BDB_H_ */