]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/back-bdb2.h
Introduction of a new Berkeley DB version 2 (!) specific backend.
[openldap] / servers / slapd / back-bdb2 / back-bdb2.h
1 /* back-bdb2.h - ldap bdb2 back-end header file */
2
3 #ifndef _BACK_BDB2_H_
4 #define _BACK_BDB2_H_
5
6 #include "ldbm.h"
7 #include "db.h"
8
9 LDAP_BEGIN_DECL
10
11 #define DEFAULT_CACHE_SIZE      1000
12
13 /*  since DEFAULT_DB_PAGE_SIZE is 1K, we have 128K,
14         which is suggested by Sleepycat  */
15 #define DEFAULT_DBCACHE_SIZE (128 * DEFAULT_DB_PAGE_SIZE)
16
17 #define DEFAULT_DB_DIRECTORY    "/usr/tmp"
18 #define DEFAULT_MODE            0600
19
20 #define SUBLEN                  3
21
22 /*
23  * there is a single index for each attribute.  these prefixes insure
24  * that there is no collision among keys.
25  */
26 #define EQ_PREFIX       '='     /* prefix for equality keys     */
27 #define APPROX_PREFIX   '~'     /* prefix for approx keys       */
28 #define SUB_PREFIX      '*'     /* prefix for substring keys    */
29 #define CONT_PREFIX     '\\'    /* prefix for continuation keys */
30
31 #define UNKNOWN_PREFIX  '?'     /* prefix for unknown keys    */
32
33 #define DEFAULT_BLOCKSIZE       8192
34
35 /*
36  * This structure represents an id block on disk and an id list
37  * in core.
38  *
39  * The fields have the following meanings:
40  *
41  *      b_nmax  maximum number of ids in this block. if this is == ALLIDSBLOCK,
42  *              then this block represents all ids.
43  *      b_nids  current number of ids in use in this block.  if this
44  *              is == INDBLOCK, then this block is an indirect block
45  *              containing a list of other blocks containing actual ids.
46  *              the list is terminated by an id of NOID.
47  *      b_ids   a list of the actual ids themselves
48  */
49
50 typedef ID ID_BLOCK;
51
52 #define ID_BLOCK_NMAX_OFFSET    0
53 #define ID_BLOCK_NIDS_OFFSET    1
54 #define ID_BLOCK_IDS_OFFSET             2
55
56 /* all ID_BLOCK macros operate on a pointer to a ID_BLOCK */
57
58 #define ID_BLOCK_NMAX(b)                ((b)[ID_BLOCK_NMAX_OFFSET])
59 #define ID_BLOCK_NIDS(b)                ((b)[ID_BLOCK_NIDS_OFFSET])
60 #define ID_BLOCK_ID(b, n)               ((b)[ID_BLOCK_IDS_OFFSET+(n)])
61
62 #define ID_BLOCK_NOID(b, n)             (ID_BLOCK_ID((b),(n)) == NOID)
63
64 #define ID_BLOCK_ALLIDS_VALUE   0
65 #define ID_BLOCK_ALLIDS(b)              (ID_BLOCK_NMAX(b) == ID_BLOCK_ALLIDS_VALUE)
66
67 #define ID_BLOCK_INDIRECT_VALUE 0
68 #define ID_BLOCK_INDIRECT(b)    (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
69
70 /* for the in-core cache of entries */
71 struct cache {
72         int             c_maxsize;
73         int             c_cursize;
74         Avlnode         *c_dntree;
75         Avlnode         *c_idtree;
76         Entry           *c_lruhead;     /* lru - add accessed entries here */
77         Entry           *c_lrutail;     /* lru - rem lru entries from here */
78         ldap_pvt_thread_mutex_t c_mutex;
79 };
80
81 /* for the cache of open index files (re-used for txn) */
82 struct dbcache {
83         int                     dbc_refcnt;
84         int                     dbc_maxids;
85         int                     dbc_maxindirect;
86         time_t          dbc_lastref;
87         long            dbc_blksize;
88         char            *dbc_name;
89         LDBM            dbc_db;
90
91         struct dbcache   *next;
92 };
93
94 typedef  struct dbcache  BDB2_TXN_FILES;
95
96
97 /* for the cache of attribute information (which are indexed, etc.) */
98 struct attrinfo {
99         char    *ai_type;       /* type name (cn, sn, ...)      */
100         int     ai_indexmask;   /* how the attr is indexed      */
101 #define INDEX_PRESENCE  0x01
102 #define INDEX_EQUALITY  0x02
103 #define INDEX_APPROX    0x04
104 #define INDEX_SUB       0x08
105 #define INDEX_UNKNOWN   0x10
106 #define INDEX_FROMINIT  0x20
107         int     ai_syntaxmask;  /* what kind of syntax          */
108 /* ...from slap.h...
109 #define SYNTAX_CIS      0x01
110 #define SYNTAX_CES      0x02
111 #define SYNTAX_BIN      0x04
112    ... etc. ...
113 */
114 };
115
116 #define MAXDBCACHE      10
117
118 /* this could be made an option */
119 #ifndef SLAPD_NEXTID_CHUNK
120 #define SLAPD_NEXTID_CHUNK      32
121 #endif
122
123
124 /*  TP stuff  */
125
126 typedef  struct _bdb2_txn_head {
127
128         /*  counter and timer to control checkpoints  */
129         size_t           txn_cnt;
130         time_t           txn_chkp;
131
132         /*  a list of all DB files in use  */
133         BDB2_TXN_FILES   *dbFiles;
134
135         /*  for performance reasons we have pointers to fixed descriptors  */
136         BDB2_TXN_FILES   *dbFileHandle[4];
137 #define  BDB2_DB_DN_FILE            0
138 #define  BDB2_DB_DN2ID_FILE         1
139 #define  BDB2_DB_ID2ENTRY_FILE      2
140 #define  BDB2_DB_ID2CHILDREN_FILE   3
141 #define  BDB2_DB_OC_IDX_FILE        4
142
143         /*  is the default attribute index set to non-none  */
144         int              withDefIDX;
145 #define  BDB2_WITH_DEF_IDX          1
146
147 } BDB2_TXN_HEAD;
148
149
150 /*  end of TP stuff  */
151
152 struct ldbminfo {
153         ID                      li_nextid;
154 #if SLAPD_NEXTID_CHUNK > 1
155         ID                      li_nextid_wrote;
156 #endif
157         char            *li_nextid_file;
158         ldap_pvt_thread_mutex_t         li_root_mutex;
159         ldap_pvt_thread_mutex_t         li_add_mutex;
160         ldap_pvt_thread_mutex_t         li_nextid_mutex;
161         int                     li_mode;
162         char                    *li_directory;
163         struct cache            li_cache;
164         Avlnode                 *li_attrs;
165         int                     li_dbcachesize;
166         int                     li_dbcachewsync;
167         struct dbcache          li_dbcache[MAXDBCACHE];
168         ldap_pvt_thread_mutex_t         li_dbcache_mutex;
169         ldap_pvt_thread_cond_t          li_dbcache_cv;
170
171         /*  Berkeley DB2 Environment  */
172         DB_ENV                  li_db_env;
173         char                    *li_dbhome;
174         BDB2_TXN_HEAD           li_txn_head;
175
176 };
177
178
179 extern  int bdb2i_with_dbenv;
180
181 #include "proto-back-bdb2.h"
182
183 LDAP_END_DECL
184
185 #endif /* _back_bdb2_h_ */