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