]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/back-ldbm.h
9a68e0e2d180c0c2c3300f7603ba47190d558b73
[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 #define DN_BASE_PREFIX          '='
28 #define DN_ONE_PREFIX           '@'
29 #define DN_SUBTREE_PREFIX       '?'
30
31 #define SLAPD_FILTER_DN_ONE             ((ber_tag_t) -2)
32 #define SLAPD_FILTER_DN_SUBTREE ((ber_tag_t) -3)
33
34 /*
35  * there is a single index for each attribute.  these prefixes ensure
36  * that there is no collision among keys.
37  */
38 #define EQ_PREFIX       '='     /* prefix for equality keys     */
39 #define APPROX_PREFIX   '~'     /* prefix for approx keys       */
40 #define SUB_PREFIX      '*'     /* prefix for substring keys    */
41 #define CONT_PREFIX     '\\'    /* prefix for continuation keys */
42
43 /* allow 3 characters per byte + PREFIX + EOS */
44 #define CONT_SIZE ( sizeof(long)*3 + 1 + 1 )
45
46 #define UNKNOWN_PREFIX  '?'     /* prefix for unknown keys    */
47
48 #define DEFAULT_BLOCKSIZE       8192
49
50 /*
51  * This structure represents an id block on disk and an id list
52  * in core.
53  *
54  * The fields have the following meanings:
55  *
56  *      b_nmax  maximum number of ids in this block. if this is == ALLIDSBLOCK,
57  *              then this block represents all ids.
58  *      b_nids  current number of ids in use in this block.  if this
59  *              is == INDBLOCK, then this block is an indirect block
60  *              containing a list of other blocks containing actual ids.
61  *              the list is terminated by an id of NOID.
62  *      b_ids   a list of the actual ids themselves
63  */
64
65 typedef ID ID_BLOCK;
66
67 #define ID_BLOCK_NMAX_OFFSET    0
68 #define ID_BLOCK_NIDS_OFFSET    1
69 #define ID_BLOCK_IDS_OFFSET             2
70
71 /* all ID_BLOCK macros operate on a pointer to a ID_BLOCK */
72
73 #define ID_BLOCK_NMAX(b)                ((b)[ID_BLOCK_NMAX_OFFSET])
74 #define ID_BLOCK_NIDS(b)                ((b)[ID_BLOCK_NIDS_OFFSET])
75 #define ID_BLOCK_ID(b, n)               ((b)[ID_BLOCK_IDS_OFFSET+(n)])
76
77 #define ID_BLOCK_NOID(b, n)             (ID_BLOCK_ID((b),(n)) == NOID)
78
79 #define ID_BLOCK_ALLIDS_VALUE   0
80 #define ID_BLOCK_ALLIDS(b)              (ID_BLOCK_NMAX(b) == ID_BLOCK_ALLIDS_VALUE)
81
82 #define ID_BLOCK_INDIRECT_VALUE 0
83 #define ID_BLOCK_INDIRECT(b)    (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
84
85 /* for the in-core cache of entries */
86 typedef struct ldbm_cache {
87         int             c_maxsize;
88         int             c_cursize;
89         Avlnode         *c_dntree;
90         Avlnode         *c_idtree;
91         Entry           *c_lruhead;     /* lru - add accessed entries here */
92         Entry           *c_lrutail;     /* lru - rem lru entries from here */
93         ldap_pvt_thread_mutex_t c_mutex;
94 } Cache;
95
96 #define CACHE_READ_LOCK         0
97 #define CACHE_WRITE_LOCK        1
98
99 /* for the cache of open index files */
100 typedef struct ldbm_dbcache {
101         int             dbc_refcnt;
102         int             dbc_maxids;
103         int             dbc_maxindirect;
104         time_t  dbc_lastref;
105         long    dbc_blksize;
106         char    *dbc_name;
107         LDBM    dbc_db;
108 } DBCache;
109
110 /* for the cache of attribute information (which are indexed, etc.) */
111 typedef struct ldbm_attrinfo {
112         char    *ai_type;       /* type name (cn, sn, ...)      */
113         int     ai_indexmask;   /* how the attr is indexed      */
114 #define INDEX_PRESENCE          0x0001
115 #define INDEX_EQUALITY          0x0002
116 #define INDEX_APPROX            0x0004
117 #define INDEX_SUB                       0x0008
118 #define INDEX_UNKNOWN           0x0010
119 #define INDEX_FROMINIT          0x1000
120         int     ai_syntaxmask;  /* what kind of syntax          */
121 /* ...from slap.h...
122 #define SYNTAX_CIS      0x01
123 #define SYNTAX_CES      0x02
124 #define SYNTAX_BIN      0x04
125    ... etc. ...
126 */
127 } AttrInfo;
128
129 #define MAXDBCACHE      16
130
131 struct ldbminfo {
132         ID                      li_nextid;
133         ldap_pvt_thread_mutex_t         li_nextid_mutex;
134         ldap_pvt_thread_mutex_t         li_root_mutex;
135         ldap_pvt_thread_mutex_t         li_add_mutex;
136         int                     li_mode;
137         char                    *li_directory;
138         Cache           li_cache;
139         Avlnode                 *li_attrs;
140         int                     li_dbcachesize;
141         int                     li_dbcachewsync;
142         DBCache         li_dbcache[MAXDBCACHE];
143         ldap_pvt_thread_mutex_t         li_dbcache_mutex;
144         ldap_pvt_thread_cond_t          li_dbcache_cv;
145 #ifdef HAVE_BERKELEY_DB2
146         DB_ENV                      li_db_env;
147 #endif
148 };
149
150 LDAP_END_DECL
151
152 #include "proto-back-ldbm.h"
153
154 #endif /* _back_ldbm_h_ */