]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/back-ldbm.h
Add multimaster replication support (ITS#170) based upon
[openldap] / servers / slapd / back-ldbm / back-ldbm.h
1 /* back-ldbm.h - ldap ldbm back-end header file */
2
3 #ifndef _BACK_LDBM_H_
4 #define _BACK_LDBM_H_
5
6 #include "ldbm.h"
7
8 LDAP_BEGIN_DECL
9
10 #define DEFAULT_CACHE_SIZE      1000
11
12 #ifdef HAVE_BERKELEY_DB2
13 #       define DEFAULT_DBCACHE_SIZE (100 * DEFAULT_DB_PAGE_SIZE)
14 #else
15 #       define DEFAULT_DBCACHE_SIZE 100000
16 #endif
17
18 #define DEFAULT_DB_DIRECTORY    "/usr/tmp"
19 #define DEFAULT_MODE            0600
20
21 #define SUBLEN                  3
22
23 /*
24  * there is a single index for each attribute.  these prefixes insure
25  * that there is no collision among keys.
26  */
27 #define EQ_PREFIX       '='     /* prefix for equality keys     */
28 #define APPROX_PREFIX   '~'     /* prefix for approx keys       */
29 #define SUB_PREFIX      '*'     /* prefix for substring keys    */
30 #define CONT_PREFIX     '\\'    /* prefix for continuation keys */
31
32 #define UNKNOWN_PREFIX  '?'     /* prefix for unknown keys    */
33
34 #define DEFAULT_BLOCKSIZE       8192
35
36 /*
37  * This structure represents an id block on disk and an id list
38  * in core.
39  *
40  * The fields have the following meanings:
41  *
42  *      b_nmax  maximum number of ids in this block. if this is == ALLIDSBLOCK,
43  *              then this block represents all ids.
44  *      b_nids  current number of ids in use in this block.  if this
45  *              is == INDBLOCK, then this block is an indirect block
46  *              containing a list of other blocks containing actual ids.
47  *              the list is terminated by an id of NOID.
48  *      b_ids   a list of the actual ids themselves
49  */
50
51 typedef ID ID_BLOCK;
52
53 #define ID_BLOCK_NMAX_OFFSET    0
54 #define ID_BLOCK_NIDS_OFFSET    1
55 #define ID_BLOCK_IDS_OFFSET             2
56
57 /* all ID_BLOCK macros operate on a pointer to a ID_BLOCK */
58
59 #define ID_BLOCK_NMAX(b)                ((b)[ID_BLOCK_NMAX_OFFSET])
60 #define ID_BLOCK_NIDS(b)                ((b)[ID_BLOCK_NIDS_OFFSET])
61 #define ID_BLOCK_ID(b, n)               ((b)[ID_BLOCK_IDS_OFFSET+(n)])
62
63 #define ID_BLOCK_NOID(b, n)             (ID_BLOCK_ID((b),(n)) == NOID)
64
65 #define ID_BLOCK_ALLIDS_VALUE   0
66 #define ID_BLOCK_ALLIDS(b)              (ID_BLOCK_NMAX(b) == ID_BLOCK_ALLIDS_VALUE)
67
68 #define ID_BLOCK_INDIRECT_VALUE 0
69 #define ID_BLOCK_INDIRECT(b)    (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
70
71 /* for the in-core cache of entries */
72 typedef struct ldbm_cache {
73         int             c_maxsize;
74         int             c_cursize;
75         Avlnode         *c_dntree;
76         Avlnode         *c_idtree;
77         Entry           *c_lruhead;     /* lru - add accessed entries here */
78         Entry           *c_lrutail;     /* lru - rem lru entries from here */
79         ldap_pvt_thread_mutex_t c_mutex;
80 } Cache;
81
82 #define CACHE_READ_LOCK         0
83 #define CACHE_WRITE_LOCK        1
84
85 /* for the cache of open index files */
86 typedef struct ldbm_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 } DBCache;
95
96 /* for the cache of attribute information (which are indexed, etc.) */
97 typedef struct ldbm_attrinfo {
98         char    *ai_type;       /* type name (cn, sn, ...)      */
99         int     ai_indexmask;   /* how the attr is indexed      */
100 #define INDEX_PRESENCE  0x01
101 #define INDEX_EQUALITY  0x02
102 #define INDEX_APPROX    0x04
103 #define INDEX_SUB       0x08
104 #define INDEX_UNKNOWN   0x10
105 #define INDEX_FROMINIT  0x20
106         int     ai_syntaxmask;  /* what kind of syntax          */
107 /* ...from slap.h...
108 #define SYNTAX_CIS      0x01
109 #define SYNTAX_CES      0x02
110 #define SYNTAX_BIN      0x04
111    ... etc. ...
112 */
113 } AttrInfo;
114
115 #define MAXDBCACHE      10
116
117 /* this could be made an option */
118 #ifndef SLAPD_NEXTID_CHUNK
119 #define SLAPD_NEXTID_CHUNK      32
120 #endif
121
122 struct ldbminfo {
123         ID                      li_nextid;
124 #if SLAPD_NEXTID_CHUNK > 1
125         ID                      li_nextid_wrote;
126 #endif
127         char            *li_nextid_file;
128         ldap_pvt_thread_mutex_t         li_root_mutex;
129         ldap_pvt_thread_mutex_t         li_add_mutex;
130         ldap_pvt_thread_mutex_t         li_nextid_mutex;
131         int                     li_mode;
132         char                    *li_directory;
133         Cache           li_cache;
134         Avlnode                 *li_attrs;
135         int                     li_dbcachesize;
136         int                     li_dbcachewsync;
137         DBCache         li_dbcache[MAXDBCACHE];
138         ldap_pvt_thread_mutex_t         li_dbcache_mutex;
139         ldap_pvt_thread_cond_t          li_dbcache_cv;
140 #ifdef HAVE_BERKELEY_DB2
141         DB_ENV                      li_db_env;
142 #endif
143 };
144
145 extern int ldbm_ignore_nextid_file;
146
147 LDAP_END_DECL
148
149 #include "proto-back-ldbm.h"
150
151 #endif /* _back_ldbm_h_ */