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