]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/back-bdb2.h
Use #ifdef, not #if
[openldap] / servers / slapd / back-bdb2 / back-bdb2.h
1 /* back-bdb2.h - ldap bdb2 back-end header file */
2 /* $OpenLDAP$ */
3
4 #ifndef _BACK_BDB2_H_
5 #define _BACK_BDB2_H_
6
7 #include "ldbm.h"
8 #include "db.h"
9
10 LDAP_BEGIN_DECL
11
12 #define DEFAULT_CACHE_SIZE      1000
13
14 /*  since DEFAULT_DB_PAGE_SIZE is 1K, we have 128K,
15         which is suggested by Sleepycat  */
16 #define DEFAULT_DBCACHE_SIZE (128 * DEFAULT_DB_PAGE_SIZE)
17
18 #define DEFAULT_DB_DIRECTORY    LDAP_RUNDIR LDAP_DIRSEP "openldap-bdb2"
19 #define DEFAULT_DB_HOME         DEFAULT_DB_DIRECTORY
20 #define DEFAULT_MODE            0600
21
22 #define SUBLEN                  3
23
24 #define DN_BASE_PREFIX          '='
25 #define DN_ONE_PREFIX           '@'
26 #define DN_SUBTREE_PREFIX       '?'
27     
28 #define BDB2_SUFFIX     ".bdb2"
29
30
31 /*
32  * there is a single index for each attribute.  these prefixes ensure
33  * that there is no collision among keys.
34  */
35 #define EQ_PREFIX       '='     /* prefix for equality keys     */
36 #define APPROX_PREFIX   '~'     /* prefix for approx keys       */
37 #define SUB_PREFIX      '*'     /* prefix for substring keys    */
38 #define CONT_PREFIX     '\\'    /* prefix for continuation keys */
39
40 /* allow 3 characters per byte + PREFIX + EOS */
41 #define CONT_SIZE       ( sizeof(long)*3 + 1 + 1 )
42
43
44 #define UNKNOWN_PREFIX  '?'     /* prefix for unknown keys    */
45
46 #define DEFAULT_BLOCKSIZE       8192
47
48 /*
49  * This structure represents an id block on disk and an id list
50  * in core.
51  *
52  * The fields have the following meanings:
53  *
54  *      b_nmax  maximum number of ids in this block. if this is == ALLIDSBLOCK,
55  *              then this block represents all ids.
56  *      b_nids  current number of ids in use in this block.  if this
57  *              is == INDBLOCK, then this block is an indirect block
58  *              containing a list of other blocks containing actual ids.
59  *              the list is terminated by an id of NOID.
60  *      b_ids   a list of the actual ids themselves
61  */
62
63 typedef ID ID_BLOCK;
64
65 #define ID_BLOCK_NMAX_OFFSET    0
66 #define ID_BLOCK_NIDS_OFFSET    1
67 #define ID_BLOCK_IDS_OFFSET             2
68
69 /* all ID_BLOCK macros operate on a pointer to a ID_BLOCK */
70
71 #define ID_BLOCK_NMAX(b)                ((b)[ID_BLOCK_NMAX_OFFSET])
72 #define ID_BLOCK_NIDS(b)                ((b)[ID_BLOCK_NIDS_OFFSET])
73 #define ID_BLOCK_ID(b, n)               ((b)[ID_BLOCK_IDS_OFFSET+(n)])
74
75 #define ID_BLOCK_NOID(b, n)             (ID_BLOCK_ID((b),(n)) == NOID)
76
77 #define ID_BLOCK_ALLIDS_VALUE   0
78 #define ID_BLOCK_ALLIDS(b)              (ID_BLOCK_NMAX(b) == ID_BLOCK_ALLIDS_VALUE)
79
80 #define ID_BLOCK_INDIRECT_VALUE 0
81 #define ID_BLOCK_INDIRECT(b)    (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
82
83 /* for the in-core cache of entries */
84 struct cache {
85         int             c_maxsize;
86         int             c_cursize;
87         Avlnode         *c_dntree;
88         Avlnode         *c_idtree;
89         Entry           *c_lruhead;     /* lru - add accessed entries here */
90         Entry           *c_lrutail;     /* lru - rem lru entries from here */
91         ldap_pvt_thread_mutex_t c_mutex;
92 };
93
94 #define CACHE_READ_LOCK         0
95 #define CACHE_WRITE_LOCK        1
96
97 /* for the cache of open index files (re-used for txn) */
98 struct dbcache {
99         int                     dbc_refcnt;
100         int                     dbc_maxids;
101         int                     dbc_maxindirect;
102         long            dbc_blksize;
103         char            *dbc_name;
104         LDBM            dbc_db;
105
106         struct dbcache   *next;
107 };
108
109 typedef  struct dbcache  BDB2_TXN_FILES;
110 typedef  struct dbcache DBCache;
111
112
113 /* for the cache of attribute information (which are indexed, etc.) */
114 struct attrinfo {
115         char    *ai_type;       /* type name (cn, sn, ...)      */
116         int     ai_indexmask;   /* how the attr is indexed      */
117 #define INDEX_PRESENCE  0x0001
118 #define INDEX_EQUALITY  0x0002
119 #define INDEX_APPROX    0x0004
120 #define INDEX_SUB               0x0008
121 #define INDEX_UNKNOWN   0x0010
122 #define INDEX_FROMINIT  0x1000
123         int     ai_syntaxmask;  /* what kind of syntax          */
124 /* ...from slap.h...
125 #define SYNTAX_CIS      0x01
126 #define SYNTAX_CES      0x02
127 #define SYNTAX_BIN      0x04
128    ... etc. ...
129 */
130 };
131
132 /*  TP stuff  */
133
134 typedef  struct _bdb2_txn_head {
135
136         /*  log size and timer to control checkpoints  */
137         u_int32_t        txn_log;
138         u_int32_t        txn_time;
139
140         /*  a list of all DB files in use  */
141         BDB2_TXN_FILES   *dbFiles;
142
143         /*  we have five fixed files  */
144 #define  BDB2_DB_DN_FILE            0
145 #define  BDB2_DB_DN2ID_FILE         1
146 #define  BDB2_DB_ID2ENTRY_FILE      2
147 #define  BDB2_DB_ID2CHILDREN_FILE   3
148 #define  BDB2_DB_OC_IDX_FILE        4
149
150         /*  a database handle for the NEXTID file
151                 (must be opened like all DB files at startup
152                 and closed on shutdown  */
153         LDBM             nextidFile;
154
155         /*  is the default attribute index set to non-none  */
156         int              withDefIDX;
157 #define  BDB2_WITH_DEF_IDX          1
158
159         /*  a handle for the backend's environment  */
160         DB_ENV           **dbenvH;
161
162 } BDB2_TXN_HEAD;
163
164
165 /*  end of TP stuff  */
166
167
168 /*  the private description of a backend type  */
169 struct ldbtype {
170         char                    *lty_dbhome;
171         size_t                  lty_mpsize;
172         int                             lty_betiming;
173 };
174
175 #define with_timing(bi) (((struct ldbtype *) \
176                         (bi)->bi_private)->lty_betiming == 1)
177
178 /*  The DB environment  */
179 extern DB_ENV       bdb2i_dbEnv;
180
181
182 /*  the private description of a database  */
183 struct ldbminfo {
184         ID                      li_nextid;
185         char            *li_nextid_file;
186         int                     li_mode;
187         char                    *li_directory;
188         struct cache            li_cache;
189         Avlnode                 *li_attrs;
190         int                     li_dbcachesize;
191
192         /*  a list of all files of the database  */
193         BDB2_TXN_HEAD           li_txn_head;
194 };
195
196
197 #include "proto-back-bdb2.h"
198
199 LDAP_END_DECL
200
201 #endif /* _back_bdb2_h_ */