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