]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/back-bdb.h
uses URL extensions to set socket permissions other than default
[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_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 DEFAULT_CACHE_SIZE     1000
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_mutex_t c_mutex;
89 } Cache;
90  
91 #define CACHE_READ_LOCK                0
92 #define CACHE_WRITE_LOCK       1
93  
94 #define BDB_INDICES             128
95
96 struct bdb_db_info {
97         char            *bdi_name;
98         DB                      *bdi_db;
99 };
100
101 struct bdb_info {
102         DB_ENV          *bi_dbenv;
103
104         /* DB_ENV parameters */
105         /* The DB_ENV can be tuned via DB_CONFIG */
106         char            *bi_dbenv_home;
107         u_int32_t       bi_dbenv_xflags; /* extra flags */
108         int                     bi_dbenv_mode;
109
110         int                     bi_ndatabases;
111         struct bdb_db_info **bi_databases;
112         ldap_pvt_thread_mutex_t bi_database_mutex;
113         int             bi_db_opflags;  /* db-specific flags */
114
115         slap_mask_t     bi_defaultmask;
116         Cache           bi_cache;
117         Avlnode         *bi_attrs;
118 #ifdef BDB_HIER
119         Avlnode         *bi_tree;
120         ldap_pvt_thread_rdwr_t  bi_tree_rdwr;
121         void            *bi_troot;
122         int             bi_nrdns;
123 #endif
124
125         int                     bi_txn;
126         int                     bi_txn_cp;
127         u_int32_t       bi_txn_cp_min;
128         u_int32_t       bi_txn_cp_kbyte;
129
130 #ifndef NO_THREADS
131         int                     bi_lock_detect;
132         int                     bi_lock_detect_seconds;
133         ldap_pvt_thread_t       bi_lock_detect_tid;
134 #endif
135
136         ID                      bi_lastid;
137         ldap_pvt_thread_mutex_t bi_lastid_mutex;
138 };
139
140 #define bi_id2entry     bi_databases[BDB_ID2ENTRY]
141 #ifdef BDB_HIER
142 #define bi_id2parent    bi_databases[BDB_ID2PARENT]
143 #else
144 #define bi_dn2id        bi_databases[BDB_DN2ID]
145 #endif
146
147 struct bdb_op_info {
148         BackendDB*      boi_bdb;
149         DB_TXN*         boi_txn;
150         int                     boi_err;
151 };
152
153 #if DB_VERSION_MAJOR < 4
154 #define TXN_CHECKPOINT(env, k, m, f)    txn_checkpoint(env, k, m, f)
155 #define TXN_ID(txn)                     txn_id(txn)
156 #define LOCK_DETECT(env, f, t, a)       lock_detect(env, f, t, a)
157 #define LOCK_GET(env, i, f, o, m, l)    lock_get(env, i, f, o, m, l)
158 #else
159 #define TXN_CHECKPOINT(env, k, m, f)    (env)->txn_checkpoint(env, k, m, f)
160 #define TXN_ID(txn)                     (txn)->id(txn)
161 #define LOCK_DETECT(env, f, t, a)       (env)->lock_detect(env, f, t, a)
162 #define LOCK_GET(env, i, f, o, m, l)    (env)->lock_get(env, i, f, o, m, l)
163 #endif
164
165 LDAP_END_DECL
166
167 #include "proto-bdb.h"
168
169 #endif /* _BACK_BDB_H_ */