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 DN_BASE_PREFIX SLAP_INDEX_EQUALITY_PREFIX
18 #define DN_ONE_PREFIX '%'
19 #define DN_SUBTREE_PREFIX '@'
21 #define DBTzero(t) (memset((t), 0, sizeof(DBT)))
22 #define DBT2bv(t,bv) ((bv)->bv_val = (t)->data, \
23 (bv)->bv_len = (t)->size)
24 #define bv2DBT(bv,t) ((t)->data = (bv)->bv_val, \
25 (t)->size = (bv)->bv_len )
27 #define BDB_TXN_RETRIES 16
29 #define BDB_MAX_ADD_LOOP 30
34 #define BDB_TMP_SUBDIR "tmp"
35 #define BDB_LG_SUBDIR "log"
36 #define BDB_DATA_SUBDIR "data"
39 #define BDB_SUFFIX ".bdb"
40 #define BDB_ID2ENTRY 0
44 /* The bdb on-disk entry format is pretty space-inefficient. Average
45 * sized user entries are 3-4K each. You need at least two entries to
46 * fit into a single database page, more is better. 64K is BDB's
47 * upper bound. Smaller pages are better for concurrency.
49 #ifndef BDB_ID2ENTRY_PAGESIZE
50 #define BDB_ID2ENTRY_PAGESIZE 16384
54 #define BDB_PAGESIZE 4096 /* BDB's original default */
57 #define DEFAULT_CACHE_SIZE 1000
59 /* The default search IDL stack cache depth */
60 #define DEFAULT_SEARCH_STACK_DEPTH 16
62 /* The minimum we can function with */
63 #define MINIMUM_SEARCH_STACK_DEPTH 8
65 /* for the IDL cache */
66 #define SLAP_IDL_CACHE 1
69 typedef struct bdb_idl_cache_entry_s {
71 ldap_pvt_thread_rdwr_t idl_entry_rwlock;
74 struct bdb_idl_cache_entry_s* idl_lru_prev;
75 struct bdb_idl_cache_entry_s* idl_lru_next;
76 } bdb_idl_cache_entry_t;
79 /* BDB backend specific entry info */
80 typedef struct bdb_entry_info {
81 struct bdb_entry_info *bei_parent;
85 #define CACHE_ENTRY_DELETED 1
86 #define CACHE_ENTRY_NO_KIDS 2
87 #define CACHE_ENTRY_NOT_LINKED 4
90 * remaining fields require backend cache lock to access
92 struct berval bei_nrdn;
94 struct berval bei_rdn;
99 ldap_pvt_thread_mutex_t bei_kids_mutex;
101 struct bdb_entry_info *bei_lrunext; /* for cache lru list */
102 struct bdb_entry_info *bei_lruprev;
105 #define BEI(e) ((EntryInfo *) ((e)->e_private))
107 /* for the in-core cache of entries */
108 typedef struct bdb_cache {
113 EntryInfo *c_lruhead; /* lru - add accessed entries here */
114 EntryInfo *c_lrutail; /* lru - rem lru entries from here */
115 ldap_pvt_thread_rdwr_t c_rwlock;
116 ldap_pvt_thread_mutex_t lru_mutex;
119 #define CACHE_READ_LOCK 0
120 #define CACHE_WRITE_LOCK 1
122 #define BDB_INDICES 128
132 /* DB_ENV parameters */
133 /* The DB_ENV can be tuned via DB_CONFIG */
135 u_int32_t bi_dbenv_xflags; /* extra flags */
139 struct bdb_db_info **bi_databases;
140 int bi_db_opflags; /* db-specific flags */
142 slap_mask_t bi_defaultmask;
145 void *bi_search_stack;
146 int bi_search_stack_depth;
149 u_int32_t bi_txn_cp_min;
150 u_int32_t bi_txn_cp_kbyte;
156 ldap_pvt_thread_mutex_t bi_lastid_mutex;
157 #if defined(LDAP_CLIENT_UPDATE) || defined(LDAP_SYNC)
158 LDAP_LIST_HEAD(pl, slap_op) bi_psearch_list;
160 #ifdef SLAP_IDL_CACHE
161 int bi_idl_cache_max_size;
162 int bi_idl_cache_size;
163 Avlnode *bi_idl_tree;
164 bdb_idl_cache_entry_t *bi_idl_lru_head;
165 bdb_idl_cache_entry_t *bi_idl_lru_tail;
166 ldap_pvt_thread_rdwr_t bi_idl_tree_rwlock;
167 ldap_pvt_thread_mutex_t bi_idl_tree_lrulock;
171 #define bi_id2entry bi_databases[BDB_ID2ENTRY]
172 #define bi_dn2id bi_databases[BDB_DN2ID]
177 DB_LOCK boi_lock; /* used when no txn */
179 u_int32_t boi_locker;
183 #define DB_OPEN(db, txn, file, name, type, flags, mode) \
184 (db)->open(db, file, name, type, flags, mode)
186 #if DB_VERSION_MAJOR < 4
187 #define LOCK_DETECT(env,f,t,a) lock_detect(env, f, t, a)
188 #define LOCK_GET(env,i,f,o,m,l) lock_get(env, i, f, o, m, l)
189 #define LOCK_PUT(env,l) lock_put(env, l)
190 #define TXN_CHECKPOINT(env,k,m,f) txn_checkpoint(env, k, m, f)
191 #define TXN_BEGIN(env,p,t,f) txn_begin((env), p, t, f)
192 #define TXN_PREPARE(txn,gid) txn_prepare((txn), (gid))
193 #define TXN_COMMIT(txn,f) txn_commit((txn), (f))
194 #define TXN_ABORT(txn) txn_abort((txn))
195 #define TXN_ID(txn) txn_id(txn)
196 #define XLOCK_ID(env, locker) lock_id(env, locker)
197 #define XLOCK_ID_FREE(env, locker) lock_id_free(env, locker)
199 #define LOCK_DETECT(env,f,t,a) (env)->lock_detect(env, f, t, a)
200 #define LOCK_GET(env,i,f,o,m,l) (env)->lock_get(env, i, f, o, m, l)
201 #define LOCK_PUT(env,l) (env)->lock_put(env, l)
202 #define TXN_CHECKPOINT(env,k,m,f) (env)->txn_checkpoint(env, k, m, f)
203 #define TXN_BEGIN(env,p,t,f) (env)->txn_begin((env), p, t, f)
204 #define TXN_PREPARE(txn,g) (txn)->prepare((txn), (g))
205 #define TXN_COMMIT(txn,f) (txn)->commit((txn), (f))
206 #define TXN_ABORT(txn) (txn)->abort((txn))
207 #define TXN_ID(txn) (txn)->id(txn)
208 #define XLOCK_ID(env, locker) (env)->lock_id(env, locker)
209 #define XLOCK_ID_FREE(env, locker) (env)->lock_id_free(env, locker)
211 /* BDB 4.1.17 adds txn arg to db->open */
212 #if DB_VERSION_MINOR > 1 || DB_VERSION_PATCH >= 17
214 #define DB_OPEN(db, txn, file, name, type, flags, mode) \
215 (db)->open(db, txn, file, name, type, flags, mode)
220 #define BDB_REUSE_LOCKERS
224 #include "proto-bdb.h"
226 #endif /* _BACK_BDB_H_ */