]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/back-ldbm.h
c7d1e212c7d7486e3823bb74cbd47ce5eecc5b19
[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 #include "db.h"
8
9 LDAP_BEGIN_DECL
10
11 #define DEFAULT_CACHE_SIZE      1000
12
13 #ifdef HAVE_BERKELEY_DB2
14 #       define DEFAULT_DBCACHE_SIZE (100 * DEFAULT_DB_PAGE_SIZE)
15 #else
16 #       define DEFAULT_DBCACHE_SIZE 100000
17 #endif
18
19 #define DEFAULT_DB_DIRECTORY    "/usr/tmp"
20 #define DEFAULT_MODE            0600
21
22 #define SUBLEN                  3
23
24 /*
25  * there is a single index for each attribute.  these prefixes insure
26  * that there is no collision among keys.
27  */
28 #define EQ_PREFIX       '='     /* prefix for equality keys     */
29 #define APPROX_PREFIX   '~'     /* prefix for approx keys       */
30 #define SUB_PREFIX      '*'     /* prefix for substring keys    */
31 #define CONT_PREFIX     '\\'    /* prefix for continuation keys */
32
33 #define UNKNOWN_PREFIX  '?'     /* prefix for unknown keys    */
34
35 #define DEFAULT_BLOCKSIZE       8192
36
37 /*
38  * This structure represents an id block on disk and an id list
39  * in core.
40  *
41  * The fields have the following meanings:
42  *
43  *      b_nmax  maximum number of ids in this block. if this is == ALLIDSBLOCK,
44  *              then this block represents all ids.
45  *      b_nids  current number of ids in use in this block.  if this
46  *              is == INDBLOCK, then this block is an indirect block
47  *              containing a list of other blocks containing actual ids.
48  *              the list is terminated by an id of NOID.
49  *      b_ids   a list of the actual ids themselves
50  */
51 typedef struct block {
52         ID              b_nmax;         /* max number of ids in this list  */
53 #define ALLIDSBLOCK     0               /* == 0 => this is an allid block  */
54         ID              b_nids;         /* current number of ids used      */
55 #define INDBLOCK        0               /* == 0 => this is an indirect blk */
56         ID              b_ids[1];       /* the ids - actually bigger       */
57 } Block, IDList;
58
59 #define ALLIDS( idl )           ((idl)->b_nmax == ALLIDSBLOCK)
60 #define INDIRECT_BLOCK( idl )   ((idl)->b_nids == INDBLOCK)
61
62 /* for the in-core cache of entries */
63 struct cache {
64         int             c_maxsize;
65         int             c_cursize;
66         Avlnode         *c_dntree;
67         Avlnode         *c_idtree;
68         Entry           *c_lruhead;     /* lru - add accessed entries here */
69         Entry           *c_lrutail;     /* lru - rem lru entries from here */
70         pthread_mutex_t c_mutex;
71 };
72
73 /* for the cache of open index files */
74 struct dbcache {
75         int             dbc_refcnt;
76         int             dbc_maxids;
77         int             dbc_maxindirect;
78         time_t          dbc_lastref;
79         long            dbc_blksize;
80         char            *dbc_name;
81         LDBM            dbc_db;
82
83 #ifdef HAVE_BERKELEY_DB2
84         struct dbcache   *next;
85 #endif
86 };
87
88 /* for the cache of attribute information (which are indexed, etc.) */
89 struct attrinfo {
90         char    *ai_type;       /* type name (cn, sn, ...)      */
91         int     ai_indexmask;   /* how the attr is indexed      */
92 #define INDEX_PRESENCE  0x01
93 #define INDEX_EQUALITY  0x02
94 #define INDEX_APPROX    0x04
95 #define INDEX_SUB       0x08
96 #define INDEX_UNKNOWN   0x10
97 #define INDEX_FROMINIT  0x20
98         int     ai_syntaxmask;  /* what kind of syntax          */
99 /* ...from slap.h...
100 #define SYNTAX_CIS      0x01
101 #define SYNTAX_CES      0x02
102 #define SYNTAX_BIN      0x04
103    ... etc. ...
104 */
105 };
106
107 #define MAXDBCACHE      10
108
109 struct ldbminfo {
110         ID                      li_nextid;
111         pthread_mutex_t         li_root_mutex;
112         pthread_mutex_t         li_add_mutex;
113         pthread_mutex_t         li_nextid_mutex;
114         int                     li_mode;
115         char                    *li_directory;
116         struct cache            li_cache;
117         Avlnode                 *li_attrs;
118         int                     li_dbcachesize;
119         int                     li_dbcachewsync;
120         struct dbcache          li_dbcache[MAXDBCACHE];
121         ldap_pvt_thread_mutex_t     li_dbcache_mutex;
122         ldap_pvt_thread_cond_t      li_dbcache_cv;
123
124 #ifdef HAVE_BERKELEY_DB2
125
126         /*  Berkeley DB2 Environment  */
127         DB_ENV                  li_db_env;
128
129 #endif
130 };
131
132 #include "proto-back-ldbm.h"
133
134 LDAP_END_DECL
135
136 #endif /* _back_ldbm_h_ */