]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/back-bdb.h
Some fixes for BDB_IDL_MULTI. Experimental back-hdb code.
[openldap] / servers / slapd / back-bdb / back-bdb.h
1 /* back-bdb.h - bdb back-end header file */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 2000-2001 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_FILTER_INDICES 1
19 /* #define BDB_IDL_MULTI                1 */
20 /* #define BDB_HIER             1 */
21
22 #define DN_BASE_PREFIX          SLAP_INDEX_EQUALITY_PREFIX
23 #define DN_ONE_PREFIX           '%'
24 #define DN_SUBTREE_PREFIX       '@'
25
26 #define DBTzero(t)                      (memset((t), 0, sizeof(DBT)))
27 #define DBT2bv(t,bv)            ((bv)->bv_val = (t)->data, \
28                                                                 (bv)->bv_len = (t)->size)
29 #define bv2DBT(bv,t)            ((t)->data = (bv)->bv_val, \
30                                                                 (t)->size = (bv)->bv_len )
31
32 #define DEFAULT_MODE            0600
33
34 #define BDB_TXN_RETRIES 16
35
36 #ifdef BDB_HIER
37 #define BDB_DBENV_HOME  LDAP_RUNDIR LDAP_DIRSEP "openldap-hdb"
38 #else
39 #define BDB_DBENV_HOME  LDAP_RUNDIR LDAP_DIRSEP "openldap-bdb"
40 #endif
41
42 #ifdef BDB_SUBDIRS
43 #define BDB_TMP_SUBDIR  LDAP_DIRSEP "tmp"
44 #define BDB_LG_SUBDIR   LDAP_DIRSEP "log"
45 #define BDB_DATA_SUBDIR LDAP_DIRSEP "data"
46 #endif
47
48 #define BDB_SUFFIX              ".bdb"
49 #define BDB_ID2ENTRY    0
50 #ifdef BDB_HIER
51 #define BDB_ID2PARENT           1
52 #else
53 #define BDB_DN2ID               1
54 #endif
55 #define BDB_NDB                 2
56
57 /* The bdb on-disk entry format is pretty space-inefficient. Average
58  * sized user entries are 3-4K each. You need at least two entries to
59  * fit into a single database page, more is better. 64K is BDB's
60  * upper bound. The same issues arise with IDLs in the index databases,
61  * but it's nearly impossible to avoid overflows there.
62  *
63  * When using BDB_IDL_MULTI, the IDL size is no longer an issue. Smaller
64  * pages are better for concurrency.
65  */
66 #ifndef BDB_ID2ENTRY_PAGESIZE
67 #define BDB_ID2ENTRY_PAGESIZE   16384
68 #endif
69
70 #ifndef BDB_PAGESIZE
71 #ifdef BDB_IDL_MULTI
72 #define BDB_PAGESIZE    4096    /* BDB's original default */
73 #else
74 #define BDB_PAGESIZE    16384
75 #endif
76 #endif
77
78 #define BDB_INDICES             128
79
80 struct bdb_db_info {
81         char            *bdi_name;
82         DB                      *bdi_db;
83 };
84
85 struct bdb_info {
86         DB_ENV          *bi_dbenv;
87
88         /* DB_ENV parameters */
89         /* The DB_ENV can be tuned via DB_CONFIG */
90         char            *bi_dbenv_home;
91         u_int32_t       bi_dbenv_xflags; /* extra flags */
92         int                     bi_dbenv_mode;
93
94         int                     bi_ndatabases;
95         struct bdb_db_info **bi_databases;
96         ldap_pvt_thread_mutex_t bi_database_mutex;
97         int             bi_db_opflags;  /* db-specific flags */
98
99         slap_mask_t     bi_defaultmask;
100         Avlnode         *bi_attrs;
101 #ifdef BDB_HIER
102         Avlnode         *bi_tree;
103         ldap_pvt_thread_rdwr_t  bi_tree_rdwr;
104         void            *bi_troot;
105         int             bi_nrdns;
106         int             bi_sufflen;
107         int             bi_nsufflen;
108 #endif
109
110         int             bi_txn;
111         int                     bi_txn_cp;
112         u_int32_t       bi_txn_cp_min;
113         u_int32_t       bi_txn_cp_kbyte;
114
115 #ifndef NO_THREADS
116         int                     bi_lock_detect;
117         int                     bi_lock_detect_seconds;
118         ldap_pvt_thread_t       bi_lock_detect_tid;
119 #endif
120
121         ID                      bi_lastid;
122         ldap_pvt_thread_mutex_t bi_lastid_mutex;
123 };
124
125 #define bi_id2entry     bi_databases[BDB_ID2ENTRY]
126 #ifdef BDB_HIER
127 #define bi_id2parent    bi_databases[BDB_ID2PARENT]
128 #else
129 #define bi_dn2id        bi_databases[BDB_DN2ID]
130 #endif
131
132 struct bdb_op_info {
133         BackendDB*      boi_bdb;
134         DB_TXN*         boi_txn;
135         int                     boi_err;
136 };
137
138 #if DB_VERSION_MAJOR < 4
139 #define TXN_CHECKPOINT(env, k, m, f)    txn_checkpoint(env, k, m, f)
140 #define LOCK_DETECT(env, f, t, a)       lock_detect(env, f, t, a)
141 #else
142 #define TXN_CHECKPOINT(env, k, m, f)    (env)->txn_checkpoint(env, k, m, f)
143 #define LOCK_DETECT(env, f, t, a)       (env)->lock_detect(env, f, t, a)
144 #endif
145
146 LDAP_END_DECL
147
148 #include "proto-bdb.h"
149
150 #endif /* _BACK_BDB_H_ */