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