]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/back-bdb.h
Hallvard B. Furuseth's patch for cache lock and mutex
[openldap] / servers / slapd / back-bdb / back-bdb.h
1 /* back-bdb.h - bdb back-end header file */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 2000-2002 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 <db.h>
13
14 #include "slap.h"
15
16 LDAP_BEGIN_DECL
17
18 #define BDB_IDL_MULTI           1
19 /* #define BDB_HIER             1 */
20
21 #define DN_BASE_PREFIX          SLAP_INDEX_EQUALITY_PREFIX
22 #define DN_ONE_PREFIX           '%'
23 #define DN_SUBTREE_PREFIX       '@'
24
25 #define DBTzero(t)                      (memset((t), 0, sizeof(DBT)))
26 #define DBT2bv(t,bv)            ((bv)->bv_val = (t)->data, \
27                                                                 (bv)->bv_len = (t)->size)
28 #define bv2DBT(bv,t)            ((t)->data = (bv)->bv_val, \
29                                                                 (t)->size = (bv)->bv_len )
30
31 #define BDB_TXN_RETRIES 16
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. The same issues arise with IDLs in the index databases,
52  * but it's nearly impossible to avoid overflows there.
53  *
54  * When using BDB_IDL_MULTI, the IDL size is no longer an issue. Smaller
55  * pages are better for concurrency.
56  */
57 #ifndef BDB_ID2ENTRY_PAGESIZE
58 #define BDB_ID2ENTRY_PAGESIZE   16384
59 #endif
60
61 #ifndef BDB_PAGESIZE
62 #ifdef BDB_IDL_MULTI
63 #define BDB_PAGESIZE    4096    /* BDB's original default */
64 #else
65 #define BDB_PAGESIZE    16384
66 #endif
67 #endif
68
69 #define DEFAULT_CACHE_SIZE     1000
70
71 /* for the in-core cache of entries */
72 typedef struct bdb_cache {
73         int             c_maxsize;
74         int             c_cursize;
75         Avlnode         *c_dntree;
76         Avlnode         *c_idtree;
77         Entry           *c_lruhead;     /* lru - add accessed entries here */
78         Entry           *c_lrutail;     /* lru - rem lru entries from here */
79         ldap_pvt_thread_rdwr_t c_rwlock;
80         ldap_pvt_thread_mutex_t lru_mutex;
81 } Cache;
82  
83 #define CACHE_READ_LOCK                0
84 #define CACHE_WRITE_LOCK       1
85  
86 #define BDB_INDICES             128
87
88 struct bdb_db_info {
89         char            *bdi_name;
90         DB                      *bdi_db;
91 };
92
93 struct bdb_info {
94         DB_ENV          *bi_dbenv;
95
96         /* DB_ENV parameters */
97         /* The DB_ENV can be tuned via DB_CONFIG */
98         char            *bi_dbenv_home;
99         u_int32_t       bi_dbenv_xflags; /* extra flags */
100         int                     bi_dbenv_mode;
101
102         int                     bi_ndatabases;
103         struct bdb_db_info **bi_databases;
104         ldap_pvt_thread_mutex_t bi_database_mutex;
105         int             bi_db_opflags;  /* db-specific flags */
106
107         slap_mask_t     bi_defaultmask;
108         Cache           bi_cache;
109         Avlnode         *bi_attrs;
110 #ifdef BDB_HIER
111         Avlnode         *bi_tree;
112         ldap_pvt_thread_rdwr_t  bi_tree_rdwr;
113         void            *bi_troot;
114         int             bi_nrdns;
115 #endif
116
117         int                     bi_txn_cp;
118         u_int32_t       bi_txn_cp_min;
119         u_int32_t       bi_txn_cp_kbyte;
120
121 #ifndef NO_THREADS
122         int                     bi_lock_detect;
123         int                     bi_lock_detect_seconds;
124         ldap_pvt_thread_t       bi_lock_detect_tid;
125 #endif
126
127         ID                      bi_lastid;
128         ldap_pvt_thread_mutex_t bi_lastid_mutex;
129 };
130
131 #define bi_id2entry     bi_databases[BDB_ID2ENTRY]
132 #ifdef BDB_HIER
133 #define bi_id2parent    bi_databases[BDB_ID2PARENT]
134 #else
135 #define bi_dn2id        bi_databases[BDB_DN2ID]
136 #endif
137
138 struct bdb_op_info {
139         BackendDB*      boi_bdb;
140         DB_TXN*         boi_txn;
141         int                     boi_err;
142 };
143
144 #if DB_VERSION_MAJOR < 4
145 #define LOCK_DETECT(env,f,t,a)          lock_detect(env, f, t, a)
146 #define LOCK_GET(env,i,f,o,m,l)         lock_get(env, i, f, o, m, l)
147 #define TXN_CHECKPOINT(env,k,m,f)       txn_checkpoint(env, k, m, f)
148 #define TXN_BEGIN(env,p,t,f)            txn_begin((env), p, t, f)
149 #define TXN_PREPARE(txn,gid)            txn_prepare((txn), (gid))
150 #define TXN_COMMIT(txn,f)                       txn_commit((txn), (f))
151 #define TXN_ABORT(txn)                          txn_abort((txn))
152 #define TXN_ID(txn)                                     txn_id(txn)
153 #else
154 #define LOCK_DETECT(env,f,t,a)          (env)->lock_detect(env, f, t, a)
155 #define LOCK_GET(env,i,f,o,m,l)         (env)->lock_get(env, i, f, o, m, l)
156 #define TXN_CHECKPOINT(env,k,m,f)       (env)->txn_checkpoint(env, k, m, f)
157 #define TXN_BEGIN(env,p,t,f)            (env)->txn_begin((env), p, t, f)
158 #define TXN_PREPARE(txn,g)                      (txn)->prepare((txn), (g))
159 #define TXN_COMMIT(txn,f)                       (txn)->commit((txn), (f))
160 #define TXN_ABORT(txn)                          (txn)->abort((txn))
161 #define TXN_ID(txn)                                     (txn)->id(txn)
162 #endif
163
164 LDAP_END_DECL
165
166 #include "proto-bdb.h"
167
168 #endif /* _BACK_BDB_H_ */