]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/back-ldbm.h
fac176726e3264b73ee854cba14f0003343a32d9
[openldap] / servers / slapd / back-ldbm / back-ldbm.h
1 /* back-ldbm.h - ldap ldbm back-end header file */
2 /*
3  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #ifndef _BACK_LDBM_H_
8 #define _BACK_LDBM_H_
9
10 #include "ldbm.h"
11
12 LDAP_BEGIN_DECL
13
14 #define DEFAULT_CACHE_SIZE      1000
15
16 #ifdef HAVE_BERKELEY_DB2
17 #       define DEFAULT_DBCACHE_SIZE (100 * DEFAULT_DB_PAGE_SIZE)
18 #else
19 #       define DEFAULT_DBCACHE_SIZE 100000
20 #endif
21
22 #define DEFAULT_DB_DIRECTORY    "/usr/tmp"
23 #define DEFAULT_MODE            0600
24
25 #define SUBLEN                  3
26
27 /* #undef DN_INDICES *//* generate dn eq, subtree, and parent indices */
28 #define DN_BASE_PREFIX          '='
29 #define DN_ONE_PREFIX           '@'
30 #define DN_SUBTREE_PREFIX       '?'
31
32 #define SLAPD_FILTER_DN_ONE             ((ber_tag_t) -2)
33 #define SLAPD_FILTER_DN_SUBTREE ((ber_tag_t) -3)
34
35 /*
36  * there is a single index for each attribute.  these prefixes ensure
37  * that there is no collision among keys.
38  */
39 #define EQ_PREFIX       '='     /* prefix for equality keys     */
40 #define APPROX_PREFIX   '~'     /* prefix for approx keys       */
41 #define SUB_PREFIX      '*'     /* prefix for substring keys    */
42 #define CONT_PREFIX     '\\'    /* prefix for continuation keys */
43
44 /* allow 3 characters per byte + PREFIX + EOS */
45 #define CONT_SIZE ( sizeof(long)*3 + 1 + 1 )
46
47 /* #undef CONT_POSTFIX *//* postfix original key */
48
49 #define UNKNOWN_PREFIX  '?'     /* prefix for unknown keys    */
50
51 #define DEFAULT_BLOCKSIZE       8192
52
53 /*
54  * This structure represents an id block on disk and an id list
55  * in core.
56  *
57  * The fields have the following meanings:
58  *
59  *      b_nmax  maximum number of ids in this block. if this is == ALLIDSBLOCK,
60  *              then this block represents all ids.
61  *      b_nids  current number of ids in use in this block.  if this
62  *              is == INDBLOCK, then this block is an indirect block
63  *              containing a list of other blocks containing actual ids.
64  *              the list is terminated by an id of NOID.
65  *      b_ids   a list of the actual ids themselves
66  */
67
68 typedef ID ID_BLOCK;
69
70 #define ID_BLOCK_NMAX_OFFSET    0
71 #define ID_BLOCK_NIDS_OFFSET    1
72 #define ID_BLOCK_IDS_OFFSET             2
73
74 /* all ID_BLOCK macros operate on a pointer to a ID_BLOCK */
75
76 #define ID_BLOCK_NMAX(b)                ((b)[ID_BLOCK_NMAX_OFFSET])
77 #define ID_BLOCK_NIDS(b)                ((b)[ID_BLOCK_NIDS_OFFSET])
78 #define ID_BLOCK_ID(b, n)               ((b)[ID_BLOCK_IDS_OFFSET+(n)])
79
80 #define ID_BLOCK_NOID(b, n)             (ID_BLOCK_ID((b),(n)) == NOID)
81
82 #define ID_BLOCK_ALLIDS_VALUE   0
83 #define ID_BLOCK_ALLIDS(b)              (ID_BLOCK_NMAX(b) == ID_BLOCK_ALLIDS_VALUE)
84
85 #define ID_BLOCK_INDIRECT_VALUE 0
86 #define ID_BLOCK_INDIRECT(b)    (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
87
88 /* for the in-core cache of entries */
89 typedef struct ldbm_cache {
90         int             c_maxsize;
91         int             c_cursize;
92         Avlnode         *c_dntree;
93         Avlnode         *c_idtree;
94         Entry           *c_lruhead;     /* lru - add accessed entries here */
95         Entry           *c_lrutail;     /* lru - rem lru entries from here */
96         ldap_pvt_thread_mutex_t c_mutex;
97 } Cache;
98
99 #define CACHE_READ_LOCK         0
100 #define CACHE_WRITE_LOCK        1
101
102 /* for the cache of open index files */
103 typedef struct ldbm_dbcache {
104         int             dbc_refcnt;
105         int             dbc_maxids;
106         int             dbc_maxindirect;
107         time_t  dbc_lastref;
108         long    dbc_blksize;
109         char    *dbc_name;
110         LDBM    dbc_db;
111 } DBCache;
112
113 /* for the cache of attribute information (which are indexed, etc.) */
114 typedef struct ldbm_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 } AttrInfo;
131
132 #define MAXDBCACHE      16
133
134 /* this could be made an option */
135 #ifndef SLAPD_NEXTID_CHUNK
136 #define SLAPD_NEXTID_CHUNK      32
137 #endif
138
139 struct ldbminfo {
140         ID                      li_nextid;
141 #if SLAPD_NEXTID_CHUNK > 1
142         ID                      li_nextid_wrote;
143 #endif
144         char            *li_nextid_file;
145         ldap_pvt_thread_mutex_t         li_root_mutex;
146         ldap_pvt_thread_mutex_t         li_add_mutex;
147         ldap_pvt_thread_mutex_t         li_nextid_mutex;
148         int                     li_mode;
149         char                    *li_directory;
150         Cache           li_cache;
151         Avlnode                 *li_attrs;
152         int                     li_dbcachesize;
153         int                     li_dbcachewsync;
154         DBCache         li_dbcache[MAXDBCACHE];
155         ldap_pvt_thread_mutex_t         li_dbcache_mutex;
156         ldap_pvt_thread_cond_t          li_dbcache_cv;
157 #ifdef HAVE_BERKELEY_DB2
158         DB_ENV                      li_db_env;
159 #endif
160 };
161
162 extern int ldbm_ignore_nextid_file;
163
164 LDAP_END_DECL
165
166 #include "proto-back-ldbm.h"
167
168 #endif /* _back_ldbm_h_ */