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