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