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_SUBENTRIES 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
46 /* The bdb on-disk entry format is pretty space-inefficient. Average
47 * sized user entries are 3-4K each. You need at least two entries to
48 * fit into a single database page, more is better. 64K is BDB's
49 * upper bound. Smaller pages are better for concurrency.
51 #ifndef BDB_ID2ENTRY_PAGESIZE
52 #define BDB_ID2ENTRY_PAGESIZE 16384
56 #define BDB_PAGESIZE 4096 /* BDB's original default */
59 #define DEFAULT_CACHE_SIZE 1000
61 /* The default search IDL stack cache depth */
62 #define DEFAULT_SEARCH_STACK_DEPTH 16
64 /* The minimum we can function with */
65 #define MINIMUM_SEARCH_STACK_DEPTH 8
67 /* for the IDL cache */
68 #define SLAP_IDL_CACHE 1
71 typedef struct bdb_idl_cache_entry_s {
73 ldap_pvt_thread_rdwr_t idl_entry_rwlock;
76 struct bdb_idl_cache_entry_s* idl_lru_prev;
77 struct bdb_idl_cache_entry_s* idl_lru_next;
78 } bdb_idl_cache_entry_t;
81 /* BDB backend specific entry info */
82 typedef struct bdb_entry_info {
83 struct bdb_entry_info *bei_parent;
87 #define CACHE_ENTRY_DELETED 1
88 #define CACHE_ENTRY_NO_KIDS 2
89 #define CACHE_ENTRY_NOT_LINKED 4
92 * remaining fields require backend cache lock to access
94 struct berval bei_nrdn;
96 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 u_int32_t bi_txn_cp_min;
152 u_int32_t bi_txn_cp_kbyte;
158 ldap_pvt_thread_mutex_t bi_lastid_mutex;
159 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
222 #define BDB_CSN_COMMIT 0
223 #define BDB_CSN_ABORT 1
224 #define BDB_CSN_RETRY 2
228 #include "proto-bdb.h"
230 #endif /* _BACK_BDB_H_ */