]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/back-bdb2.h
Integration of the BDB2 backend into the new init/startup/shutdown schema.
[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_DB_HOME         "/usr/tmp"
19 #define DEFAULT_MODE            0600
20
21 #define SUBLEN                  3
22
23 /*
24  * there is a single index for each attribute.  these prefixes insure
25  * that there is no collision among keys.
26  */
27 #define EQ_PREFIX       '='     /* prefix for equality keys     */
28 #define APPROX_PREFIX   '~'     /* prefix for approx keys       */
29 #define SUB_PREFIX      '*'     /* prefix for substring keys    */
30 #define CONT_PREFIX     '\\'    /* prefix for continuation keys */
31
32 #define UNKNOWN_PREFIX  '?'     /* prefix for unknown keys    */
33
34 #define DEFAULT_BLOCKSIZE       8192
35
36 /*
37  * This structure represents an id block on disk and an id list
38  * in core.
39  *
40  * The fields have the following meanings:
41  *
42  *      b_nmax  maximum number of ids in this block. if this is == ALLIDSBLOCK,
43  *              then this block represents all ids.
44  *      b_nids  current number of ids in use in this block.  if this
45  *              is == INDBLOCK, then this block is an indirect block
46  *              containing a list of other blocks containing actual ids.
47  *              the list is terminated by an id of NOID.
48  *      b_ids   a list of the actual ids themselves
49  */
50
51 typedef ID ID_BLOCK;
52
53 #define ID_BLOCK_NMAX_OFFSET    0
54 #define ID_BLOCK_NIDS_OFFSET    1
55 #define ID_BLOCK_IDS_OFFSET             2
56
57 /* all ID_BLOCK macros operate on a pointer to a ID_BLOCK */
58
59 #define ID_BLOCK_NMAX(b)                ((b)[ID_BLOCK_NMAX_OFFSET])
60 #define ID_BLOCK_NIDS(b)                ((b)[ID_BLOCK_NIDS_OFFSET])
61 #define ID_BLOCK_ID(b, n)               ((b)[ID_BLOCK_IDS_OFFSET+(n)])
62
63 #define ID_BLOCK_NOID(b, n)             (ID_BLOCK_ID((b),(n)) == NOID)
64
65 #define ID_BLOCK_ALLIDS_VALUE   0
66 #define ID_BLOCK_ALLIDS(b)              (ID_BLOCK_NMAX(b) == ID_BLOCK_ALLIDS_VALUE)
67
68 #define ID_BLOCK_INDIRECT_VALUE 0
69 #define ID_BLOCK_INDIRECT(b)    (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
70
71 /* for the in-core cache of entries */
72 struct 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_mutex_t c_mutex;
80 };
81
82 /* for the cache of open index files (re-used for txn) */
83 struct dbcache {
84         int                     dbc_refcnt;
85         int                     dbc_maxids;
86         int                     dbc_maxindirect;
87         time_t          dbc_lastref;
88         long            dbc_blksize;
89         char            *dbc_name;
90         LDBM            dbc_db;
91
92         struct dbcache   *next;
93 };
94
95 typedef  struct dbcache  BDB2_TXN_FILES;
96
97
98 /* for the cache of attribute information (which are indexed, etc.) */
99 struct attrinfo {
100         char    *ai_type;       /* type name (cn, sn, ...)      */
101         int     ai_indexmask;   /* how the attr is indexed      */
102 #define INDEX_PRESENCE  0x01
103 #define INDEX_EQUALITY  0x02
104 #define INDEX_APPROX    0x04
105 #define INDEX_SUB       0x08
106 #define INDEX_UNKNOWN   0x10
107 #define INDEX_FROMINIT  0x20
108         int     ai_syntaxmask;  /* what kind of syntax          */
109 /* ...from slap.h...
110 #define SYNTAX_CIS      0x01
111 #define SYNTAX_CES      0x02
112 #define SYNTAX_BIN      0x04
113    ... etc. ...
114 */
115 };
116
117 #define MAXDBCACHE      10
118
119 /* this could be made an option */
120 #ifndef SLAPD_NEXTID_CHUNK
121 #define SLAPD_NEXTID_CHUNK      32
122 #endif
123
124
125 /*  TP stuff  */
126
127 typedef  struct _bdb2_txn_head {
128
129         /*  counter and timer to control checkpoints  */
130         size_t           txn_cnt;
131         time_t           txn_chkp;
132
133         /*  a list of all DB files in use  */
134         BDB2_TXN_FILES   *dbFiles;
135
136         /*  we have five fixed files  */
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
153 /*  the private description of a backend type  */
154 struct ldbtype {
155         char                    *lty_dbhome;
156         size_t                  lty_mpsize;
157
158         /*  XXX do we need a private DB_ENV for all DB2 backend types ?  */
159         DB_ENV                  *lty_dbenv;
160 };
161
162 #define get_dbenv(be) ((struct ldbtype *) (be)->bd_info->bi_private)->lty_dbenv
163
164
165 /*  the private description of a database  */
166 struct ldbminfo {
167         ID                      li_nextid;
168 #if SLAPD_NEXTID_CHUNK > 1
169         ID                      li_nextid_wrote;
170 #endif
171         char            *li_nextid_file;
172         ldap_pvt_thread_mutex_t         li_root_mutex;
173         ldap_pvt_thread_mutex_t         li_add_mutex;
174         ldap_pvt_thread_mutex_t         li_nextid_mutex;
175         int                     li_mode;
176         char                    *li_directory;
177         struct cache            li_cache;
178         Avlnode                 *li_attrs;
179         int                     li_dbcachesize;
180         int                     li_dbcachewsync;
181         struct dbcache          li_dbcache[MAXDBCACHE];
182         ldap_pvt_thread_mutex_t         li_dbcache_mutex;
183         ldap_pvt_thread_cond_t          li_dbcache_cv;
184
185         /*  a list of all files of the database  */
186         BDB2_TXN_HEAD           li_txn_head;
187
188 };
189
190
191 #include "proto-back-bdb2.h"
192
193 LDAP_END_DECL
194
195 #endif /* _back_bdb2_h_ */