]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/back-bdb.h
Major API change - (SLAP_OP_BLOCKS) All request parameters are
[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
15 LDAP_BEGIN_DECL
16
17 /* #define BDB_HIER             1 */
18
19 #define DN_BASE_PREFIX          SLAP_INDEX_EQUALITY_PREFIX
20 #define DN_ONE_PREFIX           '%'
21 #define DN_SUBTREE_PREFIX       '@'
22
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 )
28
29 #define BDB_TXN_RETRIES         16
30
31 #define BDB_MAX_ADD_LOOP        30
32
33 #ifdef BDB_SUBDIRS
34 #define BDB_TMP_SUBDIR  "tmp"
35 #define BDB_LG_SUBDIR   "log"
36 #define BDB_DATA_SUBDIR "data"
37 #endif
38
39 #define BDB_SUFFIX              ".bdb"
40 #define BDB_ID2ENTRY    0
41 #ifdef BDB_HIER
42 #define BDB_ID2PARENT           1
43 #else
44 #define BDB_DN2ID               1
45 #endif
46 #define BDB_NDB                 2
47
48 /* The bdb on-disk entry format is pretty space-inefficient. Average
49  * sized user entries are 3-4K each. You need at least two entries to
50  * fit into a single database page, more is better. 64K is BDB's
51  * upper bound. Smaller pages are better for concurrency.
52  */
53 #ifndef BDB_ID2ENTRY_PAGESIZE
54 #define BDB_ID2ENTRY_PAGESIZE   16384
55 #endif
56
57 #ifndef BDB_PAGESIZE
58 #define BDB_PAGESIZE    4096    /* BDB's original default */
59 #endif
60
61 #define DEFAULT_CACHE_SIZE     1000
62
63 /* The default search IDL stack cache depth */
64 #define DEFAULT_SEARCH_STACK_DEPTH      16
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 /* for the in-core cache of entries */
81 typedef struct bdb_cache {
82         int             c_maxsize;
83         int             c_cursize;
84         Avlnode         *c_dntree;
85         Avlnode         *c_idtree;
86         Entry           *c_lruhead;     /* lru - add accessed entries here */
87         Entry           *c_lrutail;     /* lru - rem lru entries from here */
88         ldap_pvt_thread_rdwr_t c_rwlock;
89         ldap_pvt_thread_mutex_t lru_mutex;
90 } Cache;
91  
92 #define CACHE_READ_LOCK                0
93 #define CACHE_WRITE_LOCK       1
94  
95 #define BDB_INDICES             128
96
97 struct bdb_db_info {
98         char            *bdi_name;
99         DB                      *bdi_db;
100 };
101
102 struct bdb_info {
103         DB_ENV          *bi_dbenv;
104
105         /* DB_ENV parameters */
106         /* The DB_ENV can be tuned via DB_CONFIG */
107         char            *bi_dbenv_home;
108         u_int32_t       bi_dbenv_xflags; /* extra flags */
109         int                     bi_dbenv_mode;
110
111         int                     bi_ndatabases;
112         struct bdb_db_info **bi_databases;
113         int             bi_db_opflags;  /* db-specific flags */
114
115         slap_mask_t     bi_defaultmask;
116         Cache           bi_cache;
117         Avlnode         *bi_attrs;
118         void            *bi_search_stack;
119         int             bi_search_stack_depth;
120 #ifdef BDB_HIER
121         Avlnode         *bi_tree;
122         ldap_pvt_thread_rdwr_t  bi_tree_rdwr;
123         void            *bi_troot;
124 #endif
125
126         int                     bi_txn_cp;
127         u_int32_t       bi_txn_cp_min;
128         u_int32_t       bi_txn_cp_kbyte;
129
130         int                     bi_lock_detect;
131
132         ID                      bi_lastid;
133         ldap_pvt_thread_mutex_t bi_lastid_mutex;
134 #if defined(LDAP_CLIENT_UPDATE) || defined(LDAP_SYNC)
135         LDAP_LIST_HEAD(pl, slap_op) bi_psearch_list;
136 #endif
137 #ifdef SLAP_IDL_CACHE
138         int             bi_idl_cache_max_size;
139         int             bi_idl_cache_size;
140         Avlnode         *bi_idl_tree;
141         bdb_idl_cache_entry_t   *bi_idl_lru_head;
142         bdb_idl_cache_entry_t   *bi_idl_lru_tail;
143         ldap_pvt_thread_mutex_t bi_idl_tree_mutex;
144 #endif
145 };
146
147 #define bi_id2entry     bi_databases[BDB_ID2ENTRY]
148 #ifdef BDB_HIER
149 #define bi_id2parent    bi_databases[BDB_ID2PARENT]
150 #else
151 #define bi_dn2id        bi_databases[BDB_DN2ID]
152 #endif
153
154 struct bdb_op_info {
155         BackendDB*      boi_bdb;
156         DB_TXN*         boi_txn;
157         DB_LOCK         boi_lock;       /* used when no txn */
158         u_int32_t       boi_err;
159         u_int32_t       boi_locker;
160         int             boi_acl_cache;
161 };
162
163 #define DB_OPEN(db, txn, file, name, type, flags, mode) \
164         (db)->open(db, file, name, type, flags, mode)
165
166 #if DB_VERSION_MAJOR < 4
167 #define LOCK_DETECT(env,f,t,a)          lock_detect(env, f, t, a)
168 #define LOCK_GET(env,i,f,o,m,l)         lock_get(env, i, f, o, m, l)
169 #define LOCK_PUT(env,l)                 lock_put(env, l)
170 #define TXN_CHECKPOINT(env,k,m,f)       txn_checkpoint(env, k, m, f)
171 #define TXN_BEGIN(env,p,t,f)            txn_begin((env), p, t, f)
172 #define TXN_PREPARE(txn,gid)            txn_prepare((txn), (gid))
173 #define TXN_COMMIT(txn,f)                       txn_commit((txn), (f))
174 #define TXN_ABORT(txn)                          txn_abort((txn))
175 #define TXN_ID(txn)                                     txn_id(txn)
176 #define XLOCK_ID(env, locker)           lock_id(env, locker)
177 #define XLOCK_ID_FREE(env, locker)      lock_id_free(env, locker)
178 #else
179 #define LOCK_DETECT(env,f,t,a)          (env)->lock_detect(env, f, t, a)
180 #define LOCK_GET(env,i,f,o,m,l)         (env)->lock_get(env, i, f, o, m, l)
181 #define LOCK_PUT(env,l)                 (env)->lock_put(env, l)
182 #define TXN_CHECKPOINT(env,k,m,f)       (env)->txn_checkpoint(env, k, m, f)
183 #define TXN_BEGIN(env,p,t,f)            (env)->txn_begin((env), p, t, f)
184 #define TXN_PREPARE(txn,g)                      (txn)->prepare((txn), (g))
185 #define TXN_COMMIT(txn,f)                       (txn)->commit((txn), (f))
186 #define TXN_ABORT(txn)                          (txn)->abort((txn))
187 #define TXN_ID(txn)                                     (txn)->id(txn)
188 #define XLOCK_ID(env, locker)           (env)->lock_id(env, locker)
189 #define XLOCK_ID_FREE(env, locker)      (env)->lock_id_free(env, locker)
190
191 /* BDB 4.1.17 adds txn arg to db->open */
192 #if DB_VERSION_MINOR > 1 || DB_VERSION_PATCH >= 17
193 #undef DB_OPEN
194 #define DB_OPEN(db, txn, file, name, type, flags, mode) \
195         (db)->open(db, txn, file, name, type, flags, mode)
196 #endif
197
198 #define BDB_REUSE_LOCKERS
199
200 #ifdef BDB_REUSE_LOCKERS
201 #define LOCK_ID_FREE(env, locker)
202 #define LOCK_ID(env, locker)    bdb_locker_id(op, env, locker)
203 #else
204 #define LOCK_ID_FREE(env, locker)       XLOCK_ID_FREE(env, locker)
205 #define LOCK_ID(env, locker)            XLOCK_ID(env, locker)
206 #endif
207
208 #endif
209
210 LDAP_END_DECL
211
212 #include "proto-bdb.h"
213
214 #endif /* _BACK_BDB_H_ */