]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/back-bdb.h
LDAP Sync Operation (draft-zeilenga-ldup-sync) as a groundwork for an LDAP replicatio...
[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  LDAP_DIRSEP "tmp"
35 #define BDB_LG_SUBDIR   LDAP_DIRSEP "log"
36 #define BDB_DATA_SUBDIR LDAP_DIRSEP "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         ldap_pvt_thread_mutex_t bi_database_mutex;
114         int             bi_db_opflags;  /* db-specific flags */
115
116         slap_mask_t     bi_defaultmask;
117         Cache           bi_cache;
118         Avlnode         *bi_attrs;
119         void            *bi_search_stack;
120         int             bi_search_stack_depth;
121 #ifdef BDB_HIER
122         Avlnode         *bi_tree;
123         ldap_pvt_thread_rdwr_t  bi_tree_rdwr;
124         void            *bi_troot;
125 #endif
126
127         int                     bi_txn_cp;
128         u_int32_t       bi_txn_cp_min;
129         u_int32_t       bi_txn_cp_kbyte;
130
131         int                     bi_lock_detect;
132
133         ID                      bi_lastid;
134         ldap_pvt_thread_mutex_t bi_lastid_mutex;
135 #if defined(LDAP_CLIENT_UPDATE) || defined(LDAP_SYNC)
136         LDAP_LIST_HEAD(pl, slap_op) psearch_list;
137 #endif
138 #ifdef SLAP_IDL_CACHE
139         int             bi_idl_cache_max_size;
140         int             bi_idl_cache_size;
141         Avlnode         *bi_idl_tree;
142         bdb_idl_cache_entry_t   *bi_idl_lru_head;
143         bdb_idl_cache_entry_t   *bi_idl_lru_tail;
144         ldap_pvt_thread_mutex_t bi_idl_tree_mutex;
145 #endif
146 };
147
148 #define bi_id2entry     bi_databases[BDB_ID2ENTRY]
149 #ifdef BDB_HIER
150 #define bi_id2parent    bi_databases[BDB_ID2PARENT]
151 #else
152 #define bi_dn2id        bi_databases[BDB_DN2ID]
153 #endif
154
155 struct bdb_op_info {
156         BackendDB*      boi_bdb;
157         DB_TXN*         boi_txn;
158         int                     boi_err;
159 };
160
161 #define DB_OPEN(db, file, name, type, flags, mode) \
162         (db)->open(db, file, name, type, flags, mode)
163
164 #if DB_VERSION_MAJOR < 4
165 #define LOCK_DETECT(env,f,t,a)          lock_detect(env, f, t, a)
166 #define LOCK_GET(env,i,f,o,m,l)         lock_get(env, i, f, o, m, l)
167 #define LOCK_PUT(env,l)                 lock_put(env, l)
168 #define TXN_CHECKPOINT(env,k,m,f)       txn_checkpoint(env, k, m, f)
169 #define TXN_BEGIN(env,p,t,f)            txn_begin((env), p, t, f)
170 #define TXN_PREPARE(txn,gid)            txn_prepare((txn), (gid))
171 #define TXN_COMMIT(txn,f)                       txn_commit((txn), (f))
172 #define TXN_ABORT(txn)                          txn_abort((txn))
173 #define TXN_ID(txn)                                     txn_id(txn)
174 #define XLOCK_ID(env, locker)           lock_id(env, locker)
175 #define XLOCK_ID_FREE(env, locker)      lock_id_free(env, locker)
176 #else
177 #define LOCK_DETECT(env,f,t,a)          (env)->lock_detect(env, f, t, a)
178 #define LOCK_GET(env,i,f,o,m,l)         (env)->lock_get(env, i, f, o, m, l)
179 #define LOCK_PUT(env,l)                 (env)->lock_put(env, l)
180 #define TXN_CHECKPOINT(env,k,m,f)       (env)->txn_checkpoint(env, k, m, f)
181 #define TXN_BEGIN(env,p,t,f)            (env)->txn_begin((env), p, t, f)
182 #define TXN_PREPARE(txn,g)                      (txn)->prepare((txn), (g))
183 #define TXN_COMMIT(txn,f)                       (txn)->commit((txn), (f))
184 #define TXN_ABORT(txn)                          (txn)->abort((txn))
185 #define TXN_ID(txn)                                     (txn)->id(txn)
186 #define XLOCK_ID(env, locker)           (env)->lock_id(env, locker)
187 #define XLOCK_ID_FREE(env, locker)      (env)->lock_id_free(env, locker)
188
189 /* BDB 4.1.17 adds txn arg to db->open */
190 #if DB_VERSION_MINOR > 1 || DB_VERSION_PATCH >= 17
191 #undef DB_OPEN
192 #define DB_OPEN(db, file, name, type, flags, mode) \
193         (db)->open(db, NULL, file, name, type, (flags)|DB_AUTO_COMMIT, mode)
194 #endif
195
196 #define BDB_REUSE_LOCKERS
197
198 #ifdef BDB_REUSE_LOCKERS
199 #define LOCK_ID_FREE(env, locker)
200 #define LOCK_ID(env, locker)    bdb_locker_id(op, env, locker)
201 #else
202 #define LOCK_ID_FREE(env, locker)       XLOCK_ID_FREE(env, locker)
203 #define LOCK_ID(env, locker)            XLOCK_ID(env, locker)
204 #endif
205
206 #endif
207
208 LDAP_END_DECL
209
210 #include "proto-bdb.h"
211
212 #endif /* _BACK_BDB_H_ */