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 /* for the IDL cache */
69 #define SLAP_IDL_CACHE 1
72 typedef struct bdb_idl_cache_entry_s {
74 ldap_pvt_thread_rdwr_t idl_entry_rwlock;
77 struct bdb_idl_cache_entry_s* idl_lru_prev;
78 struct bdb_idl_cache_entry_s* idl_lru_next;
79 } bdb_idl_cache_entry_t;
82 /* for the in-core cache of entries */
83 typedef struct bdb_cache {
88 Entry *c_lruhead; /* lru - add accessed entries here */
89 Entry *c_lrutail; /* lru - rem lru entries from here */
90 ldap_pvt_thread_rdwr_t c_rwlock;
91 ldap_pvt_thread_mutex_t lru_mutex;
94 #define CACHE_READ_LOCK 0
95 #define CACHE_WRITE_LOCK 1
97 #define BDB_INDICES 128
107 /* DB_ENV parameters */
108 /* The DB_ENV can be tuned via DB_CONFIG */
110 u_int32_t bi_dbenv_xflags; /* extra flags */
114 struct bdb_db_info **bi_databases;
115 int bi_db_opflags; /* db-specific flags */
117 slap_mask_t bi_defaultmask;
120 void *bi_search_stack;
121 int bi_search_stack_depth;
124 ldap_pvt_thread_rdwr_t bi_tree_rdwr;
129 u_int32_t bi_txn_cp_min;
130 u_int32_t bi_txn_cp_kbyte;
135 ldap_pvt_thread_mutex_t bi_lastid_mutex;
136 #if defined(LDAP_CLIENT_UPDATE) || defined(LDAP_SYNC)
137 LDAP_LIST_HEAD(pl, slap_op) bi_psearch_list;
139 #ifdef SLAP_IDL_CACHE
140 int bi_idl_cache_max_size;
141 int bi_idl_cache_size;
142 Avlnode *bi_idl_tree;
143 bdb_idl_cache_entry_t *bi_idl_lru_head;
144 bdb_idl_cache_entry_t *bi_idl_lru_tail;
145 ldap_pvt_thread_mutex_t bi_idl_tree_mutex;
149 #define bi_id2entry bi_databases[BDB_ID2ENTRY]
151 #define bi_id2parent bi_databases[BDB_ID2PARENT]
153 #define bi_dn2id bi_databases[BDB_DN2ID]
159 DB_LOCK boi_lock; /* used when no txn */
161 u_int32_t boi_locker;
165 #define DB_OPEN(db, txn, file, name, type, flags, mode) \
166 (db)->open(db, file, name, type, flags, mode)
168 #if DB_VERSION_MAJOR < 4
169 #define LOCK_DETECT(env,f,t,a) lock_detect(env, f, t, a)
170 #define LOCK_GET(env,i,f,o,m,l) lock_get(env, i, f, o, m, l)
171 #define LOCK_PUT(env,l) lock_put(env, l)
172 #define TXN_CHECKPOINT(env,k,m,f) txn_checkpoint(env, k, m, f)
173 #define TXN_BEGIN(env,p,t,f) txn_begin((env), p, t, f)
174 #define TXN_PREPARE(txn,gid) txn_prepare((txn), (gid))
175 #define TXN_COMMIT(txn,f) txn_commit((txn), (f))
176 #define TXN_ABORT(txn) txn_abort((txn))
177 #define TXN_ID(txn) txn_id(txn)
178 #define XLOCK_ID(env, locker) lock_id(env, locker)
179 #define XLOCK_ID_FREE(env, locker) lock_id_free(env, locker)
181 #define LOCK_DETECT(env,f,t,a) (env)->lock_detect(env, f, t, a)
182 #define LOCK_GET(env,i,f,o,m,l) (env)->lock_get(env, i, f, o, m, l)
183 #define LOCK_PUT(env,l) (env)->lock_put(env, l)
184 #define TXN_CHECKPOINT(env,k,m,f) (env)->txn_checkpoint(env, k, m, f)
185 #define TXN_BEGIN(env,p,t,f) (env)->txn_begin((env), p, t, f)
186 #define TXN_PREPARE(txn,g) (txn)->prepare((txn), (g))
187 #define TXN_COMMIT(txn,f) (txn)->commit((txn), (f))
188 #define TXN_ABORT(txn) (txn)->abort((txn))
189 #define TXN_ID(txn) (txn)->id(txn)
190 #define XLOCK_ID(env, locker) (env)->lock_id(env, locker)
191 #define XLOCK_ID_FREE(env, locker) (env)->lock_id_free(env, locker)
193 /* BDB 4.1.17 adds txn arg to db->open */
194 #if DB_VERSION_MINOR > 1 || DB_VERSION_PATCH >= 17
196 #define DB_OPEN(db, txn, file, name, type, flags, mode) \
197 (db)->open(db, txn, file, name, type, flags, mode)
200 #define BDB_REUSE_LOCKERS
202 #ifdef BDB_REUSE_LOCKERS
203 #define LOCK_ID_FREE(env, locker)
204 #define LOCK_ID(env, locker) bdb_locker_id(op, env, locker)
206 #define LOCK_ID_FREE(env, locker) XLOCK_ID_FREE(env, locker)
207 #define LOCK_ID(env, locker) XLOCK_ID(env, locker)
214 #include "proto-bdb.h"
216 #endif /* _BACK_BDB_H_ */