]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/back-bdb.h
Handle SLAPD_FILTER_COMPUTED cases
[openldap] / servers / slapd / back-bdb / back-bdb.h
1 /* back-bdb.h - bdb back-end header file */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 2000-2003 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #ifndef _BACK_BDB_H_
9 #define _BACK_BDB_H_
10
11 #include <portable.h>
12 #include "slap.h"
13 #include <db.h>
14 #undef const    /* db.h defines this?? */
15
16 LDAP_BEGIN_DECL
17
18 #define DN_BASE_PREFIX          SLAP_INDEX_EQUALITY_PREFIX
19 #define DN_ONE_PREFIX           '%'
20 #define DN_SUBTREE_PREFIX       '@'
21
22 #define DBTzero(t)                      (memset((t), 0, sizeof(DBT)))
23 #define DBT2bv(t,bv)            ((bv)->bv_val = (t)->data, \
24                                                                 (bv)->bv_len = (t)->size)
25 #define bv2DBT(bv,t)            ((t)->data = (bv)->bv_val, \
26                                                                 (t)->size = (bv)->bv_len )
27
28 #define BDB_TXN_RETRIES         16
29
30 #define BDB_MAX_ADD_LOOP        30
31
32 #define BDB_ALIASES     1
33
34 #ifdef BDB_SUBDIRS
35 #define BDB_TMP_SUBDIR  "tmp"
36 #define BDB_LG_SUBDIR   "log"
37 #define BDB_DATA_SUBDIR "data"
38 #endif
39
40 #define BDB_SUFFIX              ".bdb"
41 #define BDB_ID2ENTRY    0
42 #define BDB_DN2ID               1
43 #define BDB_NDB                 2
44
45 /* The bdb on-disk entry format is pretty space-inefficient. Average
46  * sized user entries are 3-4K each. You need at least two entries to
47  * fit into a single database page, more is better. 64K is BDB's
48  * upper bound. Smaller pages are better for concurrency.
49  */
50 #ifndef BDB_ID2ENTRY_PAGESIZE
51 #define BDB_ID2ENTRY_PAGESIZE   16384
52 #endif
53
54 #ifndef BDB_PAGESIZE
55 #define BDB_PAGESIZE    4096    /* BDB's original default */
56 #endif
57
58 #define DEFAULT_CACHE_SIZE     1000
59
60 /* The default search IDL stack cache depth */
61 #define DEFAULT_SEARCH_STACK_DEPTH      16
62
63 /* The minimum we can function with */
64 #define MINIMUM_SEARCH_STACK_DEPTH      8
65
66 /* for the IDL cache */
67 #define SLAP_IDL_CACHE  1
68
69 #ifdef SLAP_IDL_CACHE
70 typedef struct bdb_idl_cache_entry_s {
71         struct berval kstr;
72         ldap_pvt_thread_rdwr_t idl_entry_rwlock;
73         ID      *idl;
74         DB      *db;
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;
78 #endif
79
80 /* BDB backend specific entry info */
81 typedef struct bdb_entry_info {
82         struct bdb_entry_info *bei_parent;
83         ID bei_id;
84
85         int bei_state;
86 #define CACHE_ENTRY_DELETED     1
87 #define CACHE_ENTRY_NO_KIDS     2
88 #define CACHE_ENTRY_NOT_LINKED  4
89
90         /*
91          * remaining fields require backend cache lock to access
92          */
93         struct berval bei_nrdn;
94 #ifdef BDB_HIER
95         struct berval bei_rdn;
96         int     bei_modrdns;
97 #endif
98         Entry   *bei_e;
99         Avlnode *bei_kids;
100         ldap_pvt_thread_mutex_t bei_kids_mutex;
101         
102         struct bdb_entry_info   *bei_lrunext;   /* for cache lru list */
103         struct bdb_entry_info   *bei_lruprev;
104 } EntryInfo;
105 #undef BEI
106 #define BEI(e)  ((EntryInfo *) ((e)->e_private))
107
108 /* for the in-core cache of entries */
109 typedef struct bdb_cache {
110         int             c_maxsize;
111         int             c_cursize;
112         EntryInfo       c_dntree;
113         Avlnode         *c_idtree;
114         EntryInfo       *c_lruhead;     /* lru - add accessed entries here */
115         EntryInfo       *c_lrutail;     /* lru - rem lru entries from here */
116         ldap_pvt_thread_rdwr_t c_rwlock;
117         ldap_pvt_thread_mutex_t lru_mutex;
118 } Cache;
119  
120 #define CACHE_READ_LOCK                0
121 #define CACHE_WRITE_LOCK       1
122  
123 #define BDB_INDICES             128
124
125 struct bdb_db_info {
126         char            *bdi_name;
127         DB                      *bdi_db;
128 };
129
130 struct bdb_info {
131         DB_ENV          *bi_dbenv;
132
133         /* DB_ENV parameters */
134         /* The DB_ENV can be tuned via DB_CONFIG */
135         char            *bi_dbenv_home;
136         u_int32_t       bi_dbenv_xflags; /* extra flags */
137         int                     bi_dbenv_mode;
138
139         int                     bi_ndatabases;
140         struct bdb_db_info **bi_databases;
141         int             bi_db_opflags;  /* db-specific flags */
142
143         slap_mask_t     bi_defaultmask;
144         Cache           bi_cache;
145         Avlnode         *bi_attrs;
146         void            *bi_search_stack;
147         int             bi_search_stack_depth;
148
149         int                     bi_txn_cp;
150         u_int32_t       bi_txn_cp_min;
151         u_int32_t       bi_txn_cp_kbyte;
152
153         int                     bi_lock_detect;
154         long            bi_shm_key;
155
156         ID                      bi_lastid;
157         ldap_pvt_thread_mutex_t bi_lastid_mutex;
158 #if defined(LDAP_CLIENT_UPDATE) || defined(LDAP_SYNC)
159         LDAP_LIST_HEAD(pl, slap_op) bi_psearch_list;
160 #endif
161 #ifdef SLAP_IDL_CACHE
162         int             bi_idl_cache_max_size;
163         int             bi_idl_cache_size;
164         Avlnode         *bi_idl_tree;
165         bdb_idl_cache_entry_t   *bi_idl_lru_head;
166         bdb_idl_cache_entry_t   *bi_idl_lru_tail;
167         ldap_pvt_thread_rdwr_t bi_idl_tree_rwlock;
168         ldap_pvt_thread_mutex_t bi_idl_tree_lrulock;
169 #endif
170 };
171
172 #define bi_id2entry     bi_databases[BDB_ID2ENTRY]
173 #define bi_dn2id        bi_databases[BDB_DN2ID]
174
175 struct bdb_op_info {
176         BackendDB*      boi_bdb;
177         DB_TXN*         boi_txn;
178         DB_LOCK         boi_lock;       /* used when no txn */
179         u_int32_t       boi_err;
180         u_int32_t       boi_locker;
181         int             boi_acl_cache;
182 };
183
184 #define DB_OPEN(db, txn, file, name, type, flags, mode) \
185         (db)->open(db, file, name, type, flags, mode)
186
187 #if DB_VERSION_MAJOR < 4
188 #define LOCK_DETECT(env,f,t,a)          lock_detect(env, f, t, a)
189 #define LOCK_GET(env,i,f,o,m,l)         lock_get(env, i, f, o, m, l)
190 #define LOCK_PUT(env,l)                 lock_put(env, l)
191 #define TXN_CHECKPOINT(env,k,m,f)       txn_checkpoint(env, k, m, f)
192 #define TXN_BEGIN(env,p,t,f)            txn_begin((env), p, t, f)
193 #define TXN_PREPARE(txn,gid)            txn_prepare((txn), (gid))
194 #define TXN_COMMIT(txn,f)                       txn_commit((txn), (f))
195 #define TXN_ABORT(txn)                          txn_abort((txn))
196 #define TXN_ID(txn)                                     txn_id(txn)
197 #define XLOCK_ID(env, locker)           lock_id(env, locker)
198 #define XLOCK_ID_FREE(env, locker)      lock_id_free(env, locker)
199 #else
200 #define LOCK_DETECT(env,f,t,a)          (env)->lock_detect(env, f, t, a)
201 #define LOCK_GET(env,i,f,o,m,l)         (env)->lock_get(env, i, f, o, m, l)
202 #define LOCK_PUT(env,l)                 (env)->lock_put(env, l)
203 #define TXN_CHECKPOINT(env,k,m,f)       (env)->txn_checkpoint(env, k, m, f)
204 #define TXN_BEGIN(env,p,t,f)            (env)->txn_begin((env), p, t, f)
205 #define TXN_PREPARE(txn,g)                      (txn)->prepare((txn), (g))
206 #define TXN_COMMIT(txn,f)                       (txn)->commit((txn), (f))
207 #define TXN_ABORT(txn)                          (txn)->abort((txn))
208 #define TXN_ID(txn)                                     (txn)->id(txn)
209 #define XLOCK_ID(env, locker)           (env)->lock_id(env, locker)
210 #define XLOCK_ID_FREE(env, locker)      (env)->lock_id_free(env, locker)
211
212 /* BDB 4.1.17 adds txn arg to db->open */
213 #if DB_VERSION_MINOR > 1 || DB_VERSION_PATCH >= 17
214 #undef DB_OPEN
215 #define DB_OPEN(db, txn, file, name, type, flags, mode) \
216         (db)->open(db, txn, file, name, type, flags, mode)
217 #endif
218
219 #endif
220
221 #define BDB_REUSE_LOCKERS
222
223 LDAP_END_DECL
224
225 #include "proto-bdb.h"
226
227 #endif /* _BACK_BDB_H_ */