]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/back-ldbm.h
cleanup bind
[openldap] / servers / slapd / back-ldbm / back-ldbm.h
1 /* back-ldbm.h - ldap ldbm back-end header file */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #ifndef _BACK_LDBM_H_
9 #define _BACK_LDBM_H_
10
11 #include "ldbm.h"
12
13 LDAP_BEGIN_DECL
14
15 #define DEFAULT_CACHE_SIZE      1000
16
17 #if defined(HAVE_BERKELEY_DB) && DB_VERSION_MAJOR >= 2
18 #       define DEFAULT_DBCACHE_SIZE (100 * DEFAULT_DB_PAGE_SIZE)
19 #else
20 #       define DEFAULT_DBCACHE_SIZE 100000
21 #endif
22
23 #define DN_BASE_PREFIX          SLAP_INDEX_EQUALITY_PREFIX
24 #define DN_ONE_PREFIX           '%'
25 #define DN_SUBTREE_PREFIX       '@'
26
27 /*
28  * there is a single index for each attribute.  these prefixes ensure
29  * that there is no collision among keys.
30  */
31
32 /* allow PREFIX + byte for continuate number */
33 #define SLAP_INDEX_CONT_SIZE ( sizeof(SLAP_INDEX_CONT_PREFIX) + sizeof(unsigned char) )
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
52 typedef ID ID_BLOCK;
53
54 #define ID_BLOCK_NMAX_OFFSET    0
55 #define ID_BLOCK_NIDS_OFFSET    1
56 #define ID_BLOCK_IDS_OFFSET             2
57
58 /* all ID_BLOCK macros operate on a pointer to a ID_BLOCK */
59
60 #define ID_BLOCK_NMAX(b)                ((b)[ID_BLOCK_NMAX_OFFSET])
61
62 /* Use this macro to get the value, but not to set it.
63  * By default this is identical to above.
64  */
65 #define ID_BLOCK_NMAXN(b)               ID_BLOCK_NMAX(b)
66 #define ID_BLOCK_NIDS(b)                ((b)[ID_BLOCK_NIDS_OFFSET])
67 #define ID_BLOCK_ID(b, n)               ((b)[ID_BLOCK_IDS_OFFSET+(n)])
68
69 #define ID_BLOCK_NOID(b, n)             (ID_BLOCK_ID((b),(n)) == NOID)
70
71 #define ID_BLOCK_ALLIDS_VALUE   0
72 #define ID_BLOCK_ALLIDS(b)              (ID_BLOCK_NMAX(b) == ID_BLOCK_ALLIDS_VALUE)
73
74 #define ID_BLOCK_INDIRECT_VALUE 0
75 #define ID_BLOCK_INDIRECT(b)    (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
76
77 #define USE_INDIRECT_NIDS       1
78
79 #ifdef USE_INDIRECT_NIDS
80 /*
81  * Use the high bit of ID_BLOCK_NMAX to indicate an INDIRECT block, thus
82  * freeing up the ID_BLOCK_NIDS to store an actual count. This allows us
83  * to use binary search on INDIRECT blocks.
84  */
85 #undef  ID_BLOCK_NMAXN
86 #define ID_BLOCK_NMAXN(b)               ((b)[ID_BLOCK_NMAX_OFFSET]&0x7fffffff)
87 #undef  ID_BLOCK_INDIRECT_VALUE
88 #define ID_BLOCK_INDIRECT_VALUE 0x80000000
89 #undef  ID_BLOCK_INDIRECT
90 #define ID_BLOCK_INDIRECT(b)    (ID_BLOCK_NMAX(b) & ID_BLOCK_INDIRECT_VALUE)
91
92 #endif  /* USE_INDIRECT_NIDS */
93
94 /* for the in-core cache of entries */
95 typedef struct ldbm_cache {
96         int             c_maxsize;
97         int             c_cursize;
98         Avlnode         *c_dntree;
99         Avlnode         *c_idtree;
100         Entry           *c_lruhead;     /* lru - add accessed entries here */
101         Entry           *c_lrutail;     /* lru - rem lru entries from here */
102         ldap_pvt_thread_mutex_t c_mutex;
103 } Cache;
104
105 #define CACHE_READ_LOCK         0
106 #define CACHE_WRITE_LOCK        1
107
108 /* for the cache of open index files */
109 typedef struct ldbm_dbcache {
110         int             dbc_refcnt;
111         int             dbc_maxids;
112         int             dbc_maxindirect;
113         int             dbc_dirty;
114         int             dbc_flags;
115         time_t  dbc_lastref;
116         long    dbc_blksize;
117         char    *dbc_name;
118         LDBM    dbc_db;
119         ldap_pvt_thread_mutex_t dbc_write_mutex;
120 } DBCache;
121
122 #define MAXDBCACHE      128
123
124 struct ldbminfo {
125         ldap_pvt_thread_rdwr_t          li_giant_rwlock;
126         ID                      li_nextid;
127         int                     li_mode;
128         slap_mask_t     li_defaultmask;
129         char                    *li_directory;
130         Cache           li_cache;
131         Avlnode                 *li_attrs;
132         int                     li_dblocking;   /* lock databases */
133         int                     li_dbwritesync; /* write sync */
134         int                     li_dbcachesize;
135         DBCache         li_dbcache[MAXDBCACHE];
136         ldap_pvt_thread_mutex_t         li_dbcache_mutex;
137         ldap_pvt_thread_cond_t          li_dbcache_cv;
138         DB_ENV                  *li_dbenv;
139         int                     li_envdirok;
140         int                     li_dbsyncfreq;
141         int                     li_dbsyncwaitn;
142         int                     li_dbsyncwaitinterval;
143         ldap_pvt_thread_t       li_dbsynctid;
144         int                     li_dbshutdown;
145 };
146
147 LDAP_END_DECL
148
149 #include "proto-back-ldbm.h"
150
151 #endif /* _back_ldbm_h_ */