]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/back-ldbm.h
ITS#4310 seems to affect also back-ldbm
[openldap] / servers / slapd / back-ldbm / back-ldbm.h
1 /* back-ldbm.h - ldap ldbm back-end header file */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2006 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17 #ifndef _BACK_LDBM_H_
18 #define _BACK_LDBM_H_
19
20 #include "ldbm.h"
21 #include "alock.h"
22
23 LDAP_BEGIN_DECL
24
25 #define DEFAULT_CACHE_SIZE      1000
26
27 #if defined(HAVE_BERKELEY_DB) && DB_VERSION_MAJOR >= 2
28 #       define DEFAULT_DBCACHE_SIZE (100 * DEFAULT_DB_PAGE_SIZE)
29 #else
30 #       define DEFAULT_DBCACHE_SIZE 100000
31 #endif
32
33 #define DN_BASE_PREFIX          SLAP_INDEX_EQUALITY_PREFIX
34 #define DN_ONE_PREFIX           '%'
35 #define DN_SUBTREE_PREFIX       '@'
36
37 /*
38  * there is a single index for each attribute.  these prefixes ensure
39  * that there is no collision among keys.
40  */
41
42 /* allow PREFIX + byte for continuate number */
43 #define SLAP_INDEX_CONT_SIZE ( sizeof(SLAP_INDEX_CONT_PREFIX) + sizeof(unsigned char) )
44
45 #define DEFAULT_BLOCKSIZE       8192
46
47 /*
48  * This structure represents an id block on disk and an id list
49  * in core.
50  *
51  * The fields have the following meanings:
52  *
53  *      b_nmax  maximum number of ids in this block. if this is == ALLIDSBLOCK,
54  *              then this block represents all ids.
55  *      b_nids  current number of ids in use in this block.  if this
56  *              is == INDBLOCK, then this block is an indirect block
57  *              containing a list of other blocks containing actual ids.
58  *              the list is terminated by an id of NOID.
59  *      b_ids   a list of the actual ids themselves
60  */
61
62 typedef ID ID_BLOCK;
63
64 #define ID_BLOCK_NMAX_OFFSET    0
65 #define ID_BLOCK_NIDS_OFFSET    1
66 #define ID_BLOCK_IDS_OFFSET             2
67
68 /* all ID_BLOCK macros operate on a pointer to a ID_BLOCK */
69
70 #define ID_BLOCK_NMAX(b)                ((b)[ID_BLOCK_NMAX_OFFSET])
71
72 /* Use this macro to get the value, but not to set it.
73  * By default this is identical to above.
74  */
75 #define ID_BLOCK_NMAXN(b)               ID_BLOCK_NMAX(b)
76 #define ID_BLOCK_NIDS(b)                ((b)[ID_BLOCK_NIDS_OFFSET])
77 #define ID_BLOCK_ID(b, n)               ((b)[ID_BLOCK_IDS_OFFSET+(n)])
78
79 #define ID_BLOCK_NOID(b, n)             (ID_BLOCK_ID((b),(n)) == NOID)
80
81 #define ID_BLOCK_ALLIDS_VALUE   0
82 #define ID_BLOCK_ALLIDS(b)              (ID_BLOCK_NMAX(b) == ID_BLOCK_ALLIDS_VALUE)
83
84 #define ID_BLOCK_INDIRECT_VALUE 0
85 #define ID_BLOCK_INDIRECT(b)    (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
86
87 #define USE_INDIRECT_NIDS       1
88
89 #ifdef USE_INDIRECT_NIDS
90 /*
91  * Use the high bit of ID_BLOCK_NMAX to indicate an INDIRECT block, thus
92  * freeing up the ID_BLOCK_NIDS to store an actual count. This allows us
93  * to use binary search on INDIRECT blocks.
94  */
95 #undef  ID_BLOCK_NMAXN
96 #define ID_BLOCK_NMAXN(b)               ((b)[ID_BLOCK_NMAX_OFFSET]&0x7fffffff)
97 #undef  ID_BLOCK_INDIRECT_VALUE
98 #define ID_BLOCK_INDIRECT_VALUE 0x80000000
99 #undef  ID_BLOCK_INDIRECT
100 #define ID_BLOCK_INDIRECT(b)    (ID_BLOCK_NMAX(b) & ID_BLOCK_INDIRECT_VALUE)
101
102 #endif  /* USE_INDIRECT_NIDS */
103
104 /* for the in-core cache of entries */
105 typedef struct ldbm_cache {
106         int             c_maxsize;
107         int             c_cursize;
108         Avlnode         *c_dntree;
109         Avlnode         *c_idtree;
110         Entry           *c_lruhead;     /* lru - add accessed entries here */
111         Entry           *c_lrutail;     /* lru - rem lru entries from here */
112         ldap_pvt_thread_mutex_t c_mutex;
113 } Cache;
114
115 #define CACHE_READ_LOCK         0
116 #define CACHE_WRITE_LOCK        1
117
118 /* for the cache of open index files */
119 typedef struct ldbm_dbcache {
120         int             dbc_refcnt;
121         int             dbc_maxids;
122         int             dbc_maxindirect;
123         int             dbc_dirty;
124         int             dbc_flags;
125         time_t  dbc_lastref;
126         long    dbc_blksize;
127         char    *dbc_name;
128         LDBM    dbc_db;
129         ldap_pvt_thread_mutex_t dbc_write_mutex;
130 } DBCache;
131
132 #define MAXDBCACHE      128
133
134 struct ldbminfo {
135         ldap_pvt_thread_rdwr_t          li_giant_rwlock;
136         ID                      li_nextid;
137         int                     li_mode;
138         slap_mask_t     li_defaultmask;
139         char                    *li_directory;
140         Cache           li_cache;
141         Avlnode                 *li_attrs;
142         int                     li_dblocking;   /* lock databases */
143         int                     li_dbwritesync; /* write sync */
144         int                     li_dbcachesize;
145         DBCache         li_dbcache[MAXDBCACHE];
146         ldap_pvt_thread_mutex_t         li_dbcache_mutex;
147         ldap_pvt_thread_cond_t          li_dbcache_cv;
148         DB_ENV                  *li_dbenv;
149         int                     li_envdirok;
150         int                     li_dbsyncfreq;
151         int                     li_dbsyncwaitn;
152         int                     li_dbsyncwaitinterval;
153         int                     li_dbsyncwaitcount;
154         alock_info_t    li_alock_info;
155 };
156
157 LDAP_END_DECL
158
159 #include "proto-back-ldbm.h"
160
161 #endif /* _back_ldbm_h_ */